Search in sources :

Example 1 with CompletePasswordResetRequest

use of org.haiku.haikudepotserver.api1.model.user.CompletePasswordResetRequest 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();
    }
}
Also used : PasswordResetException(org.haiku.haikudepotserver.passwordreset.PasswordResetException) Captcha(org.haiku.haikudepotserver.captcha.model.Captcha) Optional(java.util.Optional) CompletePasswordResetRequest(org.haiku.haikudepotserver.api1.model.user.CompletePasswordResetRequest) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Optional (java.util.Optional)1 ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 CompletePasswordResetRequest (org.haiku.haikudepotserver.api1.model.user.CompletePasswordResetRequest)1 Captcha (org.haiku.haikudepotserver.captcha.model.Captcha)1 PasswordResetException (org.haiku.haikudepotserver.passwordreset.PasswordResetException)1 Test (org.junit.jupiter.api.Test)1