Search in sources :

Example 1 with ChangePasswordRequest

use of org.haiku.haikudepotserver.api1.model.user.ChangePasswordRequest in project haikudepotserver by haiku.

the class UserApiIT method testChangePassword.

@Test
public void testChangePassword() {
    Captcha captcha = captchaService.generate();
    ObjectContext context = serverRuntime.newContext();
    User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
    setAuthenticatedUser("testuser");
    // check that the password is correctly configured.
    Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "U7vqpsu6BB").get()).isEqualTo(user.getObjectId());
    // now change it.
    ChangePasswordRequest request = new ChangePasswordRequest();
    request.nickname = "testuser";
    request.captchaResponse = captcha.getResponse();
    request.captchaToken = captcha.getToken();
    request.newPasswordClear = "8R3nlp11gX";
    request.oldPasswordClear = "U7vqpsu6BB";
    // ------------------------------------
    userApi.changePassword(request);
    // ------------------------------------
    // now check that the old authentication no longer works and the new one does work
    Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "U7vqpsu6BB").isPresent()).isFalse();
    Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "8R3nlp11gX").get()).isEqualTo(user.getObjectId());
}
Also used : Captcha(org.haiku.haikudepotserver.captcha.model.Captcha) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext) ChangePasswordRequest(org.haiku.haikudepotserver.api1.model.user.ChangePasswordRequest) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 ChangePasswordRequest (org.haiku.haikudepotserver.api1.model.user.ChangePasswordRequest)1 Captcha (org.haiku.haikudepotserver.captcha.model.Captcha)1 User (org.haiku.haikudepotserver.dataobjects.User)1 Test (org.junit.jupiter.api.Test)1