SEBWIN-296: Fixed unit tests for password negotiation via client.
This commit is contained in:
parent
4ba7f28a24
commit
875bb57c95
1 changed files with 133 additions and 81 deletions
|
@ -6,111 +6,163 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Moq;
|
||||||
|
using SafeExamBrowser.Contracts.Communication.Data;
|
||||||
|
using SafeExamBrowser.Contracts.Communication.Events;
|
||||||
|
using SafeExamBrowser.Contracts.Communication.Hosts;
|
||||||
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
||||||
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||||
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||||
|
using SafeExamBrowser.Contracts.I18n;
|
||||||
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
|
using SafeExamBrowser.Contracts.UserInterface;
|
||||||
|
using SafeExamBrowser.Contracts.UserInterface.MessageBox;
|
||||||
|
using SafeExamBrowser.Contracts.UserInterface.Windows;
|
||||||
|
using SafeExamBrowser.Runtime.Operations.Events;
|
||||||
|
|
||||||
namespace SafeExamBrowser.Runtime.UnitTests
|
namespace SafeExamBrowser.Runtime.UnitTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class RuntimeControllerTests
|
public class RuntimeControllerTests
|
||||||
{
|
{
|
||||||
[TestMethod]
|
private AppConfig appConfig;
|
||||||
public void TODO()
|
private Mock<IOperationSequence> bootstrapSequence;
|
||||||
|
private Mock<IClientProxy> clientProxy;
|
||||||
|
private Mock<ISessionConfiguration> currentSession;
|
||||||
|
private Settings currentSettings;
|
||||||
|
private Mock<ILogger> logger;
|
||||||
|
private Mock<IMessageBox> messageBox;
|
||||||
|
private Mock<ISessionConfiguration> nextSession;
|
||||||
|
private Settings nextSettings;
|
||||||
|
private Mock<Action> shutdown;
|
||||||
|
private Mock<IText> text;
|
||||||
|
private Mock<IUserInterfaceFactory> uiFactory;
|
||||||
|
private RuntimeController sut;
|
||||||
|
private Mock<IRuntimeHost> runtimeHost;
|
||||||
|
private Mock<IServiceProxy> service;
|
||||||
|
private SessionContext sessionContext;
|
||||||
|
private Mock<IRepeatableOperationSequence> sessionSequence;
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Initialize()
|
||||||
{
|
{
|
||||||
Assert.Fail();
|
appConfig = new AppConfig();
|
||||||
|
bootstrapSequence = new Mock<IOperationSequence>();
|
||||||
|
clientProxy = new Mock<IClientProxy>();
|
||||||
|
currentSession = new Mock<ISessionConfiguration>();
|
||||||
|
currentSettings = new Settings();
|
||||||
|
logger = new Mock<ILogger>();
|
||||||
|
messageBox = new Mock<IMessageBox>();
|
||||||
|
nextSession = new Mock<ISessionConfiguration>();
|
||||||
|
nextSettings = new Settings();
|
||||||
|
runtimeHost = new Mock<IRuntimeHost>();
|
||||||
|
service = new Mock<IServiceProxy>();
|
||||||
|
sessionContext = new SessionContext();
|
||||||
|
sessionSequence = new Mock<IRepeatableOperationSequence>();
|
||||||
|
shutdown = new Mock<Action>();
|
||||||
|
text = new Mock<IText>();
|
||||||
|
uiFactory = new Mock<IUserInterfaceFactory>();
|
||||||
|
|
||||||
|
currentSession.SetupGet(s => s.Settings).Returns(currentSettings);
|
||||||
|
nextSession.SetupGet(s => s.Settings).Returns(nextSettings);
|
||||||
|
|
||||||
|
sessionContext.ClientProxy = clientProxy.Object;
|
||||||
|
sessionContext.Current = currentSession.Object;
|
||||||
|
sessionContext.Next = nextSession.Object;
|
||||||
|
|
||||||
|
uiFactory.Setup(u => u.CreateRuntimeWindow(It.IsAny<AppConfig>())).Returns(new Mock<IRuntimeWindow>().Object);
|
||||||
|
uiFactory.Setup(u => u.CreateSplashScreen(It.IsAny<AppConfig>())).Returns(new Mock<ISplashScreen>().Object);
|
||||||
|
|
||||||
|
sut = new RuntimeController(
|
||||||
|
appConfig,
|
||||||
|
logger.Object,
|
||||||
|
messageBox.Object,
|
||||||
|
bootstrapSequence.Object,
|
||||||
|
sessionSequence.Object,
|
||||||
|
runtimeHost.Object,
|
||||||
|
service.Object,
|
||||||
|
sessionContext,
|
||||||
|
shutdown.Object,
|
||||||
|
text.Object,
|
||||||
|
uiFactory.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
//[TestMethod]
|
[TestMethod]
|
||||||
//public void MustRequestPasswordViaDialogOnDefaultDesktop()
|
public void MustRequestPasswordViaDialogOnDefaultDesktop()
|
||||||
//{
|
{
|
||||||
// var clientProxy = new Mock<IClientProxy>();
|
var args = new PasswordRequiredEventArgs();
|
||||||
// var session = new Mock<ISessionData>();
|
var password = "test1234";
|
||||||
// var url = @"http://www.safeexambrowser.org/whatever.seb";
|
var passwordDialog = new Mock<IPasswordDialog>();
|
||||||
|
var result = new Mock<IPasswordDialogResult>();
|
||||||
|
|
||||||
// passwordDialog.Setup(d => d.Show(null)).Returns(new PasswordDialogResultStub { Success = true });
|
currentSettings.KioskMode = KioskMode.DisableExplorerShell;
|
||||||
// repository.SetupGet(r => r.CurrentSession).Returns(session.Object);
|
passwordDialog.Setup(p => p.Show(It.IsAny<IWindow>())).Returns(result.Object);
|
||||||
// repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
result.SetupGet(r => r.Password).Returns(password);
|
||||||
// session.SetupGet(r => r.ClientProxy).Returns(clientProxy.Object);
|
result.SetupGet(r => r.Success).Returns(true);
|
||||||
// settings.KioskMode = KioskMode.DisableExplorerShell;
|
uiFactory.Setup(u => u.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(passwordDialog.Object);
|
||||||
|
|
||||||
// sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
sut.TryStart();
|
||||||
// sut.Perform();
|
sessionSequence.Raise(s => s.ActionRequired += null, args);
|
||||||
|
|
||||||
// clientProxy.Verify(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>()), Times.Never);
|
clientProxy.VerifyNoOtherCalls();
|
||||||
// passwordDialog.Verify(p => p.Show(null), Times.AtLeastOnce);
|
passwordDialog.Verify(p => p.Show(It.IsAny<IWindow>()), Times.Once);
|
||||||
// session.VerifyGet(s => s.ClientProxy, Times.Never);
|
uiFactory.Verify(u => u.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||||
//}
|
|
||||||
|
|
||||||
//[TestMethod]
|
Assert.AreEqual(true, args.Success);
|
||||||
//public void MustRequestPasswordViaClientDuringReconfigurationOnNewDesktop()
|
Assert.AreEqual(password, args.Password);
|
||||||
//{
|
}
|
||||||
// var clientProxy = new Mock<IClientProxy>();
|
|
||||||
// var communication = new CommunicationResult(true);
|
|
||||||
// var passwordReceived = new Action<PasswordRequestPurpose, Guid>((p, id) =>
|
|
||||||
// {
|
|
||||||
// runtimeHost.Raise(r => r.PasswordReceived += null, new PasswordReplyEventArgs { RequestId = id, Success = true });
|
|
||||||
// });
|
|
||||||
// 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).Callback(passwordReceived);
|
[TestMethod]
|
||||||
// passwordDialog.Setup(d => d.Show(null)).Returns(new PasswordDialogResultStub { Success = true });
|
public void MustRequestPasswordViaClientOnNewDesktop()
|
||||||
// repository.SetupGet(r => r.CurrentSession).Returns(session.Object);
|
{
|
||||||
// repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
var args = new PasswordRequiredEventArgs();
|
||||||
// session.SetupGet(r => r.ClientProxy).Returns(clientProxy.Object);
|
var passwordReceived = new Action<PasswordRequestPurpose, Guid>((p, id) =>
|
||||||
// settings.KioskMode = KioskMode.CreateNewDesktop;
|
{
|
||||||
|
runtimeHost.Raise(r => r.PasswordReceived += null, new PasswordReplyEventArgs { RequestId = id, Success = true });
|
||||||
|
});
|
||||||
|
|
||||||
// sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
currentSettings.KioskMode = KioskMode.CreateNewDesktop;
|
||||||
// sut.Perform();
|
clientProxy.Setup(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>())).Returns(new CommunicationResult(true)).Callback(passwordReceived);
|
||||||
|
|
||||||
// clientProxy.Verify(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>()), Times.AtLeastOnce);
|
sut.TryStart();
|
||||||
// passwordDialog.Verify(p => p.Show(null), Times.Never);
|
sessionSequence.Raise(s => s.ActionRequired += null, args);
|
||||||
// session.VerifyGet(s => s.ClientProxy, Times.AtLeastOnce);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//[TestMethod]
|
clientProxy.Verify(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>()), Times.Once);
|
||||||
//public void MustAbortAskingForPasswordViaClientIfDecidedByUser()
|
uiFactory.Verify(u => u.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||||
//{
|
}
|
||||||
// var clientProxy = new Mock<IClientProxy>();
|
|
||||||
// var communication = new CommunicationResult(true);
|
|
||||||
// var passwordReceived = new Action<PasswordRequestPurpose, Guid>((p, id) =>
|
|
||||||
// {
|
|
||||||
// runtimeHost.Raise(r => r.PasswordReceived += null, new PasswordReplyEventArgs { RequestId = id, Success = 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).Callback(passwordReceived);
|
[TestMethod]
|
||||||
// repository.SetupGet(r => r.CurrentSession).Returns(session.Object);
|
public void MustAbortAskingForPasswordViaClientIfDecidedByUser()
|
||||||
// repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
{
|
||||||
// session.SetupGet(r => r.ClientProxy).Returns(clientProxy.Object);
|
var args = new PasswordRequiredEventArgs();
|
||||||
// settings.KioskMode = KioskMode.CreateNewDesktop;
|
var passwordReceived = new Action<PasswordRequestPurpose, Guid>((p, id) =>
|
||||||
|
{
|
||||||
|
runtimeHost.Raise(r => r.PasswordReceived += null, new PasswordReplyEventArgs { RequestId = id, Success = false });
|
||||||
|
});
|
||||||
|
|
||||||
// sut = new ConfigurationOperation(appConfig, repository.Object, logger.Object, resourceLoader.Object, new[] { "blubb.exe", url });
|
currentSettings.KioskMode = KioskMode.CreateNewDesktop;
|
||||||
|
clientProxy.Setup(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>())).Returns(new CommunicationResult(true)).Callback(passwordReceived);
|
||||||
|
|
||||||
// var result = sut.Perform();
|
sut.TryStart();
|
||||||
|
sessionSequence.Raise(s => s.ActionRequired += null, args);
|
||||||
|
|
||||||
// Assert.AreEqual(OperationResult.Aborted, result);
|
clientProxy.Verify(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>()), Times.Once);
|
||||||
//}
|
uiFactory.Verify(u => u.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
//[TestMethod]
|
[TestMethod]
|
||||||
//public void MustNotWaitForPasswordViaClientIfCommunicationHasFailed()
|
public void MustNotWaitForPasswordViaClientIfCommunicationHasFailed()
|
||||||
//{
|
{
|
||||||
// var clientProxy = new Mock<IClientProxy>();
|
var args = new PasswordRequiredEventArgs();
|
||||||
// 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);
|
currentSettings.KioskMode = KioskMode.CreateNewDesktop;
|
||||||
// repository.SetupGet(r => r.CurrentSession).Returns(session.Object);
|
clientProxy.Setup(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>())).Returns(new CommunicationResult(false));
|
||||||
// repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.SettingsPasswordNeeded);
|
|
||||||
// session.SetupGet(r => r.ClientProxy).Returns(clientProxy.Object);
|
|
||||||
// settings.KioskMode = KioskMode.CreateNewDesktop;
|
|
||||||
|
|
||||||
// sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, logger.Object, resourceLoader.Object, sessionContext);
|
sut.TryStart();
|
||||||
|
sessionSequence.Raise(s => s.ActionRequired += null, args);
|
||||||
// var result = sut.Perform();
|
}
|
||||||
|
|
||||||
// Assert.AreEqual(OperationResult.Aborted, result);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue