Пример #1
0
        public void Perform_MustOnlyAllowToEnterAdminPasswordFiveTimes()
        {
            var count         = 0;
            var localSettings = new AppSettings();
            var settings      = new AppSettings {
                ConfigurationMode = ConfigurationMode.ConfigureClient
            };
            var url = @"http://www.safeexambrowser.org/whatever.seb";

            appConfig.AppDataFilePath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), "Testdata", FILE_NAME);
            localSettings.Security.AdminPasswordHash = "1234";
            settings.Security.AdminPasswordHash      = "9876";

            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            repository.Setup(r => r.TryLoadSettings(It.Is <Uri>(u => u.LocalPath.Contains(FILE_NAME)), out localSettings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            nextSession.Settings = settings;

            var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            sut.ActionRequired += args =>
            {
                if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator)
                {
                    count++;
                    p.Success = true;
                }
            };

            var result = sut.Perform();

            Assert.AreEqual(5, count);
            Assert.AreEqual(OperationResult.Failed, result);
        }
		public void Perform_MustAbortAskingForAdminPasswordIfDecidedByUser()
		{
			var password = "******";
			var currentSettings = new Settings { AdminPasswordHash = "1234", ConfigurationMode = ConfigurationMode.ConfigureClient };
			var nextSettings = new Settings { AdminPasswordHash = "9876", ConfigurationMode = ConfigurationMode.ConfigureClient };
			var url = @"http://www.safeexambrowser.org/whatever.seb";

			appConfig.AppDataFilePath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), FILE_NAME);
			nextSession.SetupGet(s => s.Settings).Returns(nextSettings);

			hashAlgorithm.Setup(h => h.GenerateHashFor(It.Is<string>(p => p == password))).Returns(currentSettings.AdminPasswordHash);
			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out currentSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
			repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);

			var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			sut.ActionRequired += args =>
			{
				if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator)
				{
					p.Success = false;
				}
			};

			var result = sut.Perform();

			repository.Verify(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>()), Times.Never);

			Assert.AreEqual(OperationResult.Aborted, result);
		}
Пример #3
0
        public void Perform_MustOnlyAllowToEnterSettingsPasswordFiveTimes()
        {
            var count    = 0;
            var settings = default(AppSettings);
            var url      = @"http://www.safeexambrowser.org/whatever.seb";

            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);

            var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            sut.ActionRequired += args =>
            {
                if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.Settings)
                {
                    count++;
                    p.Success = true;
                }
            };

            var result = sut.Perform();

            repository.Verify(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>()), Times.Exactly(6));

            Assert.AreEqual(5, count);
            Assert.AreEqual(OperationResult.Failed, result);
        }
Пример #4
0
        public void Perform_MustNotAuthenticateIfSameAdminPassword()
        {
            var currentSettings = new AppSettings {
                ConfigurationMode = ConfigurationMode.ConfigureClient
            };
            var nextSettings = new AppSettings {
                ConfigurationMode = ConfigurationMode.ConfigureClient
            };
            var url = @"http://www.safeexambrowser.org/whatever.seb";

            currentSettings.Security.AdminPasswordHash = "1234";
            nextSession.Settings = nextSettings;
            nextSettings.Security.AdminPasswordHash = "1234";
            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out currentSettings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            repository.Setup(r => r.TryLoadSettings(It.Is <Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            repository.Setup(r => r.ConfigureClientWith(It.IsAny <Uri>(), It.IsAny <PasswordParameters>())).Returns(SaveStatus.Success);

            var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            sut.ActionRequired += args =>
            {
                if (args is PasswordRequiredEventArgs)
                {
                    Assert.Fail();
                }
            };

            var result = sut.Perform();

            hashAlgorithm.Verify(h => h.GenerateHashFor(It.IsAny <string>()), Times.Never);

            Assert.AreEqual(OperationResult.Success, result);
        }
		public void Perform_MustNotAuthenticateIfSameAdminPassword()
		{
			var currentSettings = new Settings { AdminPasswordHash = "1234", ConfigurationMode = ConfigurationMode.ConfigureClient };
			var nextSettings = new Settings { AdminPasswordHash = "1234", ConfigurationMode = ConfigurationMode.ConfigureClient };
			var url = @"http://www.safeexambrowser.org/whatever.seb";

			appConfig.AppDataFilePath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), FILE_NAME);
			nextSession.SetupGet(s => s.Settings).Returns(nextSettings);

			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out currentSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
			repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
			repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);

			var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			sut.ActionRequired += args =>
			{
				if (args is PasswordRequiredEventArgs)
				{
					Assert.Fail();
				}
			};

			var result = sut.Perform();

			hashAlgorithm.Verify(h => h.GenerateHashFor(It.IsAny<string>()), Times.Never);

			Assert.AreEqual(OperationResult.Success, result);
		}
Пример #6
0
        public void Perform_MustSucceedIfSettingsPasswordCorrect()
        {
            var password = "******";
            var settings = new AppSettings {
                ConfigurationMode = ConfigurationMode.Exam
            };
            var url = @"http://www.safeexambrowser.org/whatever.seb";

            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);
            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.Is <PasswordParameters>(p => p.Password == password))).Returns(LoadStatus.Success);

            var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            sut.ActionRequired += args =>
            {
                if (args is PasswordRequiredEventArgs p)
                {
                    p.Password = password;
                    p.Success  = true;
                }
            };

            var result = sut.Perform();

            repository.Verify(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.Is <PasswordParameters>(p => p.Password == password)), Times.AtLeastOnce);

            Assert.AreEqual(OperationResult.Success, result);
        }
Пример #7
0
        public void Perform_MustUseCurrentPasswordIfAvailable()
        {
            var url      = @"http://www.safeexambrowser.org/whatever.seb";
            var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), "Testdata", FILE_NAME);
            var settings = new AppSettings {
                ConfigurationMode = ConfigurationMode.Exam
            };

            appConfig.AppDataFilePath           = location;
            settings.Security.AdminPasswordHash = "1234";

            repository
            .Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>()))
            .Returns(LoadStatus.PasswordNeeded);
            repository
            .Setup(r => r.TryLoadSettings(It.Is <Uri>(u => u.Equals(new Uri(location))), out settings, It.IsAny <PasswordParameters>()))
            .Returns(LoadStatus.Success);
            repository
            .Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.Is <PasswordParameters>(p => p.IsHash == true && p.Password == settings.Security.AdminPasswordHash)))
            .Returns(LoadStatus.Success);

            var sut    = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
            var result = sut.Perform();

            repository.Verify(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.Is <PasswordParameters>(p => p.Password == settings.Security.AdminPasswordHash)), Times.AtLeastOnce);

            Assert.AreEqual(OperationResult.Success, result);
        }
Пример #8
0
        public void Perform_MustInformAboutClientConfigurationError()
        {
            var informed = false;
            var settings = new AppSettings();
            var url      = @"http://www.safeexambrowser.org/whatever.seb";

            settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            repository.Setup(r => r.ConfigureClientWith(It.IsAny <Uri>(), It.IsAny <PasswordParameters>())).Returns(SaveStatus.UnexpectedError);

            var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            sut.ActionRequired += args =>
            {
                if (args is ClientConfigurationErrorMessageArgs)
                {
                    informed = true;
                }
            };

            var result = sut.Perform();

            Assert.AreEqual(OperationResult.Failed, result);
            Assert.IsTrue(informed);
        }
        public void Perform_MustSucceedIfAdminPasswordTestdata()
        {
            var password        = "******";
            var currentSettings = new ApplicationSettings {
                AdminPasswordHash = "1234", ConfigurationMode = ConfigurationMode.ConfigureClient
            };
            var nextSettings = new ApplicationSettings {
                AdminPasswordHash = "9876", ConfigurationMode = ConfigurationMode.ConfigureClient
            };
            var url = @"http://www.safeexambrowser.org/whatever.seb";

            nextSession.Settings = nextSettings;
            hashAlgorithm.Setup(h => h.GenerateHashFor(It.Is <string>(p => p == password))).Returns(currentSettings.AdminPasswordHash);
            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out currentSettings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            repository.Setup(r => r.TryLoadSettings(It.Is <Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);
            repository.Setup(r => r.ConfigureClientWith(It.IsAny <Uri>(), It.IsAny <PasswordParameters>())).Returns(SaveStatus.Success);

            var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            sut.ActionRequired += args =>
            {
                if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator)
                {
                    p.Password = password;
                    p.Success  = true;
                }
            };

            var result = sut.Perform();

            repository.Verify(r => r.ConfigureClientWith(It.IsAny <Uri>(), It.IsAny <PasswordParameters>()), Times.Once);

            Assert.AreEqual(OperationResult.Success, result);
        }
Пример #10
0
        public void Perform_MustNotFailWithInvalidUri()
        {
            var uri    = @"an/invalid\uri.'*%yolo/()你好";
            var sut    = new ConfigurationOperation(new[] { "blubb.exe", uri }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
            var result = sut.Perform();

            Assert.AreEqual(OperationResult.Success, result);
        }
		public void Perform_MustCorrectlyHandleBrowserResource()
		{
			var settings = new Settings { ConfigurationMode = ConfigurationMode.Exam };
			var url = @"http://www.safeexambrowser.org/whatever.seb";

			nextSession.SetupGet(s => s.Settings).Returns(settings);
			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.LoadWithBrowser);

			var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			var result = sut.Perform();

			Assert.AreEqual(url, settings.Browser.StartUrl);
			Assert.AreEqual(OperationResult.Success, result);
		}
Пример #12
0
        public void Perform_MustUseAppDataAs3rdPrio()
        {
            var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), "Testdata", FILE_NAME);
            var settings = default(AppSettings);

            appConfig.AppDataFilePath = location;
            repository.Setup(r => r.TryLoadSettings(It.IsAny <Uri>(), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success);

            var sut    = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
            var result = sut.Perform();

            repository.Verify(r => r.TryLoadSettings(It.Is <Uri>(u => u.Equals(location)), out settings, It.IsAny <PasswordParameters>()), Times.Once);
            Assert.AreEqual(OperationResult.Success, result);
        }
Пример #13
0
        public void Perform_MustFallbackToDefaultsAsLastPrio()
        {
            var defaultSettings = new AppSettings();

            repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings);

            var sut    = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
            var result = sut.Perform();

            repository.Verify(r => r.LoadDefaultSettings(), Times.Once);

            Assert.AreEqual(OperationResult.Success, result);
            Assert.AreSame(defaultSettings, nextSession.Settings);
        }
		public void Perform_MustFallbackToDefaultsAsLastPrio()
		{
			var actualSettings = default(Settings);
			var defaultSettings = new Settings();

			repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings);
			nextSession.SetupSet<Settings>(s => s.Settings = It.IsAny<Settings>()).Callback(s => actualSettings = s);

			var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			var result = sut.Perform();

			repository.Verify(r => r.LoadDefaultSettings(), Times.Once);
			nextSession.VerifySet(s => s.Settings = defaultSettings);

			Assert.AreEqual(OperationResult.Success, result);
			Assert.AreSame(defaultSettings, actualSettings);
		}
		public void Perform_MustUseCommandLineArgumentAs1stPrio()
		{
			var settings = new Settings { ConfigurationMode = ConfigurationMode.Exam };
			var url = @"http://www.safeexambrowser.org/whatever.seb";
			var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), FILE_NAME);

			appConfig.AppDataFilePath = location;
			appConfig.ProgramDataFilePath = location;

			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);

			var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			var result = sut.Perform();
			var resource = new Uri(url);

			repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>()), Times.Once);
			Assert.AreEqual(OperationResult.Success, result);
		}
		public void Perform_MustNotAllowToAbortIfNotInConfigureClientMode()
		{
			var settings = new Settings();

			settings.ConfigurationMode = ConfigurationMode.Exam;
			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);

			var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			sut.ActionRequired += args =>
			{
				if (args is ConfigurationCompletedEventArgs c)
				{
					Assert.Fail();
				}
			};

			var result = sut.Perform();

			Assert.AreEqual(OperationResult.Success, result);
		}
		public void Perform_MustAbortAskingForSettingsPasswordIfDecidedByUser()
		{
			var settings = default(Settings);
			var url = @"http://www.safeexambrowser.org/whatever.seb";

			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);

			var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			sut.ActionRequired += args =>
			{
				if (args is PasswordRequiredEventArgs p)
				{
					p.Success = false;
				}
			};

			var result = sut.Perform();

			Assert.AreEqual(OperationResult.Aborted, result);
		}
Пример #18
0
        public void MustCorrectlySetConfiguration()
        {
            var response = new ConfigurationResponse
            {
                Configuration = new ClientConfiguration
                {
                    AppConfig = new AppConfig(),
                    SessionId = Guid.NewGuid(),
                    Settings  = new Settings()
                }
            };

            runtime.Setup(r => r.GetConfiguration()).Returns(new CommunicationResult <ConfigurationResponse>(true, response));

            var result = sut.Perform();

            Assert.AreSame(configuration.AppConfig, response.Configuration.AppConfig);
            Assert.AreEqual(configuration.SessionId, response.Configuration.SessionId);
            Assert.AreSame(configuration.Settings, response.Configuration.Settings);
            Assert.AreEqual(OperationResult.Success, result);
        }
		public void Perform_MustNotAbortIfNotWishedByUser()
		{
			var settings = new Settings();
			var url = @"http://www.safeexambrowser.org/whatever.seb";

			settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
			repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
			repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);

			var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext);
			sut.ActionRequired += args =>
			{
				if (args is ConfigurationCompletedEventArgs c)
				{
					c.AbortStartup = false;
				}
			};

			var result = sut.Perform();

			Assert.AreEqual(OperationResult.Success, result);
		}
Пример #20
0
        public void Perform_MustNotFailWithoutCommandLineArgs()
        {
            var defaultSettings = new AppSettings();
            var result          = OperationResult.Failed;

            repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings);

            var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);

            result = sut.Perform();

            repository.Verify(r => r.LoadDefaultSettings(), Times.Once);
            Assert.AreEqual(OperationResult.Success, result);
            Assert.AreSame(defaultSettings, nextSession.Settings);

            sut    = new ConfigurationOperation(new string[] { }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
            result = sut.Perform();

            repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2));
            Assert.AreEqual(OperationResult.Success, result);
            Assert.AreSame(defaultSettings, nextSession.Settings);
        }