public void SaveAdminPasswordReturnsFalseIfGettingStreamThrowsUnauthorizedAccessException() { // Act bool passwordSaved = AdminSecurity.SaveTemporaryPassword("password", () => { throw new UnauthorizedAccessException(); }); // Assert Assert.False(passwordSaved); }
public void SaveAdminPasswordUsesCryptoToWritePasswordAndSalt() { // Arrange var password = "******"; MemoryStream ms = new MemoryStream(); // Act bool passwordSaved = AdminSecurity.SaveTemporaryPassword(password, () => ms); // Assert Assert.True(passwordSaved); string savedPassword = Encoding.Default.GetString(ms.ToArray()); // Trim everything after the new line. Cannot use the properties from the stream since it is already closed by the writer. savedPassword = savedPassword.Substring(0, savedPassword.IndexOf(Environment.NewLine)); Assert.True(Crypto.VerifyHashedPassword(savedPassword, password)); }