public void Shutdown_MustNotInitiateIfQuitPasswordIncorrect() { var args = new System.ComponentModel.CancelEventArgs(); var dialog = new Mock <IPasswordDialog>(); var dialogResult = new PasswordDialogResult { Password = "******", Success = true }; settings.Security.QuitPasswordHash = "1234"; dialog.Setup(d => d.Show(It.IsAny <IWindow>())).Returns(dialogResult); hashAlgorithm.Setup(h => h.GenerateHashFor(It.IsAny <string>())).Returns("9876"); uiFactory.Setup(u => u.CreatePasswordDialog(It.IsAny <TextKey>(), It.IsAny <TextKey>())).Returns(dialog.Object); sut.TryStart(); taskbar.Raise(t => t.QuitButtonClicked += null, args as object); messageBox.Verify(m => m.Show( It.IsAny <TextKey>(), It.IsAny <TextKey>(), It.IsAny <MessageBoxAction>(), It.Is <MessageBoxIcon>(i => i == MessageBoxIcon.Warning), It.IsAny <IWindow>()), Times.Once); uiFactory.Verify(u => u.CreatePasswordDialog(It.IsAny <TextKey>(), It.IsAny <TextKey>()), Times.Once); runtimeProxy.Verify(p => p.RequestShutdown(), Times.Never); Assert.IsTrue(args.Cancel); }
/// <summary> /// Handles a key press on in password input textbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void tbPasswordInput_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { pdrResult = PasswordDialogResult.Cancelled; this.Close(); } else if (e.KeyCode == Keys.Enter) { if (tbPasswordInput.Text.ToUpper() == sPassword.ToUpper()) { pdrResult = PasswordDialogResult.Correct; this.Close(); } else { if (nRetriesRemaining == 0) { pdrResult = PasswordDialogResult.Incorrect; this.Close(); } else { nRetriesRemaining -= 1; tbPasswordInput.Clear(); } } } }
public void Shutdown_MustAbortAskingUserForQuitPassword() { var args = new System.ComponentModel.CancelEventArgs(); var dialog = new Mock <IPasswordDialog>(); var dialogResult = new PasswordDialogResult { Success = false }; settings.Security.QuitPasswordHash = "1234"; dialog.Setup(d => d.Show(It.IsAny <IWindow>())).Returns(dialogResult); runtimeProxy.Setup(r => r.RequestShutdown()).Returns(new CommunicationResult(true)); uiFactory.Setup(u => u.CreatePasswordDialog(It.IsAny <TextKey>(), It.IsAny <TextKey>())).Returns(dialog.Object); sut.TryStart(); taskbar.Raise(t => t.QuitButtonClicked += null, args as object); uiFactory.Verify(u => u.CreatePasswordDialog(It.IsAny <TextKey>(), It.IsAny <TextKey>()), Times.Once); runtimeProxy.Verify(p => p.RequestShutdown(), Times.Never); Assert.IsTrue(args.Cancel); }
/// <summary> /// Initialises the form /// </summary> /// <param name="sPasswordRequired">The password that is required by the user</param> /// <param name="sMessage">The message to show to the user</param> /// <param name="s">The size of this form</param> /// <param name="sSC">The ShowCode - the reason for opening, no presets, can be anything</param> public frmPasswordInput(string sPasswordRequired, string sMessage, Size s, string sSC) { sFontName = Properties.Settings.Default.sFontName; sPassword = sPasswordRequired; sMessageToShow = sMessage; cFrmBackColour = Properties.Settings.Default.cFrmBackColour; cFrmForeColour = Properties.Settings.Default.cFrmForeColour; sShowCode = sSC; pdrResult = PasswordDialogResult.Incorrect; this.Size = s; this.StartPosition = FormStartPosition.CenterScreen; this.BackColor = cFrmBackColour; this.ForeColor = cFrmForeColour; this.FormBorderStyle = FormBorderStyle.None; lblMessage = new Label(); lblMessage.AutoSize = false; lblMessage.Width = this.Width; lblMessage.Height = (int)(Properties.Settings.Default.fMainScreenFontSize * 2); lblMessage.Top = this.Height / 4; lblMessage.Left = 0; lblMessage.Font = new Font(sFontName, Properties.Settings.Default.fMainScreenFontSize); lblMessage.BackColor = cFrmBackColour; lblMessage.ForeColor = cFrmForeColour; lblMessage.Text = sMessage; lblMessage.TextAlign = ContentAlignment.MiddleCenter; this.Controls.Add(lblMessage); tbPasswordInput = new TextBox(); tbPasswordInput.Font = new Font(sFontName, 18.0f); tbPasswordInput.PasswordChar = ' '; tbPasswordInput.Width = this.Width / 5; tbPasswordInput.Left = (this.Width / 2) - (tbPasswordInput.Width / 2); tbPasswordInput.Top = this.Height / 2; tbPasswordInput.BackColor = cFrmForeColour; tbPasswordInput.ForeColor = Properties.Settings.Default.cFrmBackColour; tbPasswordInput.BorderStyle = BorderStyle.None; tbPasswordInput.KeyDown += new KeyEventHandler(tbPasswordInput_KeyDown); this.Controls.Add(tbPasswordInput); }
public void Operations_MustRequestPasswordViaDialogOnDefaultDesktop() { var args = new PasswordRequiredEventArgs(); var passwordDialog = new Mock <IPasswordDialog>(); var result = new PasswordDialogResult { Password = "******", Success = true }; currentSettings.Security.KioskMode = KioskMode.DisableExplorerShell; passwordDialog.Setup(p => p.Show(It.IsAny <IWindow>())).Returns(result); uiFactory.Setup(u => u.CreatePasswordDialog(It.IsAny <string>(), It.IsAny <string>())).Returns(passwordDialog.Object); sut.TryStart(); sessionSequence.Raise(s => s.ActionRequired += null, args); clientProxy.VerifyNoOtherCalls(); passwordDialog.Verify(p => p.Show(It.IsAny <IWindow>()), Times.Once); uiFactory.Verify(u => u.CreatePasswordDialog(It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.AreEqual(true, args.Success); Assert.AreEqual(result.Password, args.Password); }
public void Communication_MustCorrectlyHandlePasswordRequest() { var args = new PasswordRequestEventArgs { Purpose = PasswordRequestPurpose.LocalSettings, RequestId = Guid.NewGuid() }; var dialog = new Mock <IPasswordDialog>(); var result = new PasswordDialogResult { Password = "******", Success = true }; dialog.Setup(d => d.Show(It.IsAny <IWindow>())).Returns(result); uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny <string>(), It.IsAny <string>())).Returns(dialog.Object); sut.TryStart(); clientHost.Raise(c => c.PasswordRequested += null, args); runtimeProxy.Verify(p => p.SubmitPassword( It.Is <Guid>(g => g == args.RequestId), It.Is <bool>(b => b == result.Success), It.Is <string>(s => s == result.Password)), Times.Once); }
public IPasswordDialogResult Show(IWindow parent = null) { return(Dispatcher.Invoke(() => { var result = new PasswordDialogResult { Success = false }; if (parent is Window) { Owner = parent as Window; WindowStartupLocation = WindowStartupLocation.CenterOwner; } if (ShowDialog() is true) { result.Password = Password.Password; result.Success = true; } return result; })); }
public PasswordDialogResult Show(IWindow parent = null) { return(Dispatcher.Invoke(() => { var result = new PasswordDialogResult { Success = false }; if (parent is Window) { Owner = parent as Window; } InitializeBounds(); if (ShowDialog() is true) { result.Password = Password.Password; result.Success = true; } return result; })); }