Update Safe Exam Browser Patch to 3.10.0.826
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2025 ETH Zürich, IT Services
|
||||
*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Responsibilities;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Responsibilities
|
||||
{
|
||||
[TestClass]
|
||||
public class ClientResponsibilityTests
|
||||
{
|
||||
private Mock<IRuntimeWindow> runtimeWindow;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private RuntimeContext context;
|
||||
private Mock<Action> shutdown;
|
||||
private Mock<IProcess> clientProcess;
|
||||
private Mock<IClientProxy> clientProxy;
|
||||
|
||||
private ClientResponsibility sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
clientProcess = new Mock<IProcess>();
|
||||
clientProxy = new Mock<IClientProxy>();
|
||||
context = new RuntimeContext();
|
||||
logger = new Mock<ILogger>();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
runtimeWindow = new Mock<IRuntimeWindow>();
|
||||
shutdown = new Mock<Action>();
|
||||
|
||||
context.ClientProcess = clientProcess.Object;
|
||||
context.ClientProxy = clientProxy.Object;
|
||||
|
||||
sut = new ClientResponsibility(logger.Object, messageBox.Object, context, runtimeWindow.Object, shutdown.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClientProcess_MustShutdownWhenClientTerminated()
|
||||
{
|
||||
sut.Assume(RuntimeTask.RegisterSessionEvents);
|
||||
clientProcess.Raise(c => c.Terminated += null, -1);
|
||||
|
||||
messageBox.Verify(m => m.Show(
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<MessageBoxAction>(),
|
||||
It.Is<MessageBoxIcon>(i => i == MessageBoxIcon.Error),
|
||||
It.IsAny<IWindow>()), Times.Once);
|
||||
shutdown.Verify(s => s(), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClientProxy_MustShutdownWhenConnectionLost()
|
||||
{
|
||||
sut.Assume(RuntimeTask.RegisterSessionEvents);
|
||||
clientProxy.Raise(c => c.ConnectionLost += null);
|
||||
|
||||
messageBox.Verify(m => m.Show(
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<MessageBoxAction>(),
|
||||
It.Is<MessageBoxIcon>(i => i == MessageBoxIcon.Error),
|
||||
It.IsAny<IWindow>()), Times.Once);
|
||||
shutdown.Verify(s => s(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2025 ETH Zürich, IT Services
|
||||
*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Events;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.ResponsibilityModel;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Responsibilities;
|
||||
using SafeExamBrowser.Settings;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Responsibilities
|
||||
{
|
||||
[TestClass]
|
||||
public class CommunicationResponsibilityTests
|
||||
{
|
||||
private Mock<IClientProxy> clientProxy;
|
||||
private RuntimeContext context;
|
||||
private SessionConfiguration currentSession;
|
||||
private AppSettings currentSettings;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IResponsibilityCollection<RuntimeTask>> responsibilities;
|
||||
private SessionConfiguration nextSession;
|
||||
private AppSettings nextSettings;
|
||||
private Mock<IRuntimeHost> runtimeHost;
|
||||
private Mock<Action> shutdown;
|
||||
|
||||
private CommunicationResponsibility sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
clientProxy = new Mock<IClientProxy>();
|
||||
context = new RuntimeContext();
|
||||
logger = new Mock<ILogger>();
|
||||
responsibilities = new Mock<IResponsibilityCollection<RuntimeTask>>();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
shutdown = new Mock<Action>();
|
||||
|
||||
currentSession = new SessionConfiguration();
|
||||
currentSettings = new AppSettings();
|
||||
nextSession = new SessionConfiguration();
|
||||
nextSettings = new AppSettings();
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
nextSession.Settings = nextSettings;
|
||||
|
||||
context.ClientProxy = clientProxy.Object;
|
||||
context.Current = currentSession;
|
||||
context.Next = nextSession;
|
||||
context.Responsibilities = responsibilities.Object;
|
||||
|
||||
sut = new CommunicationResponsibility(logger.Object, context, runtimeHost.Object, shutdown.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Communication_MustProvideClientConfigurationUponRequest()
|
||||
{
|
||||
var args = new ClientConfigurationEventArgs();
|
||||
var nextAppConfig = new AppConfig();
|
||||
var nextSessionId = Guid.NewGuid();
|
||||
var nextSettings = new AppSettings();
|
||||
|
||||
nextSession.AppConfig = nextAppConfig;
|
||||
nextSession.SessionId = nextSessionId;
|
||||
nextSession.Settings = nextSettings;
|
||||
|
||||
sut.Assume(RuntimeTask.RegisterEvents);
|
||||
runtimeHost.Raise(r => r.ClientConfigurationNeeded += null, args);
|
||||
|
||||
Assert.AreSame(nextAppConfig, args.ClientConfiguration.AppConfig);
|
||||
Assert.AreEqual(nextSessionId, args.ClientConfiguration.SessionId);
|
||||
Assert.AreSame(nextSettings, args.ClientConfiguration.Settings);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Communication_MustStartNewSessionUponRequest()
|
||||
{
|
||||
var args = new ReconfigurationEventArgs { ConfigurationPath = "C:\\Some\\File\\Path.seb" };
|
||||
|
||||
sut.Assume(RuntimeTask.RegisterEvents);
|
||||
runtimeHost.Raise(r => r.ReconfigurationRequested += null, args);
|
||||
|
||||
responsibilities.Verify(r => r.Delegate(RuntimeTask.StartSession));
|
||||
Assert.AreEqual(context.ReconfigurationFilePath, args.ConfigurationPath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Communication_MustShutdownUponRequest()
|
||||
{
|
||||
sut.Assume(RuntimeTask.RegisterEvents);
|
||||
runtimeHost.Raise(r => r.ShutdownRequested += null);
|
||||
shutdown.Verify(s => s(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2025 ETH Zürich, IT Services
|
||||
*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.ResponsibilityModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Responsibilities;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Service;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Responsibilities
|
||||
{
|
||||
[TestClass]
|
||||
public class ServiceResponsibilityTests
|
||||
{
|
||||
private RuntimeContext context;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private Mock<IResponsibilityCollection<RuntimeTask>> responsibilities;
|
||||
private Mock<IRuntimeWindow> runtimeWindow;
|
||||
private Mock<IServiceProxy> serviceProxy;
|
||||
private Mock<Action> shutdown;
|
||||
private SessionConfiguration currentSession;
|
||||
private AppSettings currentSettings;
|
||||
private ServiceResponsibility sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
context = new RuntimeContext();
|
||||
logger = new Mock<ILogger>();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
responsibilities = new Mock<IResponsibilityCollection<RuntimeTask>>();
|
||||
runtimeWindow = new Mock<IRuntimeWindow>();
|
||||
serviceProxy = new Mock<IServiceProxy>();
|
||||
shutdown = new Mock<Action>();
|
||||
|
||||
currentSession = new SessionConfiguration();
|
||||
currentSettings = new AppSettings();
|
||||
currentSession.Settings = currentSettings;
|
||||
|
||||
context.Current = currentSession;
|
||||
context.Responsibilities = responsibilities.Object;
|
||||
|
||||
sut = new ServiceResponsibility(logger.Object, messageBox.Object, context, runtimeWindow.Object, serviceProxy.Object, shutdown.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ServiceProxy_MustShutdownWhenConnectionLostAndMandatory()
|
||||
{
|
||||
currentSettings.Service.Policy = ServicePolicy.Mandatory;
|
||||
|
||||
sut.Assume(RuntimeTask.RegisterSessionEvents);
|
||||
serviceProxy.Raise(c => c.ConnectionLost += null);
|
||||
|
||||
messageBox.Verify(m => m.Show(
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<MessageBoxAction>(),
|
||||
It.Is<MessageBoxIcon>(i => i == MessageBoxIcon.Error),
|
||||
It.IsAny<IWindow>()), Times.Once);
|
||||
responsibilities.Verify(r => r.Delegate(RuntimeTask.StopSession), Times.Once);
|
||||
shutdown.Verify(s => s(), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ServiceProxy_MustNotShutdownWhenConnectionLostAndNotMandatory()
|
||||
{
|
||||
currentSettings.Service.Policy = ServicePolicy.Optional;
|
||||
|
||||
sut.Assume(RuntimeTask.RegisterSessionEvents);
|
||||
serviceProxy.Raise(c => c.ConnectionLost += null);
|
||||
|
||||
messageBox.Verify(m => m.Show(
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<TextKey>(),
|
||||
It.IsAny<MessageBoxAction>(),
|
||||
It.Is<MessageBoxIcon>(i => i == MessageBoxIcon.Error),
|
||||
It.IsAny<IWindow>()), Times.Never);
|
||||
responsibilities.Verify(r => r.Delegate(RuntimeTask.StopSession), Times.Never);
|
||||
shutdown.Verify(s => s(), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.Core.Contracts.ResponsibilityModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Responsibilities;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Security;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Responsibilities
|
||||
{
|
||||
[TestClass]
|
||||
public class SessionResponsibilityTests
|
||||
{
|
||||
private AppConfig appConfig;
|
||||
private Mock<IClientProxy> clientProxy;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private Mock<IResponsibilityCollection<RuntimeTask>> responsibilities;
|
||||
private RuntimeContext context;
|
||||
private Mock<IRuntimeWindow> runtimeWindow;
|
||||
private Mock<IRepeatableOperationSequence> sessionSequence;
|
||||
private Mock<Action> shutdown;
|
||||
private Mock<IText> text;
|
||||
private SessionConfiguration currentSession;
|
||||
private AppSettings currentSettings;
|
||||
private SessionConfiguration nextSession;
|
||||
private AppSettings nextSettings;
|
||||
private SessionResponsibility sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
appConfig = new AppConfig();
|
||||
clientProxy = new Mock<IClientProxy>();
|
||||
context = new RuntimeContext();
|
||||
logger = new Mock<ILogger>();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
responsibilities = new Mock<IResponsibilityCollection<RuntimeTask>>();
|
||||
runtimeWindow = new Mock<IRuntimeWindow>();
|
||||
sessionSequence = new Mock<IRepeatableOperationSequence>();
|
||||
shutdown = new Mock<Action>();
|
||||
text = new Mock<IText>();
|
||||
|
||||
currentSession = new SessionConfiguration();
|
||||
currentSettings = new AppSettings();
|
||||
nextSession = new SessionConfiguration();
|
||||
nextSettings = new AppSettings();
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
nextSession.Settings = nextSettings;
|
||||
|
||||
context.ClientProxy = clientProxy.Object;
|
||||
context.Current = currentSession;
|
||||
context.Next = nextSession;
|
||||
context.Responsibilities = responsibilities.Object;
|
||||
|
||||
sut = new SessionResponsibility(appConfig, logger.Object, messageBox.Object, context, runtimeWindow.Object, sessionSequence.Object, shutdown.Object, text.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustHideRuntimeWindowWhenUsingDisableExplorerShell()
|
||||
{
|
||||
context.Current = default;
|
||||
currentSettings.Security.KioskMode = KioskMode.DisableExplorerShell;
|
||||
nextSettings.Security.KioskMode = KioskMode.DisableExplorerShell;
|
||||
sessionSequence.Setup(s => s.TryPerform()).Callback(() => context.Current = currentSession).Returns(OperationResult.Success);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
runtimeWindow.Verify(w => w.Hide(), Times.Once);
|
||||
runtimeWindow.Reset();
|
||||
sessionSequence.Reset();
|
||||
sessionSequence.Setup(s => s.TryRepeat()).Returns(OperationResult.Aborted);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
runtimeWindow.Verify(w => w.Hide(), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustShowMessageBoxOnFailure()
|
||||
{
|
||||
context.Current = default;
|
||||
sessionSequence.Setup(b => b.TryPerform()).Callback(() => context.Current = currentSession).Returns(OperationResult.Failed);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
messageBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()), Times.AtLeastOnce);
|
||||
messageBox.Reset();
|
||||
sessionSequence.Reset();
|
||||
sessionSequence.Setup(b => b.TryRepeat()).Returns(OperationResult.Failed);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
messageBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()), Times.AtLeastOnce);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustTerminateOnSessionStartFailure()
|
||||
{
|
||||
context.Current = default;
|
||||
sessionSequence.Setup(b => b.TryPerform()).Callback(() => context.Current = currentSession).Returns(OperationResult.Failed);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
sessionSequence.Verify(b => b.TryPerform(), Times.Once);
|
||||
sessionSequence.Verify(b => b.TryRepeat(), Times.Never);
|
||||
sessionSequence.Verify(b => b.TryRevert(), Times.Once);
|
||||
shutdown.Verify(s => s(), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustNotTerminateOnSessionStartAbortion()
|
||||
{
|
||||
context.Current = default;
|
||||
sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Aborted);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
sessionSequence.Verify(b => b.TryPerform(), Times.Once);
|
||||
sessionSequence.Verify(b => b.TryRepeat(), Times.Never);
|
||||
sessionSequence.Verify(b => b.TryRevert(), Times.Never);
|
||||
shutdown.Verify(s => s(), Times.Never);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustInformClientAboutAbortedReconfiguration()
|
||||
{
|
||||
context.Current = default;
|
||||
sessionSequence.Setup(b => b.TryPerform()).Callback(() => context.Current = currentSession).Returns(OperationResult.Aborted);
|
||||
|
||||
sut.Assume(RuntimeTask.StartSession);
|
||||
|
||||
clientProxy.Verify(c => c.InformReconfigurationAborted(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user