Example #1
0
            public void WithExistingDeviceIdIsRecognized()
            {
                var accessControl = new AccessControl(new CoreSettings());

                Guid accessToken = accessControl.RegisterRemoteAccessToken(new Guid());

                Guid existingAccessToken = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Equal(accessToken, existingAccessToken);
            }
Example #2
0
            public void WithRemoteAccessTokenThrowsArgumentException()
            {
                var settings      = new CoreSettings();
                var accessControl = new AccessControl(settings);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws <ArgumentException>(() => accessControl.UpgradeLocalAccess(token, "password123"));
            }
Example #3
0
            public async Task SmokeTest()
            {
                AccessControl accessControl = SetupVotableAccessControl(2);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                accessControl.RegisterVote(token, SetupVotedEntry());

                Assert.Equal(1, await accessControl.ObserveRemainingVotes(token).FirstAsync());
            }
Example #4
0
            public void ThrowsInvalidOperationExceptionIfGuestSystemIsDisabled()
            {
                var settings = new CoreSettings {
                    EnableGuestSystem = false
                };

                var  accessControl = new AccessControl(settings);
                Guid token         = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws <InvalidOperationException>(() => accessControl.RegisterVote(token, SetupVotedEntry()));
            }
Example #5
0
            public void WithoutVotesLeftThrowsInvalidOperationException()
            {
                var settings = new CoreSettings
                {
                    EnableGuestSystem = true,
                    MaxVoteCount      = 0
                };
                var  accessControl = new AccessControl(settings);
                Guid token         = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws <InvalidOperationException>(() => accessControl.RegisterVote(token, new PlaylistEntry(0, Helpers.SetupSongMock())));
            }
Example #6
0
        public void RegisterVoteForSameEntryThrowsInvalidOperationException()
        {
            var settings = new CoreSettings { MaxVoteCount = 2 };
            var accessControl = new AccessControl(settings);
            Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

            var entry = SetupVotedEntry();

            accessControl.RegisterVote(token, entry);
            entry.Vote();
            Assert.Throws<InvalidOperationException>(() => accessControl.RegisterVote(token, entry));
        }
Example #7
0
        public void UnlockedRemoteControlGivesAdminRightsByDefault()
        {
            var settings = new CoreSettings
            {
                LockRemoteControl = false
            };

            var accessControl = new AccessControl(settings);

            Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

            accessControl.VerifyAccess(token);
        }
Example #8
0
        public void UnlockedRemoteControlGivesAdminRightsByDefault()
        {
            var settings = new CoreSettings
            {
                LockRemoteControl = false
            };

            var accessControl = new AccessControl(settings);

            Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

            accessControl.VerifyAccess(token);
        }
Example #9
0
            public void ThrowsWrongPasswordExceptionOnWrongPassword()
            {
                var settings = new CoreSettings
                {
                    RemoteControlPassword = "******"
                };

                var accessControl = new AccessControl(settings);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws <WrongPasswordException>(() => accessControl.UpgradeRemoteAccess(token, "lolol"));
            }
Example #10
0
        public void LockedRemoteControlGivesGuestRightsByDefault()
        {
            var settings = new CoreSettings
            {
                LockRemoteControl     = true,
                RemoteControlPassword = "******"
            };

            var accessControl = new AccessControl(settings);

            Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

            Assert.Throws <AccessException>(() => accessControl.VerifyAccess(token));
        }
Example #11
0
        public void LockedRemoteControlGivesGuestRightsByDefault()
        {
            var settings = new CoreSettings
            {
                LockRemoteControl = true,
                RemoteControlPassword = "******"
            };

            var accessControl = new AccessControl(settings);

            Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

            Assert.Throws<AccessException>(() => accessControl.VerifyAccess(token));
        }
Example #12
0
            public void SmokeTest()
            {
                var settings = new CoreSettings {
                    EnableGuestSystem = true
                };
                var  accessControl = new AccessControl(settings);
                Guid token         = accessControl.RegisterRemoteAccessToken(new Guid());

                var entry = SetupVotedEntry();

                accessControl.RegisterVote(token, entry);

                Assert.True(accessControl.IsVoteRegistered(token, entry));
                Assert.False(accessControl.IsVoteRegistered(token, new PlaylistEntry(0, Helpers.SetupSongMock())));
            }
Example #13
0
        public void RegisteredVoteUnregistersAutomaticallyWhenEntryvoteCountIsReset()
        {
            var settings = new CoreSettings { MaxVoteCount = 2 };
            var accessControl = new AccessControl(settings);
            Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

            var entry = new PlaylistEntry(0, Helpers.SetupSongMock());
            entry.Vote();

            var votes = accessControl.ObserveRemainingVotes(token).CreateCollection();
            accessControl.RegisterVote(token, entry);

            entry.ResetVotes();

            Assert.Equal(new int?[] { 2, 1, 2 }, votes);
        }
Example #14
0
            public void UpgradesToAdmin()
            {
                var settings = new CoreSettings
                {
                    LockRemoteControl     = true,
                    RemoteControlPassword = "******"
                };

                var accessControl = new AccessControl(settings);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                accessControl.UpgradeRemoteAccess(token, "password123");

                accessControl.VerifyAccess(token);
            }
Example #15
0
            public void ThrowsInvalidOperationExceptionIfGuestSystemIsDisabled()
            {
                var settings = new CoreSettings
                {
                    EnableGuestSystem = false,
                    LockRemoteControl = true
                };

                var  accessControl = new AccessControl(settings);
                Guid localToken    = accessControl.RegisterLocalAccessToken();

                accessControl.SetRemotePassword(localToken, "Password");

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws <InvalidOperationException>(() => accessControl.RegisterShadowVote(token, SetupShadowVotedEntry()));
            }
Example #16
0
            public void UpdatesOnlyRemoteAccessPermissions()
            {
                var settings = new CoreSettings
                {
                    LockRemoteControl     = true,
                    RemoteControlPassword = null
                };

                var accessControl = new AccessControl(settings);

                Guid localToken = accessControl.RegisterLocalAccessToken();

                Guid remoteToken       = accessControl.RegisterRemoteAccessToken(new Guid());
                var  remotePermissions = accessControl.ObserveAccessPermission(remoteToken).CreateCollection();

                accessControl.SetRemotePassword(localToken, "password");

                Assert.Equal(AccessPermission.Admin, accessControl.ObserveAccessPermission(localToken).FirstAsync().Wait());
                Assert.Equal(new[] { AccessPermission.Admin, AccessPermission.Guest }, remotePermissions);
            }
Example #17
0
        public void UpdatesRemoteAccessWhenLockRemoteSettingChanges()
        {
            var settings = new CoreSettings
            {
                LockRemoteControl = false
            };

            var accessControl = new AccessControl(settings);

            Guid remoteToken = accessControl.RegisterRemoteAccessToken(new Guid());
            Guid adminToken  = accessControl.RegisterLocalAccessToken();

            var permissions = accessControl.ObserveAccessPermission(remoteToken).CreateCollection();

            settings.LockRemoteControl = true;
            accessControl.SetRemotePassword(adminToken, "password");

            settings.LockRemoteControl = false;
            settings.LockRemoteControl = true;

            Assert.Equal(new[] { AccessPermission.Admin, AccessPermission.Guest, AccessPermission.Admin, AccessPermission.Guest }, permissions);
        }
Example #18
0
            public void UpdatesOnlyRemoteAccessPermissions()
            {
                var settings = new CoreSettings
                {
                    LockRemoteControl = true,
                    RemoteControlPassword = null
                };

                var accessControl = new AccessControl(settings);

                Guid localToken = accessControl.RegisterLocalAccessToken();

                Guid remoteToken = accessControl.RegisterRemoteAccessToken(new Guid());
                var remotePermissions = accessControl.ObserveAccessPermission(remoteToken).CreateCollection();

                accessControl.SetRemotePassword(localToken, "password");

                Assert.Equal(AccessPermission.Admin, accessControl.ObserveAccessPermission(localToken).FirstAsync().Wait());
                Assert.Equal(new[] { AccessPermission.Admin, AccessPermission.Guest }, remotePermissions);
            }
Example #19
0
            public void SmokeTest()
            {
                var settings = new CoreSettings { EnableVotingSystem = true };
                var accessControl = new AccessControl(settings);
                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                var entry = SetupVotedEntry();
                accessControl.RegisterVote(token, entry);

                Assert.True(accessControl.IsVoteRegistered(token, entry));
                Assert.False(accessControl.IsVoteRegistered(token, new PlaylistEntry(0, Helpers.SetupSongMock())));
            }
Example #20
0
            public async Task ReturnsCurrentValueImmediately()
            {
                var settings = new CoreSettings();
                var accessControl = new AccessControl(settings);
                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Equal(settings.MaxVoteCount, await accessControl.ObserveRemainingVotes(token).FirstAsync());
            }
Example #21
0
            public void SmokeTest()
            {
                var settings = new CoreSettings();
                var accessControl = new AccessControl(settings);
                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                var votes = accessControl.ObserveRemainingVotes(token).CreateCollection();

                accessControl.RegisterVote(token, SetupVotedEntry());
                accessControl.RegisterVote(token, SetupVotedEntry());

                Assert.Equal(new int?[] { 2, 1, 0 }, votes);
            }
Example #22
0
            public void WithExistingDeviceIdIsRecognized()
            {
                var accessControl = new AccessControl(new CoreSettings());

                Guid accessToken = accessControl.RegisterRemoteAccessToken(new Guid());

                Guid existingAccessToken = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Equal(accessToken, existingAccessToken);
            }
Example #23
0
            public async Task SmokeTest()
            {
                var settings = new CoreSettings
                {
                    EnableVotingSystem = true,
                    MaxVoteCount = 2
                };
                var accessControl = new AccessControl(settings);
                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                accessControl.RegisterVote(token, SetupVotedEntry());

                Assert.Equal(settings.MaxVoteCount - 1, await accessControl.ObserveRemainingVotes(token).FirstAsync());
            }
Example #24
0
            public void WithRemoteAccessTokenThrowsArgumentException()
            {
                var settings = new CoreSettings();
                var accessControl = new AccessControl(settings);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws<ArgumentException>(() => accessControl.UpgradeLocalAccess(token, "password123"));
            }
Example #25
0
        public void UpdatesRemoteAccessWhenLockRemoteSettingChanges()
        {
            var settings = new CoreSettings
            {
                LockRemoteControl = false
            };

            var accessControl = new AccessControl(settings);

            Guid remoteToken = accessControl.RegisterRemoteAccessToken(new Guid());
            Guid adminToken = accessControl.RegisterLocalAccessToken();

            var permissions = accessControl.ObserveAccessPermission(remoteToken).CreateCollection();

            settings.LockRemoteControl = true;
            accessControl.SetRemotePassword(adminToken, "password");

            settings.LockRemoteControl = false;
            settings.LockRemoteControl = true;

            Assert.Equal(new[] { AccessPermission.Admin, AccessPermission.Guest, AccessPermission.Admin, AccessPermission.Guest }, permissions);
        }
Example #26
0
            public void ThrowsWrongPasswordExceptionOnWrongPassword()
            {
                var settings = new CoreSettings
                {
                    RemoteControlPassword = "******"
                };

                var accessControl = new AccessControl(settings);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws<WrongPasswordException>(() => accessControl.UpgradeRemoteAccess(token, "lolol"));
            }
Example #27
0
            public void ThrowsInvalidOperationExceptionIfVotingIsDisabled()
            {
                var settings = new CoreSettings { EnableVotingSystem = false };

                var accessControl = new AccessControl(settings);
                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws<InvalidOperationException>(() => accessControl.RegisterVote(token, SetupVotedEntry()));
            }
Example #28
0
            public void UpgradesToAdmin()
            {
                var settings = new CoreSettings
                {
                    LockRemoteControl = true,
                    RemoteControlPassword = "******"
                };

                var accessControl = new AccessControl(settings);

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                accessControl.UpgradeRemoteAccess(token, "password123");

                accessControl.VerifyAccess(token);
            }
            public void ThrowsInvalidOperationExceptionIfGuestSystemIsDisabled()
            {
                var settings = new CoreSettings
                {
                    EnableGuestSystem = false,
                    LockRemoteControl = true
                };

                var accessControl = new AccessControl(settings);
                Guid localToken = accessControl.RegisterLocalAccessToken();
                accessControl.SetRemotePassword(localToken, "Password");

                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws<InvalidOperationException>(() => accessControl.RegisterShadowVote(token, SetupShadowVotedEntry()));
            }
Example #30
0
            public void WithoutVotesLeftThrowsInvalidOperationException()
            {
                var settings = new CoreSettings
                {
                    EnableVotingSystem = true,
                    MaxVoteCount = 0
                };
                var accessControl = new AccessControl(settings);
                Guid token = accessControl.RegisterRemoteAccessToken(new Guid());

                Assert.Throws<InvalidOperationException>(() => accessControl.RegisterVote(token, new PlaylistEntry(0, Helpers.SetupSongMock())));
            }