use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class PasswordResetEndpointTest method creatingAPasswordResetWhenTheUserHasNonUaaOrigin.
@Test
void creatingAPasswordResetWhenTheUserHasNonUaaOrigin() throws Exception {
when(mockScimUserProvisioning.retrieveByUsernameAndOriginAndZone(eq("user@example.com"), eq(OriginKeys.UAA), eq(currentZoneId))).thenReturn(Collections.emptyList());
ScimUser user = new ScimUser("id001", "user@example.com", null, null);
user.setMeta(new ScimMeta(new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), 0));
user.addEmail("user@example.com");
user.setOrigin(OriginKeys.LDAP);
when(mockScimUserProvisioning.retrieveByUsernameAndZone(eq("user@example.com"), eq(currentZoneId))).thenReturn(Collections.singletonList(user));
MockHttpServletRequestBuilder post = post("/password_resets").contentType(APPLICATION_JSON).content("user@example.com").accept(APPLICATION_JSON);
mockMvc.perform(post).andExpect(status().isConflict()).andExpect(content().string(containsString("\"user_id\":\"id001\"")));
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class PasswordResetEndpointTest method creatingAPasswordResetWhenTheUsernameExists.
@Test
void creatingAPasswordResetWhenTheUsernameExists() throws Exception {
ScimUser user = new ScimUser("id001", "user@example.com", null, null);
user.setMeta(new ScimMeta(yesterday, yesterday, 0));
user.addEmail("user@example.com");
user.setPasswordLastModified(yesterday);
when(mockScimUserProvisioning.retrieveByUsernameAndOriginAndZone(eq("user@example.com"), eq(OriginKeys.UAA), eq(currentZoneId))).thenReturn(Collections.singletonList(user));
MockHttpServletRequestBuilder post = post("/password_resets").contentType(APPLICATION_JSON).content("user@example.com").accept(APPLICATION_JSON);
mockMvc.perform(post).andExpect(status().isCreated()).andExpect(content().string(containsString("\"code\":\"secret_code\""))).andExpect(content().string(containsString("\"user_id\":\"id001\"")));
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class PasswordResetEndpointTest method changingAPasswordWithAValidCode.
@Test
void changingAPasswordWithAValidCode() throws Exception {
ExpiringCode code = new ExpiringCode("secret_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), "{\"user_id\":\"eyedee\",\"username\":\"user@example.com\",\"passwordModifiedTime\":null,\"client_id\":\"\",\"redirect_uri\":\"\"}", null);
when(mockExpiringCodeStore.retrieveCode("secret_code", currentZoneId)).thenReturn(code);
ScimUser scimUser = new ScimUser("eyedee", "user@example.com", "User", "Man");
scimUser.setMeta(new ScimMeta(new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), 0));
scimUser.addEmail("user@example.com");
when(mockScimUserProvisioning.retrieve("eyedee", currentZoneId)).thenReturn(scimUser);
ExpiringCode autologinCode = new ExpiringCode("autologin-code", new Timestamp(System.currentTimeMillis() + 5 * 60 * 1000), "data", AUTOLOGIN.name());
when(mockExpiringCodeStore.generateCode(anyString(), any(Timestamp.class), eq(AUTOLOGIN.name()), anyString())).thenReturn(autologinCode);
MockHttpServletRequestBuilder post = post("/password_change").contentType(APPLICATION_JSON).content("{\"code\":\"secret_code\",\"new_password\":\"new_secret\"}").accept(APPLICATION_JSON);
SecurityContextHolder.getContext().setAuthentication(new MockAuthentication());
mockMvc.perform(post).andExpect(status().isOk()).andExpect(jsonPath("$.user_id").value("eyedee")).andExpect(jsonPath("$.username").value("user@example.com"));
verify(mockScimUserProvisioning).changePassword("eyedee", null, "new_secret", currentZoneId);
}
Aggregations