Search in sources :

Example 1 with ForgotPasswordInfo

use of org.cloudfoundry.identity.uaa.account.ForgotPasswordInfo in project uaa by cloudfoundry.

the class UaaResetPasswordServiceTests method forgotPassword_ResetCodeIsReturnedSuccessfully.

@Test
void forgotPassword_ResetCodeIsReturnedSuccessfully() {
    ScimUser user = new ScimUser("user-id-001", "exampleUser", "firstName", "lastName");
    user.setPasswordLastModified(new Date(1234));
    user.setPrimaryEmail("user@example.com");
    String zoneID = currentZoneId;
    when(scimUserProvisioning.retrieveByUsernameAndOriginAndZone(anyString(), anyString(), eq(zoneID))).thenReturn(Collections.singletonList(user));
    Timestamp expiresAt = new Timestamp(System.currentTimeMillis());
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    when(codeStore.generateCode(eq("{\"user_id\":\"user-id-001\",\"username\":\"exampleUser\",\"passwordModifiedTime\":1234,\"client_id\":\"example\",\"redirect_uri\":\"redirect.example.com\"}"), any(Timestamp.class), anyString(), anyString())).thenReturn(new ExpiringCode("code", expiresAt, "user-id-001", null));
    ForgotPasswordInfo forgotPasswordInfo = uaaResetPasswordService.forgotPassword("exampleUser", "example", "redirect.example.com");
    verify(codeStore).expireByIntent(captor.capture(), anyString());
    assertEquals(UaaResetPasswordService.FORGOT_PASSWORD_INTENT_PREFIX + user.getId(), captor.getValue());
    assertThat(forgotPasswordInfo.getUserId(), equalTo("user-id-001"));
    assertThat(forgotPasswordInfo.getEmail(), equalTo("user@example.com"));
    ExpiringCode resetPasswordCode = forgotPasswordInfo.getResetPasswordCode();
    assertThat(resetPasswordCode.getCode(), equalTo("code"));
    assertThat(resetPasswordCode.getExpiresAt(), equalTo(expiresAt));
    assertThat(resetPasswordCode.getData(), equalTo("user-id-001"));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ExpiringCode(org.cloudfoundry.identity.uaa.codestore.ExpiringCode) ForgotPasswordInfo(org.cloudfoundry.identity.uaa.account.ForgotPasswordInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.anyString(org.mockito.Mockito.anyString) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with ForgotPasswordInfo

use of org.cloudfoundry.identity.uaa.account.ForgotPasswordInfo in project uaa by cloudfoundry.

the class UaaResetPasswordServiceTests method forgotPasswordFallsBackToUsernameIfNoPrimaryEmail.

@Test
void forgotPasswordFallsBackToUsernameIfNoPrimaryEmail() {
    ScimUser user = new ScimUser("user-id-001", "user@example.com", "firstName", "lastName");
    String zoneID = currentZoneId;
    when(scimUserProvisioning.retrieveByUsernameAndOriginAndZone(anyString(), anyString(), eq(zoneID))).thenReturn(Collections.singletonList(user));
    Timestamp expiresAt = new Timestamp(System.currentTimeMillis());
    when(codeStore.generateCode(anyString(), any(Timestamp.class), anyString(), anyString())).thenReturn(new ExpiringCode("code", expiresAt, "user-id-001", null));
    ForgotPasswordInfo forgotPasswordInfo = uaaResetPasswordService.forgotPassword("exampleUser", "example", "redirect.example.com");
    assertThat(forgotPasswordInfo.getEmail(), equalTo("user@example.com"));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ExpiringCode(org.cloudfoundry.identity.uaa.codestore.ExpiringCode) ForgotPasswordInfo(org.cloudfoundry.identity.uaa.account.ForgotPasswordInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.anyString(org.mockito.Mockito.anyString) Timestamp(java.sql.Timestamp) Test(org.junit.jupiter.api.Test)

Aggregations

Timestamp (java.sql.Timestamp)2 ForgotPasswordInfo (org.cloudfoundry.identity.uaa.account.ForgotPasswordInfo)2 ExpiringCode (org.cloudfoundry.identity.uaa.codestore.ExpiringCode)2 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.jupiter.api.Test)2 Mockito.anyString (org.mockito.Mockito.anyString)2 Date (java.util.Date)1