public void KickUserServerNotAllowed() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var admin = JoinAsGuest(s, c, "admin"); client.DequeueAndAssertMessage <UserJoinedMessage>(); var target = JoinAsGuest(server, client, "target"); c.DequeueAndAssertMessage <UserJoinedMessage>(); handler.OnKickUserMessage(new MessageEventArgs <KickUserMessage> (s, new KickUserMessage(target, true))); Assert.AreEqual(GablarskiMessageType.KickUser, c.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage); permissions.EnablePermissions(admin.UserId, PermissionName.KickPlayerFromChannel); handler.OnKickUserMessage(new MessageEventArgs <KickUserMessage> (s, new KickUserMessage(target, true))); Assert.AreEqual(GablarskiMessageType.KickUser, c.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage); }
public void Teardown() { handler = null; server = null; observer = null; context = null; }
public void Setup() { manager = new ServerUserManager(); permissions = new MockPermissionsProvider(); channels = new LobbyChannelProvider(); MockServerContext mcontext; context = mcontext = new MockServerContext { ChannelsProvider = channels, PermissionsProvider = permissions, UserManager = new ServerUserManager(), Settings = new ServerSettings { Name = "Test Server" } }; mcontext.Users = new ServerUserHandler(context, manager); mcontext.Channels = handler = new ServerChannelHandler(context); user = UserInfoTests.GetTestUser(1, 1, false); provider = new MockConnectionProvider(GablarskiProtocol.Instance); mcontext.AddConnectionProvider(provider); mcontext.Start(); var connections = provider.GetConnections(GablarskiProtocol.Instance); client = new ConnectionBuffer(connections.Item1); server = connections.Item2; manager.Connect(server); manager.Join(server, user); }
public void SetPermissionsSelf() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var u = JoinAsGuest(s, c, "nick"); permissions.UpdatedSupported = true; permissions.EnablePermissions(u.UserId, PermissionName.ModifyPermissions); handler.OnSetPermissionsMessage(new MessageEventArgs <SetPermissionsMessage> (s, new SetPermissionsMessage(u, new [] { new Permission(PermissionName.SendAudio, true), new Permission(PermissionName.SendAudioToMultipleTargets, false), new Permission(PermissionName.KickPlayerFromChannel, true) { ChannelId = 1 }, }))); var msg = c.DequeueAndAssertMessage <PermissionsMessage>(); Assert.AreEqual(u.UserId, msg.OwnerId); var perms = msg.Permissions.ToList(); perms.Single(p => p.ChannelId == 0 && p.Name == PermissionName.SendAudio && p.IsAllowed); perms.Single(p => p.ChannelId == 0 && p.Name == PermissionName.SendAudioToMultipleTargets && !p.IsAllowed); perms.Single(p => p.ChannelId == 1 && p.Name == PermissionName.KickPlayerFromChannel && p.IsAllowed); }
private IUserInfo Join(bool loggedIn, ConnectionBuffer connection, string nickname, string serverPassword) { connection.SendAsync(new JoinMessage(nickname, serverPassword)); var joinResultMessage = connection.DequeueAndAssertMessage <JoinResultMessage>(); Assert.AreEqual(LoginResultState.Success, joinResultMessage.Result); if (!loggedIn) { connection.DequeueAndAssertMessage <PermissionsMessage>(); } var userJoinedMessage = connection.DequeueAndAssertMessage <UserJoinedMessage>(); IUserInfo user = userJoinedMessage.UserInfo; Assert.AreEqual(nickname, userJoinedMessage.UserInfo.Nickname); Assert.AreEqual(joinResultMessage.UserInfo.Username, userJoinedMessage.UserInfo.Username); Assert.AreEqual(joinResultMessage.UserInfo.UserId, userJoinedMessage.UserInfo.UserId); Assert.AreEqual(joinResultMessage.UserInfo.CurrentChannelId, userJoinedMessage.UserInfo.CurrentChannelId); //connection.Client.DequeueAndAssertMessage<ChannelListMessage>(); //var usermsg = connection.Client.DequeueAndAssertMessage<UserInfoListMessage>(); //Assert.IsNotNull (usermsg.Users.FirstOrDefault (u => u.UserId == userJoinedMessage.UserInfo.UserId)); //connection.Client.DequeueAndAssertMessage<SourceListMessage>(); return(user); }
public void RequestSourceListFromViewer() { permissions.EnablePermissions(user.UserId, PermissionName.RequestSource); var audioArgs = AudioCodecArgsTests.GetTestArgs(); handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server, new RequestSourceMessage("Name", audioArgs))); var result = client.DequeueAndAssertMessage <SourceResultMessage>(); Assert.AreEqual(SourceResult.Succeeded, result.SourceResult); handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server, new RequestSourceMessage("Name2", audioArgs))); var result2 = client.DequeueAndAssertMessage <SourceResultMessage>(); Assert.AreEqual(SourceResult.Succeeded, result2.SourceResult); client.AssertNoMessage(); var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); userManager.Join(c, UserInfoTests.GetTestUser(2)); handler.RequestSourceListMessage(new MessageEventArgs <RequestSourceListMessage> (c, new RequestSourceListMessage())); var list = cl.DequeueAndAssertMessage <SourceListMessage>(); Assert.AreEqual(2, list.Sources.Count()); Assert.Contains(result.Source, list.Sources.ToList()); Assert.Contains(result2.Source, list.Sources.ToList()); cl.AssertNoMessage(); }
public void Setup() { permissions = new MockPermissionsProvider(); users = new MockUserProvider(); provider = new MockConnectionProvider(GablarskiProtocol.Instance); context = new MockServerContext(provider) { Settings = new ServerSettings(), UserProvider = users, PermissionsProvider = permissions, ChannelsProvider = new LobbyChannelProvider(), }; context.Sources = new ServerSourceHandler(context, new ServerSourceManager(context)); context.Channels = new ServerChannelHandler(context); context.UserManager = new ServerUserManager(); context.Users = handler = new ServerUserHandler(context, context.UserManager); context.Start(); var cs = provider.GetConnections(GablarskiProtocol.Instance); server = new ServerConnectionBuffer(cs.Item2); client = new ConnectionBuffer(cs.Item1); var observers = provider.GetConnections(GablarskiProtocol.Instance); sobserver = observers.Item2; observer = new ConnectionBuffer(observers.Item1); }
public void ClientAudioSourceStateChangedDifferentChannel() { var u = UserInfoTests.GetTestUser(2, 2, false); var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); userManager.Join(c, u); var s = manager.Create("Name", u, new AudioCodecArgs()); handler.ClientAudioSourceStateChangeMessage(new MessageEventArgs <ClientAudioSourceStateChangeMessage> (c, new ClientAudioSourceStateChangeMessage { SourceId = s.Id, Starting = true })); cl.AssertNoMessage(); var change = client.DequeueAndAssertMessage <AudioSourceStateChangeMessage>(); Assert.AreEqual(s.Id, change.SourceId); Assert.AreEqual(true, change.Starting); }
public void SendAudioDataMessageUserMuted() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); userManager.Join(c, UserInfoTests.GetTestUser(2, 1, true)); var s = GetSourceFromRequest(c, cl); var result = client.DequeueAndAssertMessage <SourceResultMessage>(); Assert.AreEqual(SourceResult.NewSource, result.SourceResult); client.AssertNoMessage(); handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (c, new ClientAudioDataMessage { Data = new [] { new byte[512] }, SourceId = s.Id, TargetType = TargetType.Channel, TargetIds = new [] { 1 } })); cl.AssertNoMessage(); client.AssertNoMessage(); }
public void SendAudioDataMessageToUser() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); var u = UserInfoTests.GetTestUser(2, 2, false); userManager.Join(c, u); var s = GetSourceFromRequest(); var result = cl.DequeueAndAssertMessage <SourceResultMessage>(); Assert.AreEqual(SourceResult.NewSource, result.SourceResult); cl.AssertNoMessage(); permissions.EnablePermissions(user.UserId, PermissionName.SendAudio); handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (server, new ClientAudioDataMessage { Data = new [] { new byte[512] }, SourceId = s.Id, TargetType = TargetType.User, TargetIds = new [] { u.UserId } })); client.AssertNoMessage(); Assert.AreEqual(s.Id, cl.DequeueAndAssertMessage <ServerAudioDataMessage>().SourceId); }
public void KickUserFromServer() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ServerConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var admin = JoinAsGuest(s, c, "admin"); client.DequeueAndAssertMessage <UserJoinedMessage>(); permissions.EnablePermissions(admin.UserId, PermissionName.KickPlayerFromServer); var target = JoinAsGuest(server, client, "target"); c.DequeueAndAssertMessage <UserJoinedMessage>(); handler.OnKickUserMessage(new MessageEventArgs <KickUserMessage> (s, new KickUserMessage(target, true))); var kicked = client.DequeueAndAssertMessage <UserKickedMessage>(); Assert.AreEqual(target.UserId, kicked.UserId); Assert.AreEqual(true, kicked.FromServer); kicked = c.DequeueAndAssertMessage <UserKickedMessage>(); Assert.AreEqual(target.UserId, kicked.UserId); Assert.AreEqual(true, kicked.FromServer); Assert.AreEqual(target.UserId, c.DequeueAndAssertMessage <UserDisconnectedMessage>().UserId); }
public void SendAudioDataMessageToCurrentChannelWithoutPermission() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); userManager.Join(c, UserInfoTests.GetTestUser(2, 1, false)); var s = GetSourceFromRequest(); var result = cl.DequeueAndAssertMessage <SourceResultMessage>(); Assert.AreEqual(SourceResult.NewSource, result.SourceResult); cl.AssertNoMessage(); handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (server, new ClientAudioDataMessage { Data = new [] { new byte[512] }, SourceId = s.Id, TargetType = TargetType.Channel, TargetIds = new [] { user.CurrentChannelId } })); cl.AssertNoMessage(); Assert.AreEqual(GablarskiMessageType.ClientAudioData, client.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage); }
public async Task RequestChannelListMessageNotConnected() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = new ConnectionBuffer(cs.Item1); await c.DisconnectAsync(); handler.RequestChanneListMessage(new MessageEventArgs <RequestChannelListMessage> (cs.Item2, new RequestChannelListMessage())); c.AssertNoMessage(); }
public void RequestSourceListNotConnected() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); c.DisconnectAsync().Wait(); handler.RequestSourceListMessage(new MessageEventArgs <RequestSourceListMessage> (c, new RequestSourceListMessage())); cl.AssertNoMessage(); }
public void RequestSourceNotJoined() { var cs = this.provider.GetConnections(GablarskiProtocol.Instance); var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(cs.Item2); handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (cs.Item2, new RequestSourceMessage("Name", AudioCodecArgsTests.GetTestArgs()))); cl.AssertNoMessage(); }
public void KickUserNotConnected() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var u = JoinAsGuest(s, c, "nick"); handler.OnKickUserMessage(new MessageEventArgs <KickUserMessage> (server, new KickUserMessage(u, true))); c.AssertNoMessage(); }
public void BanNotConnected() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); handler.OnBanUserMessage(new MessageEventArgs <BanUserMessage> (s, new BanUserMessage { BanInfo = new BanInfo(null, "username", TimeSpan.Zero) })); c.AssertNoMessage(); }
public void PreApproveRegistrationUnsupported() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var u = JoinAsGuest(s, c, "nick"); users.UpdateSupported = false; users.RegistrationMode = UserRegistrationMode.None; Assert.Throws <NotSupportedException> (() => handler.ApproveRegistration(u)); }
public async Task RegisterNotConnected() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); await s.DisconnectAsync(); handler.OnRegisterMessage(new MessageEventArgs <RegisterMessage> (s, new RegisterMessage("username", "password"))); c.AssertNoMessage(); }
public void ServerInfo() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version }); var msg = connection.DequeueAndAssertMessage <ServerInfoMessage>(); Assert.AreEqual(this.settings.Name, msg.ServerInfo.Name); Assert.AreEqual(this.settings.Description, msg.ServerInfo.Description); Assert.IsNull(msg.ServerInfo.Logo); }
private ConnectionBuffer Connect() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version, Host = "test", Port = 42912 }); connection.DequeueAndAssertMessage <ServerInfoMessage>(); connection.DequeueAndAssertMessage <ChannelListMessage>(); connection.DequeueAndAssertMessage <UserInfoListMessage>(); connection.DequeueAndAssertMessage <SourceListMessage>(); return(connection); }
public void SetPermissionsNotAllowed() { permissions.UpdatedSupported = true; var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var u = JoinAsGuest(s, c, "nick"); handler.OnSetPermissionsMessage(new MessageEventArgs <SetPermissionsMessage> (s, new SetPermissionsMessage(u, new Permission[0]))); Assert.AreEqual(GablarskiMessageType.SetPermissions, c.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage); }
private ConnectionBuffer Login(string username, string password) { ConnectionBuffer connection = Connect(); connection.SendAsync(new LoginMessage { Username = username, Password = password }); var loginResultMessage = connection.DequeueAndAssertMessage <LoginResultMessage>(); Assert.IsTrue(loginResultMessage.Result.Succeeded); connection.DequeueAndAssertMessage <PermissionsMessage>(); return(connection); }
public void OldVersionReject() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = 0 }); Message message = connection.DequeueMessage(); Assert.IsInstanceOf <ConnectionRejectedMessage> (message); var rejected = (ConnectionRejectedMessage)message; Assert.AreEqual(ConnectionRejectedReason.IncompatibleVersion, rejected.Reason); }
public void ClientAudioSourceStateChangeNotJoined() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); handler.ClientAudioSourceStateChangeMessage(new MessageEventArgs <ClientAudioSourceStateChangeMessage> (c, new ClientAudioSourceStateChangeMessage { SourceId = 1, Starting = true })); client.AssertNoMessage(); cl.AssertNoMessage(); }
public void RequestChannelList() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new RequestChannelListMessage()); Message message = connection.DequeueMessage(); Assert.IsInstanceOf <ChannelListMessage> (message); var list = (ChannelListMessage)message; Assert.AreEqual(GenericResult.Success, list.Result); Assert.IsNotNull(list.Channels); CollectionAssert.IsNotEmpty(list.Channels); }
public void SetPermissionsNoPermissions() { permissions.UpdatedSupported = true; var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var u = JoinAsGuest(s, c, "nick"); permissions.EnablePermissions(u.UserId, PermissionName.ModifyPermissions); handler.OnSetPermissionsMessage(new MessageEventArgs <SetPermissionsMessage> (s, new SetPermissionsMessage(u, new Permission[0]))); c.AssertNoMessage(); }
public void RedirectMatch() { server.AddRedirector(new MockRedirector("monkeys.com", new IPEndPoint(IPAddress.Any, 6113))); var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version, Host = "monkeys.com", Port = 42912 }); var msg = connection.DequeueAndAssertMessage <RedirectMessage>(); Assert.AreEqual(IPAddress.Any.ToString(), msg.Host); Assert.AreEqual(6113, msg.Port); }
public void Setup() { permissions = new MockPermissionsProvider(); LobbyChannelProvider channels = new LobbyChannelProvider(); channels.SaveChannel(new ChannelInfo { Name = "Channel 2" }); this.provider = new MockConnectionProvider(GablarskiProtocol.Instance); this.provider.Start(MessageTypes.All); userManager = new ServerUserManager(); MockServerContext c; context = c = new MockServerContext(provider) { Settings = new ServerSettings { Name = "Server", DefaultAudioBitrate = defaultBitrate, MaximumAudioBitrate = maxBitrate, MinimumAudioBitrate = minBitrate }, UserManager = userManager, PermissionsProvider = permissions, ChannelsProvider = channels }; c.Users = new ServerUserHandler(context, userManager); manager = new ServerSourceManager(context); handler = new ServerSourceHandler(context, manager); user = UserInfoTests.GetTestUser(1, 1, false); var cs = provider.GetConnections(GablarskiProtocol.Instance); client = new ConnectionBuffer(cs.Item1); server = cs.Item2; userManager.Connect(server); userManager.Join(server, user); }
public void RegisterPreapprovedNotApproved() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var s = new ConnectionBuffer(cs.Item2); var c = new ConnectionBuffer(cs.Item1); var u = JoinAsGuest(s, c, "nick"); users.UpdateSupported = true; users.RegistrationMode = UserRegistrationMode.PreApproved; handler.OnRegisterMessage(new MessageEventArgs <RegisterMessage> (s, new RegisterMessage("username", "password"))); var msg = c.DequeueAndAssertMessage <RegisterResultMessage>(); Assert.AreEqual(RegisterResult.FailedNotApproved, msg.Result); }