public async Task ChangePassword_GivenDifferentNewAndConfirmPassword_ThrowsException() { var userRepository = Substitute.For <IUserRepository>(); var roleRepository = Substitute.For <IRoleRepository>(); var teamRepository = Substitute.For <ITeamRepository>(); var ldapRepository = Substitute.For <ILdapAuthenticationModeRepository>(); var ldapConnectionService = Substitute.For <ILdapConnectionService>(); var userPasswordChangeSubmit = new UserPasswordChangeSubmit() { Uuid = Guid.NewGuid(), OldPassword = "******", NewPassword = "******", NewPasswordConfirmed = "newPassword2" }; var userService = new UserService(userRepository, roleRepository, teamRepository, ldapRepository, mapper, ldapConnectionService); Exception caughtException = null; try { await userService.ChangePassword(userPasswordChangeSubmit); } catch (Exception ex) { caughtException = ex; } Assert.True(caughtException is ItemNotProcessableException, "Correctly changing password should NOT throw any exeption"); Assert.True(caughtException.Message == "New password and confirm new password fields do not match.", "Differing new passwords should return 'New password and confirm new password fields do not match.'"); }
public async Task ChangePassword_GivenNoOldPassword_ThrowsException() { var userRepository = Substitute.For <IUserRepository>(); var roleRepository = Substitute.For <IRoleRepository>(); var teamRepository = Substitute.For <ITeamRepository>(); var ldapRepository = Substitute.For <ILdapAuthenticationModeRepository>(); var ldapConnectionService = Substitute.For <ILdapConnectionService>(); var userPasswordChangeSubmit = new UserPasswordChangeSubmit() { Uuid = Guid.NewGuid(), NewPassword = "******", NewPasswordConfirmed = "newPassword1" }; var userService = new UserService(userRepository, roleRepository, teamRepository, ldapRepository, mapper, ldapConnectionService); Exception caughtException = null; try { await userService.ChangePassword(userPasswordChangeSubmit); } catch (Exception ex) { caughtException = ex; } Assert.True(caughtException is ItemNotProcessableException, "Correctly changing password should NOT throw any exeption"); Assert.True(caughtException.Message == "Old password must be specified.", "Missing old password returned should return 'Old password must be specified.'"); }
public async Task ChangePassword_GivenUserChangeSubmit_CompletesSuccessfully() { var userRepository = Substitute.For <IUserRepository>(); var roleRepository = Substitute.For <IRoleRepository>(); var teamRepository = Substitute.For <ITeamRepository>(); var ldapRepository = Substitute.For <ILdapAuthenticationModeRepository>(); var ldapConnectionService = Substitute.For <ILdapConnectionService>(); var userPasswordChangeSubmit = new UserPasswordChangeSubmit() { Uuid = Guid.NewGuid(), OldPassword = "******", NewPassword = "******", NewPasswordConfirmed = "newPassword1" }; var userService = new UserService(userRepository, roleRepository, teamRepository, ldapRepository, mapper, ldapConnectionService); Exception caughtException = null; try { await userService.ChangePassword(userPasswordChangeSubmit); } catch (Exception ex) { caughtException = ex; } Assert.True(caughtException == null, "Correctly changing password should NOT throw any exeption"); }
public async Task ChangePassword_GivenUserChangeSubmit_ReturnsNoContent() { // Arrange var userService = Substitute.For <IUserService>(); var controller = new UserController(userService); var guid = Guid.NewGuid(); var userPasswordChangeSubmit = new UserPasswordChangeSubmit() { Uuid = guid, OldPassword = "******", NewPassword = "******", NewPasswordConfirmed = "newPassword1" }; // Act Exception caughtException = null; IActionResult actionResult = null; try { actionResult = await controller.ChangeUserPasswordAsync(guid, userPasswordChangeSubmit); } catch (Exception ex) { caughtException = ex; } // Assert var noContentResult = actionResult as NoContentResult; Assert.NotNull(noContentResult); }
public async Task ChangePassword(UserPasswordChangeSubmit changeSubmit) { if (string.Compare(changeSubmit.NewPassword, changeSubmit.NewPasswordConfirmed, StringComparison.Ordinal) != 0) { throw new ItemNotProcessableException("New password and confirm new password fields do not match."); } if (string.IsNullOrEmpty(changeSubmit.OldPassword)) { throw new ItemNotProcessableException("Old password must be specified."); } await userRepository.ChangePassword(changeSubmit.Uuid, changeSubmit.OldPassword, changeSubmit.NewPassword); }
public abstract Task <IActionResult> ChangeUserPasswordAsync([FromRoute][Required] Guid userId, [FromBody] UserPasswordChangeSubmit userPasswordChangeSubmit);
public async override Task <IActionResult> ChangeUserPasswordAsync([FromRoute, Required] Guid userId, [FromBody] UserPasswordChangeSubmit userPasswordChangeSubmit) { if (userId == Guid.Empty) { return(BadRequest()); } await userService.ChangePassword(userPasswordChangeSubmit); return(NoContent()); }