2018-01-18 15:14:05 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Moq;
|
2018-06-28 13:40:30 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Data;
|
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
2018-09-04 10:58:56 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Runtime.Operations;
|
2018-10-03 14:35:27 +02:00
|
|
|
|
using SafeExamBrowser.Runtime.Operations.Events;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
2018-01-18 15:14:05 +01:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ConfigurationOperationTests
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private AppConfig appConfig;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
private Mock<ILogger> logger;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
private Mock<IConfigurationRepository> repository;
|
2018-06-28 13:40:30 +02:00
|
|
|
|
private Mock<IResourceLoader> resourceLoader;
|
2018-02-16 13:42:27 +01:00
|
|
|
|
private Settings settings;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
private ConfigurationOperation sut;
|
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig = new AppConfig();
|
2018-03-14 12:07:20 +01:00
|
|
|
|
logger = new Mock<ILogger>();
|
2018-02-06 15:12:11 +01:00
|
|
|
|
repository = new Mock<IConfigurationRepository>();
|
2018-06-28 13:40:30 +02:00
|
|
|
|
resourceLoader = new Mock<IResourceLoader>();
|
2018-02-16 13:42:27 +01:00
|
|
|
|
settings = new Settings();
|
2018-01-19 09:23:09 +01:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.AppDataFolder = @"C:\Not\Really\AppData";
|
|
|
|
|
appConfig.DefaultSettingsFileName = "SettingsDummy.txt";
|
|
|
|
|
appConfig.ProgramDataFolder = @"C:\Not\Really\ProgramData";
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
repository.SetupGet(r => r.CurrentSettings).Returns(settings);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustUseCommandLineArgumentAs1stPrio()
|
|
|
|
|
{
|
2018-06-27 14:02:16 +02:00
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
2018-09-04 10:58:56 +02:00
|
|
|
|
var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.ProgramDataFolder = location;
|
|
|
|
|
appConfig.AppDataFolder = location;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
2018-06-21 11:07:46 +02:00
|
|
|
|
sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-27 14:02:16 +02:00
|
|
|
|
var resource = new Uri(url);
|
2018-06-21 11:07:46 +02:00
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustUseProgramDataAs2ndPrio()
|
|
|
|
|
{
|
2018-09-04 10:58:56 +02:00
|
|
|
|
var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
2018-06-21 11:07:46 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.ProgramDataFolder = location;
|
|
|
|
|
appConfig.AppDataFolder = $@"{location}\WRONG";
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
2018-06-21 11:07:46 +02:00
|
|
|
|
sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
var resource = new Uri(Path.Combine(location, "SettingsDummy.txt"));
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustUseAppDataAs3rdPrio()
|
|
|
|
|
{
|
2018-09-04 10:58:56 +02:00
|
|
|
|
var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig.AppDataFolder = location;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
2018-06-21 11:07:46 +02:00
|
|
|
|
sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
var resource = new Uri(Path.Combine(location, "SettingsDummy.txt"));
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustFallbackToDefaultsAsLastPrio()
|
|
|
|
|
{
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
2018-06-21 11:07:46 +02:00
|
|
|
|
sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Verify(r => r.LoadDefaultSettings(), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustAbortIfWishedByUser()
|
|
|
|
|
{
|
2018-09-04 10:58:56 +02:00
|
|
|
|
appConfig.ProgramDataFolder = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
2018-06-21 09:14:14 +02:00
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is ConfigurationCompletedEventArgs c)
|
|
|
|
|
{
|
|
|
|
|
c.AbortStartup = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
var result = sut.Perform();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
Assert.AreEqual(OperationResult.Aborted, result);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotAbortIfNotWishedByUser()
|
|
|
|
|
{
|
2018-06-21 11:07:46 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is ConfigurationCompletedEventArgs c)
|
|
|
|
|
{
|
|
|
|
|
c.AbortStartup = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
var result = sut.Perform();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 11:07:46 +02:00
|
|
|
|
Assert.AreEqual(OperationResult.Success, result);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
}
|
2018-06-27 14:02:16 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotAllowToAbortIfNotInConfigureClientMode()
|
|
|
|
|
{
|
|
|
|
|
settings.ConfigurationMode = ConfigurationMode.Exam;
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is ConfigurationCompletedEventArgs c)
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail();
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-06-27 14:02:16 +02:00
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut.Perform();
|
2018-06-27 14:02:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotFailWithoutCommandLineArgs()
|
|
|
|
|
{
|
|
|
|
|
repository.Setup(r => r.LoadDefaultSettings());
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new string[] { });
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotFailWithInvalidUri()
|
|
|
|
|
{
|
|
|
|
|
var uri = @"an/invalid\uri.'*%yolo/()你好";
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", uri });
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustOnlyAllowToEnterAdminPasswordFiveTimes()
|
|
|
|
|
{
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.AdminPasswordNeeded);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Success = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, null), Times.Exactly(5));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustOnlyAllowToEnterSettingsPasswordFiveTimes()
|
|
|
|
|
{
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Success = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, null), Times.Exactly(5));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustSucceedIfAdminPasswordCorrect()
|
|
|
|
|
{
|
|
|
|
|
var password = "test";
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.AdminPasswordNeeded);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), password, null)).Returns(LoadStatus.Success);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Password = password;
|
|
|
|
|
p.Success = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
2018-06-28 13:40:30 +02:00
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, null), Times.Once);
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), password, null), Times.Once);
|
2018-06-27 14:02:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustSucceedIfSettingsPasswordCorrect()
|
|
|
|
|
{
|
|
|
|
|
var password = "test";
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, password)).Returns(LoadStatus.Success);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Password = password;
|
|
|
|
|
p.Success = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-27 14:02:16 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
2018-06-28 13:40:30 +02:00
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, null), Times.Once);
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, password), Times.Once);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustAbortAskingForAdminPasswordIfDecidedByUser()
|
|
|
|
|
{
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.AdminPasswordNeeded);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Success = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Perform();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Aborted, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustAbortAskingForSettingsPasswordIfDecidedByUser()
|
|
|
|
|
{
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Success = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Perform();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Aborted, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustAllowEnteringBothPasswords()
|
|
|
|
|
{
|
|
|
|
|
var adminPassword = "xyz";
|
|
|
|
|
var settingsPassword = "abc";
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, settingsPassword)).Returns(LoadStatus.AdminPasswordNeeded);
|
2018-06-28 13:40:30 +02:00
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), adminPassword, settingsPassword)).Returns(LoadStatus.Success);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
|
|
|
|
sut.ActionRequired += args =>
|
|
|
|
|
{
|
|
|
|
|
if (args is PasswordRequiredEventArgs p)
|
|
|
|
|
{
|
|
|
|
|
p.Password = p.Purpose == PasswordRequestPurpose.Administrator ? adminPassword : settingsPassword;
|
|
|
|
|
p.Success = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-28 13:40:30 +02:00
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, null), Times.Once);
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), null, settingsPassword), Times.Once);
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.IsAny<Uri>(), adminPassword, settingsPassword), Times.Once);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotWaitForPasswordViaClientIfCommunicationHasFailed()
|
|
|
|
|
{
|
|
|
|
|
var clientProxy = new Mock<IClientProxy>();
|
|
|
|
|
var communication = new CommunicationResult(false);
|
|
|
|
|
var session = new Mock<ISessionData>();
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
clientProxy.Setup(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>())).Returns(communication);
|
2018-06-28 13:40:30 +02:00
|
|
|
|
repository.SetupGet(r => r.CurrentSession).Returns(session.Object);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
|
|
|
|
session.SetupGet(r => r.ClientProxy).Returns(clientProxy.Object);
|
|
|
|
|
settings.KioskMode = KioskMode.CreateNewDesktop;
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Perform();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Aborted, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustHandleInvalidData()
|
|
|
|
|
{
|
|
|
|
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
|
|
|
|
|
resourceLoader.Setup(r => r.IsHtmlResource(It.IsAny<Uri>())).Returns(false);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.InvalidData);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Perform();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Failed, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustHandleHtmlAsInvalidData()
|
|
|
|
|
{
|
|
|
|
|
var url = "http://www.blubb.org/some/resource.html";
|
|
|
|
|
|
|
|
|
|
resourceLoader.Setup(r => r.IsHtmlResource(It.IsAny<Uri>())).Returns(true);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.InvalidData);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Perform();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, result);
|
|
|
|
|
Assert.AreEqual(url, settings.Browser.StartUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustReconfigureSuccessfullyWithCorrectUri()
|
|
|
|
|
{
|
|
|
|
|
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
2018-09-04 10:58:56 +02:00
|
|
|
|
var resource = new Uri(Path.Combine(location, nameof(Operations), "SettingsDummy.txt"));
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
repository.SetupGet(r => r.ReconfigurationFilePath).Returns(resource.AbsolutePath);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null)).Returns(LoadStatus.Success);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Repeat();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustFailToReconfigureWithInvalidUri()
|
|
|
|
|
{
|
|
|
|
|
var resource = new Uri("file:///C:/does/not/exist.txt");
|
|
|
|
|
|
|
|
|
|
repository.SetupGet(r => r.ReconfigurationFilePath).Returns(null as string);
|
|
|
|
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, null);
|
2018-06-28 13:40:30 +02:00
|
|
|
|
|
|
|
|
|
var result = sut.Repeat();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Never);
|
|
|
|
|
Assert.AreEqual(OperationResult.Failed, result);
|
|
|
|
|
|
|
|
|
|
repository.SetupGet(r => r.ReconfigurationFilePath).Returns(resource.AbsolutePath);
|
|
|
|
|
result = sut.Repeat();
|
|
|
|
|
|
|
|
|
|
repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Never);
|
|
|
|
|
Assert.AreEqual(OperationResult.Failed, result);
|
2018-06-27 14:02:16 +02:00
|
|
|
|
}
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|