Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void RedirectNoMatch()
        {
            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            = "monkeys2.com", Port = 42912
            });

            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);
        }
Exemplo n.º 4
0
        public void RequestChannelListMessageNotJoined()
        {
            permissions.EnablePermissions(-1, PermissionName.RequestChannelList);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = new ConnectionBuffer(cs.Item1);
            var s  = new ConnectionBuffer(cs.Item2);

            manager.Connect(cs.Item2);

            handler.RequestChanneListMessage(new MessageEventArgs <RequestChannelListMessage> (s,
                                                                                               new RequestChannelListMessage()));

            var msg = c.DequeueAndAssertMessage <ChannelListMessage>();

            Assert.AreEqual(GenericResult.Success, msg.Result);
            ChannelInfoTests.AssertChanelsAreEqual(channels.GetChannels().Single(), msg.Channels.Single());
        }
Exemplo n.º 5
0
        public void SetStatus()
        {
            JoinAsGuest(server, client, "Nickname");

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var s  = new ConnectionBuffer(cs.Item2);
            var c  = new ConnectionBuffer(cs.Item1);

            JoinAsGuest(s, c, "Nickname2");

            client.DequeueAndAssertMessage <UserJoinedMessage>();

            handler.OnSetStatusMessage(new MessageEventArgs <SetStatusMessage> (server,
                                                                                new SetStatusMessage(UserStatus.MutedMicrophone)));

            var update = c.DequeueAndAssertMessage <UserUpdatedMessage>();

            Assert.AreEqual(UserStatus.MutedMicrophone, update.User.Status);
        }
Exemplo n.º 6
0
        public AudioSource GetSourceFromRequest(MockServerConnection serverConnection, ConnectionBuffer clientConnection)
        {
            permissions.EnablePermissions(userManager.GetUser(serverConnection).UserId, PermissionName.RequestSource);

            var audioArgs = new AudioCodecArgs(AudioFormat.Mono16bitLPCM, 64000, AudioSourceTests.FrameSize, 10);

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (serverConnection,
                                                                                      new RequestSourceMessage("Name", audioArgs)));

            var result = clientConnection.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.Succeeded, result.SourceResult);
            Assert.AreEqual("Name", result.SourceName);
            Assert.AreEqual("Name", result.Source.Name);

            AudioCodecArgsTests.AssertAreEqual(audioArgs, result.Source.CodecSettings);

            clientConnection.AssertNoMessage();

            return(result.Source);
        }
Exemplo n.º 7
0
        public void SendAudioDataMessageToMultipleUsersWithoutPermission()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            var u1 = UserInfoTests.GetTestUser(2, 1, false);

            userManager.Join(c, u1);

            var cs2 = provider.GetConnections(GablarskiProtocol.Instance);
            var c2  = cs2.Item2;
            var cl2 = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c2);
            var u2 = UserInfoTests.GetTestUser(3, 1, false);

            userManager.Join(c2, u2);

            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 [] { u1.UserId, u2.UserId }
            }));

            cl.AssertNoMessage();
            Assert.AreEqual(GablarskiMessageType.ClientAudioData, client.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage);
        }
Exemplo n.º 8
0
        public void JoinChannelAtLimit()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.ChangeChannel);

            Assert.AreEqual(ChannelEditResult.Success, channels.SaveChannel(new ChannelInfo {
                Name = "Channel 2", UserLimit = 1
            }));
            client.DequeueAndAssertMessage <ChannelListMessage>();

            var channel = channels.GetChannels().Single(c => c.Name == "Channel 2");

            context.Users.Move(user, channel);

            var moved = client.DequeueAndAssertMessage <UserChangedChannelMessage>();

            Assert.AreEqual(user.UserId, moved.ChangeInfo.TargetUserId);
            Assert.AreEqual(channel.ChannelId, moved.ChangeInfo.TargetChannelId);
            Assert.AreEqual(channels.DefaultChannel.ChannelId, moved.ChangeInfo.PreviousChannelId);
            Assert.AreEqual(0, moved.ChangeInfo.RequestingUserId);

            var secondUser = UserInfoTests.GetTestUser(2, 1, false);

            var cs           = provider.GetConnections(GablarskiProtocol.Instance);
            var secondClient = new ConnectionBuffer(cs.Item1);

            var secondServer = cs.Item2;

            manager.Connect(secondServer);
            manager.Join(secondServer, secondUser);
            permissions.EnablePermissions(secondUser.UserId, PermissionName.ChangeChannel);

            context.Users.Move(secondServer, secondUser, channel);

            client.AssertNoMessage();

            var result = secondClient.DequeueAndAssertMessage <ChannelChangeResultMessage>();

            Assert.AreEqual(ChannelChangeResult.FailedFull, result.Result);
        }
Exemplo n.º 9
0
        public void SetPermissionsOtherConnected()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var s1 = new ConnectionBuffer(cs.Item2);
            var c1 = new ConnectionBuffer(cs.Item1);

            var u1 = JoinAsGuest(s1, c1, "nick");

            permissions.UpdatedSupported = true;
            permissions.EnablePermissions(u1.UserId, PermissionName.ModifyPermissions);

            cs = provider.GetConnections(GablarskiProtocol.Instance);
            var s2 = new ConnectionBuffer(cs.Item2);
            var c2 = new ConnectionBuffer(cs.Item1);

            var u2 = JoinAsGuest(s2, c2, "nick2");

            handler.OnSetPermissionsMessage(new MessageEventArgs <SetPermissionsMessage> (s1,
                                                                                          new SetPermissionsMessage(u2, new []
            {
                new Permission(PermissionName.SendAudio, true),
                new Permission(PermissionName.SendAudioToMultipleTargets, false),
                new Permission(PermissionName.KickPlayerFromChannel, true)
                {
                    ChannelId = 1
                },
            })));

            var msg = c2.DequeueAndAssertMessage <PermissionsMessage>();

            Assert.AreEqual(u2.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);
        }
Exemplo n.º 10
0
        public void RequestSourceNotification()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.RequestSource);

            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));

            var audioArgs = AudioCodecArgsTests.GetTestArgs();

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server,
                                                                                      new RequestSourceMessage("Name", audioArgs)));

            var sourceAdded = cl.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.NewSource, sourceAdded.SourceResult);
            Assert.AreEqual("Name", sourceAdded.SourceName);
            AudioCodecArgsTests.AssertAreEqual(audioArgs, sourceAdded.Source.CodecSettings);

            cl.AssertNoMessage();
        }
Exemplo n.º 11
0
        public void SetCommentSameComment()
        {
            JoinAsGuest(server, client, "Nickname");

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var s  = new ConnectionBuffer(cs.Item2);
            var c  = new ConnectionBuffer(cs.Item1);

            JoinAsGuest(s, c, "Nickname2");

            client.DequeueAndAssertMessage <UserJoinedMessage>();

            handler.OnSetCommentMessage(new MessageEventArgs <SetCommentMessage> (server,
                                                                                  new SetCommentMessage("comment")));

            var update = c.DequeueAndAssertMessage <UserUpdatedMessage>();

            Assert.AreEqual("comment", update.User.Comment);

            handler.OnSetCommentMessage(new MessageEventArgs <SetCommentMessage> (server,
                                                                                  new SetCommentMessage("comment")));

            c.AssertNoMessage();
        }
Exemplo n.º 12
0
        public void DeleteChannelUserIsIn()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.ChangeChannel);

            Assert.AreEqual(ChannelEditResult.Success, channels.SaveChannel(new ChannelInfo {
                Name = "Channel 2"
            }));
            client.DequeueAndAssertMessage <ChannelListMessage>();

            var channel = channels.GetChannels().Single(c => c.Name == "Channel 2");

            context.Users.Move(server, user, channel);
            client.DequeueAndAssertMessage <UserChangedChannelMessage>();

            permissions.EnablePermissions(user.UserId, PermissionName.DeleteChannel, PermissionName.RequestChannelList);

            handler.ChannelEditMessage(new MessageEventArgs <ChannelEditMessage> (server, new ChannelEditMessage
            {
                Channel = channel,
                Delete  = true
            }));

            var moved = client.DequeueAndAssertMessage <UserChangedChannelMessage>();

            Assert.AreEqual(user.UserId, moved.ChangeInfo.TargetUserId);
            Assert.AreEqual(channels.GetChannels().Single().ChannelId, moved.ChangeInfo.TargetChannelId);
            Assert.AreEqual(channel.ChannelId, moved.ChangeInfo.PreviousChannelId);
            Assert.AreEqual(0, moved.ChangeInfo.RequestingUserId);

            client.DequeueAndAssertMessage <ChannelListMessage>();

            var result = client.DequeueAndAssertMessage <ChannelEditResultMessage>();

            Assert.AreEqual(channel.ChannelId, result.ChannelId);
            Assert.AreEqual(ChannelEditResult.Success, result.Result);
        }
Exemplo n.º 13
0
        public void RequestSourceDefaultBitrate()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.RequestSource);

            var audioArgs = new AudioCodecArgs(AudioFormat.Mono16bitLPCM, 0, AudioSourceTests.FrameSize, 10);

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server, new RequestSourceMessage("Name", audioArgs)));

            var result = client.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.Succeeded, result.SourceResult);
            Assert.AreEqual("Name", result.SourceName);
            Assert.AreEqual("Name", result.Source.Name);

            audioArgs.Bitrate = defaultBitrate;
            AudioCodecArgsTests.AssertAreEqual(audioArgs, result.Source.CodecSettings);

            client.AssertNoMessage();
        }
Exemplo n.º 14
0
        public void Move()
        {
            IChannelInfo altChannel = new ChannelInfo {
                Name = "Channel 2"
            };

            context.ChannelsProvider.SaveChannel(altChannel);
            client.DequeueAndAssertMessage <ChannelListMessage>();
            observer.DequeueAndAssertMessage <ChannelListMessage>();

            altChannel = context.ChannelsProvider.GetChannels().Single(c => c.Name == "Channel 2");

            Connect();
            JoinAsGuest();

            IUserInfo user = handler.First();

            handler.Move(user, altChannel);

            var move = client.DequeueAndAssertMessage <UserChangedChannelMessage>();

            Assert.AreEqual(user.UserId, move.ChangeInfo.TargetUserId);
            Assert.AreEqual(altChannel.ChannelId, move.ChangeInfo.TargetChannelId);
            Assert.AreEqual(1, move.ChangeInfo.PreviousChannelId);
            Assert.AreEqual(0, move.ChangeInfo.RequestingUserId);

            move = observer.DequeueAndAssertMessage <UserChangedChannelMessage>();
            Assert.AreEqual(user.UserId, move.ChangeInfo.TargetUserId);
            Assert.AreEqual(altChannel.ChannelId, move.ChangeInfo.TargetChannelId);
            Assert.AreEqual(1, move.ChangeInfo.PreviousChannelId);
            Assert.AreEqual(0, move.ChangeInfo.RequestingUserId);
        }