use of org.haiku.haikudepotserver.passwordreset.PasswordResetException in project haikudepotserver by haiku.
the class UserApiIT method testCompletePasswordReset_ok.
/**
* <p>This checks a password reset token can be picked-up and actioned. The token will have been sent to the
* user earlier in an email.</p>
*/
@Test
public void testCompletePasswordReset_ok() {
createPasswordResetTestUser();
Assertions.assertThat(getOnlyPasswordResetTokenCodeForTestUser()).isNull();
try {
passwordResetService.initiate("integration-test-recipient@haiku-os.org");
} catch (PasswordResetException pre) {
throw new IllegalStateException("unable to initiate the password reset when testing complete", pre);
}
Captcha captcha = captchaService.generate();
CompletePasswordResetRequest request = new CompletePasswordResetRequest();
request.captchaToken = captcha.getToken();
request.captchaResponse = captcha.getResponse();
request.token = getOnlyPasswordResetTokenCodeForTestUser();
request.passwordClear = "kQ83hWi3oWnYY21k";
// ------------------------------------
userApi.completePasswordReset(request);
// ------------------------------------
// the user should now be able to be authenticated with the new password.
Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "kQ83hWi3oWnYY21k").isPresent()).isTrue();
{
ObjectContext context = serverRuntime.newContext();
Optional<UserPasswordResetToken> token = UserPasswordResetToken.getByCode(context, request.token);
Assertions.assertThat(token.isPresent()).isFalse();
}
}
Aggregations