SEBWIN-420: Ensured the temporary directory is always created for every new session.
This commit is contained in:
parent
867bcfe6a7
commit
68360a603d
5 changed files with 29 additions and 5 deletions
|
@ -14,6 +14,7 @@ using SafeExamBrowser.Configuration.Contracts;
|
||||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||||
using SafeExamBrowser.Logging.Contracts;
|
using SafeExamBrowser.Logging.Contracts;
|
||||||
using SafeExamBrowser.Runtime.Operations;
|
using SafeExamBrowser.Runtime.Operations;
|
||||||
|
using SafeExamBrowser.SystemComponents.Contracts;
|
||||||
|
|
||||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
{
|
{
|
||||||
private AppConfig appConfig;
|
private AppConfig appConfig;
|
||||||
private Mock<IConfigurationRepository> configuration;
|
private Mock<IConfigurationRepository> configuration;
|
||||||
|
private Mock<IFileSystem> fileSystem;
|
||||||
private Mock<ILogger> logger;
|
private Mock<ILogger> logger;
|
||||||
private Mock<IRuntimeHost> runtimeHost;
|
private Mock<IRuntimeHost> runtimeHost;
|
||||||
private SessionConfiguration session;
|
private SessionConfiguration session;
|
||||||
|
@ -34,6 +36,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
{
|
{
|
||||||
appConfig = new AppConfig();
|
appConfig = new AppConfig();
|
||||||
configuration = new Mock<IConfigurationRepository>();
|
configuration = new Mock<IConfigurationRepository>();
|
||||||
|
fileSystem = new Mock<IFileSystem>();
|
||||||
logger = new Mock<ILogger>();
|
logger = new Mock<ILogger>();
|
||||||
runtimeHost = new Mock<IRuntimeHost>();
|
runtimeHost = new Mock<IRuntimeHost>();
|
||||||
session = new SessionConfiguration();
|
session = new SessionConfiguration();
|
||||||
|
@ -43,47 +46,52 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
session.AppConfig = appConfig;
|
session.AppConfig = appConfig;
|
||||||
sessionContext.Next = session;
|
sessionContext.Next = session;
|
||||||
|
|
||||||
sut = new SessionInitializationOperation(configuration.Object, logger.Object, runtimeHost.Object, sessionContext);
|
sut = new SessionInitializationOperation(configuration.Object, fileSystem.Object, logger.Object, runtimeHost.Object, sessionContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustInitializeConfigurationOnPerform()
|
public void Perform_MustInitializeConfiguration()
|
||||||
{
|
{
|
||||||
var token = Guid.NewGuid();
|
var token = Guid.NewGuid();
|
||||||
|
|
||||||
|
appConfig.TemporaryDirectory = @"C:\Some\Random\Path";
|
||||||
session.ClientAuthenticationToken = token;
|
session.ClientAuthenticationToken = token;
|
||||||
|
|
||||||
var result = sut.Perform();
|
var result = sut.Perform();
|
||||||
|
|
||||||
configuration.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
configuration.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
||||||
|
fileSystem.Verify(f => f.CreateDirectory(It.Is<string>(s => s == appConfig.TemporaryDirectory)), Times.Once);
|
||||||
|
|
||||||
Assert.AreEqual(OperationResult.Success, result);
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
Assert.IsNull(sessionContext.Current);
|
Assert.IsNull(sessionContext.Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustInitializeConfigurationOnRepeat()
|
public void Repeat_MustInitializeConfiguration()
|
||||||
{
|
{
|
||||||
var currentSession = new SessionConfiguration();
|
var currentSession = new SessionConfiguration();
|
||||||
var token = Guid.NewGuid();
|
var token = Guid.NewGuid();
|
||||||
|
|
||||||
|
appConfig.TemporaryDirectory = @"C:\Some\Random\Path";
|
||||||
session.ClientAuthenticationToken = token;
|
session.ClientAuthenticationToken = token;
|
||||||
sessionContext.Current = currentSession;
|
sessionContext.Current = currentSession;
|
||||||
|
|
||||||
var result = sut.Repeat();
|
var result = sut.Repeat();
|
||||||
|
|
||||||
configuration.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
configuration.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
||||||
|
fileSystem.Verify(f => f.CreateDirectory(It.Is<string>(s => s == appConfig.TemporaryDirectory)), Times.Once);
|
||||||
|
|
||||||
Assert.AreEqual(OperationResult.Success, result);
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
Assert.AreSame(currentSession,sessionContext.Current);
|
Assert.AreSame(currentSession,sessionContext.Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustDoNothingOnRevert()
|
public void Revert_MustDoNothing()
|
||||||
{
|
{
|
||||||
var result = sut.Revert();
|
var result = sut.Revert();
|
||||||
|
|
||||||
configuration.VerifyNoOtherCalls();
|
configuration.VerifyNoOtherCalls();
|
||||||
|
fileSystem.VerifyNoOtherCalls();
|
||||||
logger.VerifyNoOtherCalls();
|
logger.VerifyNoOtherCalls();
|
||||||
runtimeHost.VerifyNoOtherCalls();
|
runtimeHost.VerifyNoOtherCalls();
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ namespace SafeExamBrowser.Runtime
|
||||||
bootstrapOperations.Enqueue(new I18nOperation(logger, text));
|
bootstrapOperations.Enqueue(new I18nOperation(logger, text));
|
||||||
bootstrapOperations.Enqueue(new CommunicationHostOperation(runtimeHost, logger));
|
bootstrapOperations.Enqueue(new CommunicationHostOperation(runtimeHost, logger));
|
||||||
|
|
||||||
sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost, sessionContext));
|
sessionOperations.Enqueue(new SessionInitializationOperation(configuration, fileSystem, logger, runtimeHost, sessionContext));
|
||||||
sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new FileSystem(), new HashAlgorithm(), logger, sessionContext));
|
sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new FileSystem(), new HashAlgorithm(), logger, sessionContext));
|
||||||
sessionOperations.Enqueue(new ServerOperation(args, configuration, fileSystem, logger, sessionContext, server));
|
sessionOperations.Enqueue(new ServerOperation(args, configuration, fileSystem, logger, sessionContext, server));
|
||||||
sessionOperations.Enqueue(new VirtualMachineOperation(vmDetector, logger, sessionContext));
|
sessionOperations.Enqueue(new VirtualMachineOperation(vmDetector, logger, sessionContext));
|
||||||
|
|
|
@ -12,12 +12,14 @@ using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||||
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
||||||
using SafeExamBrowser.I18n.Contracts;
|
using SafeExamBrowser.I18n.Contracts;
|
||||||
using SafeExamBrowser.Logging.Contracts;
|
using SafeExamBrowser.Logging.Contracts;
|
||||||
|
using SafeExamBrowser.SystemComponents.Contracts;
|
||||||
|
|
||||||
namespace SafeExamBrowser.Runtime.Operations
|
namespace SafeExamBrowser.Runtime.Operations
|
||||||
{
|
{
|
||||||
internal class SessionInitializationOperation : SessionOperation
|
internal class SessionInitializationOperation : SessionOperation
|
||||||
{
|
{
|
||||||
private IConfigurationRepository configuration;
|
private IConfigurationRepository configuration;
|
||||||
|
private IFileSystem fileSystem;
|
||||||
private ILogger logger;
|
private ILogger logger;
|
||||||
private IRuntimeHost runtimeHost;
|
private IRuntimeHost runtimeHost;
|
||||||
|
|
||||||
|
@ -26,11 +28,13 @@ namespace SafeExamBrowser.Runtime.Operations
|
||||||
|
|
||||||
public SessionInitializationOperation(
|
public SessionInitializationOperation(
|
||||||
IConfigurationRepository configuration,
|
IConfigurationRepository configuration,
|
||||||
|
IFileSystem fileSystem,
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
IRuntimeHost runtimeHost,
|
IRuntimeHost runtimeHost,
|
||||||
SessionContext sessionContext) : base(sessionContext)
|
SessionContext sessionContext) : base(sessionContext)
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
this.fileSystem = fileSystem;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.runtimeHost = runtimeHost;
|
this.runtimeHost = runtimeHost;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +70,8 @@ namespace SafeExamBrowser.Runtime.Operations
|
||||||
logger.Info($" -> Client-ID: {Context.Next.AppConfig.ClientId}");
|
logger.Info($" -> Client-ID: {Context.Next.AppConfig.ClientId}");
|
||||||
logger.Info($" -> Runtime-ID: {Context.Next.AppConfig.RuntimeId}");
|
logger.Info($" -> Runtime-ID: {Context.Next.AppConfig.RuntimeId}");
|
||||||
logger.Info($" -> Session-ID: {Context.Next.SessionId}");
|
logger.Info($" -> Session-ID: {Context.Next.SessionId}");
|
||||||
|
|
||||||
|
fileSystem.CreateDirectory(Context.Next.AppConfig.TemporaryDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FinalizeSessionConfiguration()
|
private void FinalizeSessionConfiguration()
|
||||||
|
|
|
@ -13,6 +13,11 @@ namespace SafeExamBrowser.SystemComponents.Contracts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IFileSystem
|
public interface IFileSystem
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates all directories and subdirectories defined by the given path.
|
||||||
|
/// </summary>
|
||||||
|
void CreateDirectory(string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the item at the given path, if it exists. Directories will be completely deleted, including all subdirectories and files.
|
/// Deletes the item at the given path, if it exists. Directories will be completely deleted, including all subdirectories and files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -13,6 +13,11 @@ namespace SafeExamBrowser.SystemComponents
|
||||||
{
|
{
|
||||||
public class FileSystem : IFileSystem
|
public class FileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
|
public void CreateDirectory(string path)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
public void Delete(string path)
|
public void Delete(string path)
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
|
Loading…
Reference in a new issue