Search in sources :

Example 11 with ScimMeta

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\"")));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ScimMeta(org.cloudfoundry.identity.uaa.scim.ScimMeta) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 12 with ScimMeta

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\"")));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ScimMeta(org.cloudfoundry.identity.uaa.scim.ScimMeta) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 13 with ScimMeta

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);
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ScimMeta(org.cloudfoundry.identity.uaa.scim.ScimMeta) ExpiringCode(org.cloudfoundry.identity.uaa.codestore.ExpiringCode) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MockAuthentication(org.cloudfoundry.identity.uaa.test.MockAuthentication) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

ScimMeta (org.cloudfoundry.identity.uaa.scim.ScimMeta)13 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)12 Test (org.junit.jupiter.api.Test)11 Date (java.util.Date)10 Timestamp (java.sql.Timestamp)6 ExpiringCode (org.cloudfoundry.identity.uaa.codestore.ExpiringCode)6 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 MockAuthentication (org.cloudfoundry.identity.uaa.test.MockAuthentication)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Mockito.anyString (org.mockito.Mockito.anyString)4 InvalidPasswordException (org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException)3 SecurityContext (org.springframework.security.core.context.SecurityContext)2 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)1 PasswordChange (org.cloudfoundry.identity.uaa.scim.endpoints.PasswordChange)1 JSONObject (org.json.JSONObject)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1