public void ShouldHaveValidationErrorWithEmptyOldPassword(string OldPassword) { UpdatePasswordUserRequestModel requestModel = new UpdatePasswordUserRequestModel() { OldPassword = OldPassword }; _validator.ShouldHaveValidationErrorFor(r => r.OldPassword, requestModel).WithErrorMessage("old password cannot be empty."); }
public void ShouldHaveValidationErrorWithGreaterThan60CharactersOldPassword(string OldPassword) { UpdatePasswordUserRequestModel requestModel = new UpdatePasswordUserRequestModel() { OldPassword = OldPassword }; _validator.ShouldHaveValidationErrorFor(r => r.OldPassword, requestModel).WithErrorMessage("old password must be less than 60 characters."); }
public void ShouldNotHaveValidationErrorWithEqualNewPassword(string newPassword, string newPasswordConfirmation) { UpdatePasswordUserRequestModel requestModel = new UpdatePasswordUserRequestModel() { NewPassword = newPassword, NewPasswordConfirmation = newPasswordConfirmation }; _validator.ShouldNotHaveValidationErrorFor(r => r.NewPasswordConfirmation, requestModel); }
public void ShouldHaveValidationErrorWithNotEqualNewPassword(string newPassword, string newPasswordConfirmation) { UpdatePasswordUserRequestModel requestModel = new UpdatePasswordUserRequestModel() { NewPassword = newPassword, NewPasswordConfirmation = newPasswordConfirmation }; _validator.ShouldHaveValidationErrorFor(r => r.NewPasswordConfirmation, requestModel).WithErrorMessage("new password confirmation must be equal to new password."); }
public async Task <IActionResult> UpdatePassword(UpdatePasswordUserRequestModel model) { try { await _userService.UpdatePassword(this.GetUserIdFromToken(), model); return(Ok()); } catch (Exception exception) { return(this.HandleExceptionToUserAndLogIfExceptionIsUnexpected(exception)); } }
public async Task ShouldReturnOkOnCallUpdateUserPassword() { Guid id = await InsertUserOnDatabase(); _httpClient.InsertAuthorizationTokenOnRequestHeader(_authorizationTokenHelper.CreateToken(id)); UpdatePasswordUserRequestModel model = new UpdatePasswordUserRequestModel() { NewPassword = "******", NewPasswordConfirmation = "NEWPASSWORD", OldPassword = "******" }; HttpResponseMessage httpResponse = await _httpClient.PutAsync("../users/password", _createRequestHelper.CreateStringContent(model)); Assert.Equal((int)HttpStatusCode.OK, (int)httpResponse.StatusCode); }
public async Task ShouldInvalidPasswordExceptionOnTryUpdateUserPasswordWithIncorrectOldPassword() { UpdatePasswordUserRequestModel model = new UpdatePasswordUserRequestModel() { OldPassword = "******", NewPassword = "******", NewPasswordConfirmation = "new password" }; _userRepositoryMock.GetById(Arg.Any <Guid>()).Returns(_fakeConfirmedInsertedUser); _hashUtilsMock.CompareHash(Arg.Any <string>(), Arg.Any <string>()).Returns(false); Exception exception = await Record.ExceptionAsync(() => _userService.UpdatePassword(_fakeConfirmedInsertedUser.Id.ToString(), model)); Assert.IsType <InvalidPasswordException>(exception); }
public async Task ShouldThrowResourceNotFoundExceptionOnTryUpdateNotExistsUserPassword() { User notExistsUser = null; UpdatePasswordUserRequestModel model = new UpdatePasswordUserRequestModel() { OldPassword = "******", NewPassword = "******", NewPasswordConfirmation = "new password" }; _userRepositoryMock.GetById(Arg.Any <Guid>()).Returns(notExistsUser); Exception exception = await Record.ExceptionAsync(() => _userService.UpdatePassword(Guid.NewGuid().ToString(), model)); Assert.IsType <ResourceNotFoundException>(exception); }
public async Task ShouldUpdateUserPassword() { UpdatePasswordUserRequestModel model = new UpdatePasswordUserRequestModel() { OldPassword = "******", NewPassword = "******", NewPasswordConfirmation = "new password" }; _userRepositoryMock.GetById(Arg.Any <Guid>()).Returns(_fakeConfirmedInsertedUser); _hashUtilsMock.CompareHash(Arg.Any <string>(), Arg.Any <string>()).Returns(true); Exception exception = await Record.ExceptionAsync(() => _userService.UpdatePassword(_fakeConfirmedInsertedUser.Id.ToString(), model)); Assert.Null(exception); await _userRepositoryMock.Received(1).Save(); }
public async Task UpdatePassword(string userId, UpdatePasswordUserRequestModel model) { await new UpdatePasswordUserValidator().ValidateRequestModelAndThrow(model); User user = await _userRepository.GetById(Guid.Parse(userId)); ThrowIfUserIsNullOrNotConfirmed(user); if (!_hashUtils.CompareHash(model.OldPassword, user.Password)) { throw new InvalidPasswordException(); } user.UpdatePassword(_hashUtils.GenerateHash(model.NewPassword)); _userRepository.Update(user); await _userRepository.Save(); }