Search in sources :

Example 1 with InitiatePasswordResetRequest

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

the class UserApiIT method testInitiatePasswordReset.

/**
 * <p>This test will check the initiation of the password reset procedure.</p>
 */
@Test
public void testInitiatePasswordReset() {
    createPasswordResetTestUser();
    Captcha captcha = captchaService.generate();
    InitiatePasswordResetRequest request = new InitiatePasswordResetRequest();
    request.captchaToken = captcha.getToken();
    request.captchaResponse = captcha.getResponse();
    request.email = "integration-test-recipient@haiku-os.org";
    // ------------------------------------
    userApi.initiatePasswordReset(request);
    // ------------------------------------
    {
        ObjectContext context = serverRuntime.newContext();
        User user = User.tryGetByNickname(context, "testuser").get();
        // check for the presence of a token.
        List<UserPasswordResetToken> tokens = UserPasswordResetToken.findByUser(context, user);
        Assertions.assertThat(tokens.size()).isEqualTo(1);
        UserPasswordResetToken token = tokens.get(0);
        // check that an email did actually get sent.
        List<SimpleMailMessage> messages = mailSender.getSentMessages();
        Assertions.assertThat(messages.size()).isEqualTo(1);
        SimpleMailMessage message = messages.get(0);
        Assertions.assertThat(message.getTo()).isEqualTo(new String[] { "integration-test-recipient@haiku-os.org" });
        Assertions.assertThat(message.getFrom()).isEqualTo("integration-test-sender@haiku-os.org");
        Assertions.assertThat(message.getText()).contains(token.getCode());
    }
}
Also used : Captcha(org.haiku.haikudepotserver.captcha.model.Captcha) User(org.haiku.haikudepotserver.dataobjects.User) UserPasswordResetToken(org.haiku.haikudepotserver.dataobjects.UserPasswordResetToken) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) InitiatePasswordResetRequest(org.haiku.haikudepotserver.api1.model.user.InitiatePasswordResetRequest) List(java.util.List) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)1 ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 InitiatePasswordResetRequest (org.haiku.haikudepotserver.api1.model.user.InitiatePasswordResetRequest)1 Captcha (org.haiku.haikudepotserver.captcha.model.Captcha)1 User (org.haiku.haikudepotserver.dataobjects.User)1 UserPasswordResetToken (org.haiku.haikudepotserver.dataobjects.UserPasswordResetToken)1 Test (org.junit.jupiter.api.Test)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1