SEBWIN-363, SEBWIN-357: Ensured session is retained when loading a configuration from a server which requires authentication and introduced new flag to determine whether a reconfiguration is allowed or not. Also fixed session persistence when using delete cookies settings.

This commit is contained in:
dbuechel 2020-02-25 10:41:55 +01:00
parent 1d9f5ffad7
commit 07bb78e637
11 changed files with 52 additions and 19 deletions

View file

@ -213,7 +213,7 @@ namespace SafeExamBrowser.Browser
cefSettings.CefCommandLineArgs.Add("touch-events", "enabled");
cefSettings.LogFile = appConfig.BrowserLogFilePath;
cefSettings.LogSeverity = error ? LogSeverity.Error : (warning ? LogSeverity.Warning : LogSeverity.Info);
cefSettings.PersistSessionCookies = !settings.DeleteCookiesOnShutdown;
cefSettings.PersistSessionCookies = !settings.DeleteCookiesOnStartup || !settings.DeleteCookiesOnShutdown;
cefSettings.UserAgent = InitializeUserAgent();
if (!settings.AllowPdfReader)

View file

@ -626,7 +626,7 @@ namespace SafeExamBrowser.Client.UnitTests
var args = new DownloadEventArgs();
appConfig.TemporaryDirectory = @"C:\Folder\Does\Not\Exist";
settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
settings.Security.AllowReconfiguration = true;
messageBox.Setup(m => m.Show(
It.IsAny<TextKey>(),
It.IsAny<TextKey>(),
@ -653,7 +653,7 @@ namespace SafeExamBrowser.Client.UnitTests
var args = new DownloadEventArgs();
appConfig.TemporaryDirectory = @"C:\Folder\Does\Not\Exist";
settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
settings.Security.AllowReconfiguration = true;
messageBox.Setup(m => m.Show(
It.IsAny<TextKey>(),
It.IsAny<TextKey>(),
@ -677,7 +677,7 @@ namespace SafeExamBrowser.Client.UnitTests
var args = new DownloadEventArgs();
appConfig.TemporaryDirectory = @"C:\Folder\Does\Not\Exist";
settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
settings.Security.AllowReconfiguration = true;
messageBox.Setup(m => m.Show(
It.IsAny<TextKey>(),
It.IsAny<TextKey>(),

View file

@ -337,7 +337,7 @@ namespace SafeExamBrowser.Client
private void Browser_ConfigurationDownloadRequested(string fileName, DownloadEventArgs args)
{
if (Settings.ConfigurationMode == ConfigurationMode.ConfigureClient)
if (Settings.Security.AllowReconfiguration)
{
args.AllowDownload = true;
args.Callback = Browser_ConfigurationDownloadFinished;
@ -353,7 +353,7 @@ namespace SafeExamBrowser.Client
else
{
args.AllowDownload = false;
logger.Info($"Denied download request for configuration file '{fileName}' due to '{Settings.ConfigurationMode}' mode.");
logger.Info($"Denied download request for configuration file '{fileName}'.");
}
}

View file

@ -26,6 +26,22 @@ namespace SafeExamBrowser.Configuration.UnitTests.ConfigurationData
sut = new DataProcessor();
}
[TestMethod]
public void MustAllowReconfigurationAccordingToMode()
{
var settings1 = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
var settings2 = new AppSettings { ConfigurationMode = ConfigurationMode.Exam };
settings1.Security.AllowReconfiguration = false;
settings2.Security.AllowReconfiguration = true;
sut.Process(new Dictionary<string, object>(), settings1);
sut.Process(new Dictionary<string, object>(), settings2);
Assert.IsTrue(settings1.Security.AllowReconfiguration);
Assert.IsFalse(settings2.Security.AllowReconfiguration);
}
[TestMethod]
public void MustCalculateCorrectConfigurationKey()
{

View file

@ -20,9 +20,15 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
{
internal void Process(IDictionary<string, object> rawData, AppSettings settings)
{
AllowReconfiguration(settings);
CalculateConfigurationKey(rawData, settings);
}
private void AllowReconfiguration(AppSettings settings)
{
settings.Security.AllowReconfiguration = settings.ConfigurationMode == ConfigurationMode.ConfigureClient;
}
private void CalculateConfigurationKey(IDictionary<string, object> rawData, AppSettings settings)
{
using (var algorithm = new SHA256Managed())

View file

@ -165,6 +165,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Mouse.AllowRightButton = true;
settings.Security.AllowApplicationLogAccess = false;
settings.Security.AllowReconfiguration = false;
settings.Security.KioskMode = KioskMode.CreateNewDesktop;
settings.Security.VirtualMachinePolicy = VirtualMachinePolicy.Deny;

View file

@ -110,7 +110,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
}
[TestMethod]
public void Perform_MustTestdatalyHandleBrowserResource()
public void Perform_MustCorrectlyHandleBrowserResource()
{
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.Exam };
var url = @"http://www.safeexambrowser.org/whatever.seb";
@ -121,6 +121,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
var result = sut.Perform();
Assert.IsFalse(settings.Browser.DeleteCacheOnShutdown);
Assert.IsFalse(settings.Browser.DeleteCookiesOnShutdown);
Assert.IsTrue(settings.Security.AllowReconfiguration);
Assert.AreEqual(url, settings.Browser.StartUrl);
Assert.AreEqual(OperationResult.Success, result);
}
@ -331,7 +334,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
}
[TestMethod]
public void Perform_MustSucceedIfAdminPasswordTestdata()
public void Perform_MustSucceedIfAdminPasswordCorrect()
{
var password = "test";
var currentSettings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
@ -394,7 +397,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
}
[TestMethod]
public void Perform_MustSucceedIfSettingsPasswordTestdata()
public void Perform_MustSucceedIfSettingsPasswordCorrect()
{
var password = "test";
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.Exam };
@ -504,7 +507,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
}
[TestMethod]
public void Repeat_MustPerformForExamWithTestdataUri()
public void Repeat_MustPerformForExamWithCorrectUri()
{
var currentSettings = new AppSettings();
var location = Path.GetDirectoryName(GetType().Assembly.Location);
@ -526,7 +529,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
}
[TestMethod]
public void Repeat_MustPerformForClientConfigurationWithTestdataUri()
public void Repeat_MustPerformForClientConfigurationWithCorrectUri()
{
var currentSettings = new AppSettings();
var location = Path.GetDirectoryName(GetType().Assembly.Location);

View file

@ -163,7 +163,7 @@ namespace SafeExamBrowser.Runtime.UnitTests
var args = new ReconfigurationEventArgs { ConfigurationPath = "C:\\Some\\File\\Path.seb" };
StartSession();
currentSettings.ConfigurationMode = ConfigurationMode.ConfigureClient;
currentSettings.Security.AllowReconfiguration = true;
bootstrapSequence.Reset();
sessionSequence.Reset();
sessionSequence.Setup(s => s.TryRepeat()).Returns(OperationResult.Success);
@ -182,6 +182,7 @@ namespace SafeExamBrowser.Runtime.UnitTests
public void Communication_MustInformClientAboutAbortedReconfiguration()
{
StartSession();
currentSettings.Security.AllowReconfiguration = true;
sessionSequence.Reset();
sessionSequence.Setup(s => s.TryRepeat()).Returns(OperationResult.Aborted);
@ -196,7 +197,7 @@ namespace SafeExamBrowser.Runtime.UnitTests
var args = new ReconfigurationEventArgs { ConfigurationPath = "C:\\Some\\File\\Path.seb" };
StartSession();
currentSettings.ConfigurationMode = ConfigurationMode.Exam;
currentSettings.Security.AllowReconfiguration = false;
bootstrapSequence.Reset();
sessionSequence.Reset();

View file

@ -204,8 +204,12 @@ namespace SafeExamBrowser.Runtime.Operations
private OperationResult HandleBrowserResource(Uri uri)
{
Context.Next.Settings.Browser.DeleteCacheOnShutdown = false;
Context.Next.Settings.Browser.DeleteCookiesOnShutdown = false;
Context.Next.Settings.Browser.StartUrl = uri.AbsoluteUri;
logger.Info($"The configuration resource needs authentication or is a webpage, using '{uri}' as startup URL for the browser.");
Context.Next.Settings.Security.AllowReconfiguration = true;
logger.Info($"The configuration resource needs authentication or is a webpage, using '{uri}' as start URL for the browser.");
return OperationResult.Success;
}

View file

@ -19,7 +19,6 @@ using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Runtime.Contracts;
using SafeExamBrowser.Runtime.Operations.Events;
using SafeExamBrowser.Settings;
using SafeExamBrowser.Settings.Security;
using SafeExamBrowser.Settings.Service;
using SafeExamBrowser.UserInterface.Contracts;
@ -344,9 +343,7 @@ namespace SafeExamBrowser.Runtime
private void RuntimeHost_ReconfigurationRequested(ReconfigurationEventArgs args)
{
var mode = Session.Settings.ConfigurationMode;
if (mode == ConfigurationMode.ConfigureClient)
if (Session.Settings.Security.AllowReconfiguration)
{
logger.Info($"Accepted request for reconfiguration with '{args.ConfigurationPath}'.");
sessionContext.ReconfigurationFilePath = args.ConfigurationPath;
@ -355,7 +352,7 @@ namespace SafeExamBrowser.Runtime
}
else
{
logger.Info($"Denied request for reconfiguration with '{args.ConfigurationPath}' due to '{mode}' mode!");
logger.Info($"Denied request for reconfiguration with '{args.ConfigurationPath}'!");
sessionContext.ClientProxy.InformReconfigurationDenied(args.ConfigurationPath);
}
}

View file

@ -26,6 +26,11 @@ namespace SafeExamBrowser.Settings.Security
/// </summary>
public bool AllowApplicationLogAccess { get; set; }
/// <summary>
/// Determines whether the user may reconfigure the application.
/// </summary>
public bool AllowReconfiguration { get; set; }
/// <summary>
/// The kiosk mode which determines how the computer is locked down.
/// </summary>