Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void MoveToUnknownChannel()
        {
            Connect();
            JoinAsGuest();

            IUserInfo user = handler.First();

            handler.Move(user, new ChannelInfo());

            client.AssertNoMessage();
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        public void RequestMuteWithoutPermission()
        {
            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 source = GetSourceFromRequest();

            Assert.AreEqual(SourceResult.NewSource, cl.DequeueAndAssertMessage <SourceResultMessage>().SourceResult);
            cl.AssertNoMessage();

            handler.RequestMuteSourceMessage(new MessageEventArgs <RequestMuteSourceMessage> (c,
                                                                                              new RequestMuteSourceMessage(source, true)));

            var denied = cl.DequeueAndAssertMessage <PermissionDeniedMessage>();

            Assert.AreEqual(GablarskiMessageType.RequestMuteSource, denied.DeniedMessage);
            cl.AssertNoMessage();
        }
Ejemplo n.º 15
0
        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();
        }
Ejemplo n.º 16
0
        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();
        }
Ejemplo n.º 17
0
        public void SetPermissionsNotConnected()
        {
            permissions.UpdatedSupported = true;

            var u = UserInfoTests.GetTestUser();

            permissions.EnablePermissions(u.UserId, PermissionName.ModifyPermissions);

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

            cs.Item2.DisconnectAsync().Wait();

            handler.OnSetPermissionsMessage(new MessageEventArgs <SetPermissionsMessage> (c,
                                                                                          new SetPermissionsMessage(u, new Permission[0])));

            c.AssertNoMessage();
        }
Ejemplo n.º 18
0
        public void SendAudioDataMessageNotJoined()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);

            handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (c,
                                                                                            new ClientAudioDataMessage
            {
                Data       = new [] { new byte[512] },
                SourceId   = 1,
                TargetType = TargetType.Channel,
                TargetIds  = new [] { 1 }
            }));

            cl.AssertNoMessage();
            client.AssertNoMessage();
        }
Ejemplo n.º 19
0
        public void ClientAudioSourceStateChangedUserMuted()
        {
            var u = UserInfoTests.GetTestUser(2, 1, true);

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

            client.AssertNoMessage();
            cl.AssertNoMessage();
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        public void RegistrationApprovalMessageUnknownUser()
        {
            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;

            permissions.UpdatedSupported = true;
            permissions.EnablePermissions(u.UserId, PermissionName.ApproveRegistrations);

            handler.OnRegistrationApprovalMessage(new MessageEventArgs <RegistrationApprovalMessage> (s,
                                                                                                      new RegistrationApprovalMessage {
                Approved = true, UserId = 2
            }));

            c.AssertNoMessage();
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        public void SetPermissionsUnsupported()
        {
            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 []
            {
                new Permission(PermissionName.SendAudio, true),
                new Permission(PermissionName.SendAudioToMultipleTargets, false),
                new Permission(PermissionName.KickPlayerFromChannel, true)
                {
                    ChannelId = 1
                },
            })));

            c.AssertNoMessage();
        }
Ejemplo n.º 24
0
        public IUserInfo JoinAsGuest(ConnectionBuffer sc, ConnectionBuffer cc, bool connect, bool shouldWork, bool allowGuests, string serverPassword, string nickname, string userServerpassword)
        {
            context.Settings.AllowGuestLogins = allowGuests;
            context.Settings.ServerPassword   = serverPassword;

            if (connect)
            {
                handler.Manager.Connect(sobserver);
                handler.Manager.Connect(sc);
            }

            handler.OnJoinMessage(new MessageEventArgs <JoinMessage> (sc,
                                                                      new JoinMessage(nickname, userServerpassword)));

            if (shouldWork)
            {
                Assert.IsTrue(handler.Manager.GetIsJoined(sc), "User is not joined");

                var msg = cc.DequeueAndAssertMessage <JoinResultMessage>();
                Assert.AreEqual(nickname, msg.UserInfo.Nickname);

                cc.DequeueAndAssertMessage <PermissionsMessage>();
                cc.DequeueAndAssertMessage <UserJoinedMessage>();

                observer.DequeueAndAssertMessage <UserJoinedMessage>();

                return(msg.UserInfo);
            }
            else
            {
                Assert.IsFalse(handler.Manager.GetIsJoined(sc), "User joined");
                observer.AssertNoMessage();

                return(null);
            }
        }
Ejemplo n.º 25
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();
        }
Ejemplo n.º 26
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();
        }
Ejemplo n.º 27
0
        public void SetStatusSameStatus()
        {
            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);

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

            c.AssertNoMessage();
        }
Ejemplo n.º 28
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();
        }