Search in sources :

Example 11 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method testForcePasswordExpireAccountExternalUser.

@Test
void testForcePasswordExpireAccountExternalUser() throws Exception {
    ScimUser user = createUser(uaaAdminToken);
    user.setOrigin("NOT_UAA");
    updateUser(uaaAdminToken, HttpStatus.OK.value(), user);
    UserAccountStatus alteredAccountStatus = new UserAccountStatus();
    alteredAccountStatus.setPasswordChangeRequired(true);
    updateAccountStatus(user, alteredAccountStatus).andExpect(status().isBadRequest());
    assertFalse(usersRepository.checkPasswordChangeIndividuallyRequired(user.getId(), IdentityZoneHolder.get().getId()));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) UserAccountStatus(org.cloudfoundry.identity.uaa.account.UserAccountStatus) Test(org.junit.jupiter.api.Test)

Example 12 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method verification_link.

@Test
void verification_link() throws Exception {
    ScimUser joel = setUpScimUser();
    MockHttpServletRequestBuilder get = setUpVerificationLinkRequest(joel, scimCreateToken);
    MvcResult result = mockMvc.perform(get).andExpect(status().isOk()).andReturn();
    VerificationResponse verificationResponse = JsonUtils.readValue(result.getResponse().getContentAsString(), VerificationResponse.class);
    assertThat(verificationResponse.getVerifyLink().toString(), startsWith("http://localhost/verify_user"));
    String query = verificationResponse.getVerifyLink().getQuery();
    String code = getQueryStringParam(query, "code");
    assertThat(code, is(notNullValue()));
    ExpiringCode expiringCode = codeStore.retrieveCode(code, IdentityZoneHolder.get().getId());
    assertThat(expiringCode.getExpiresAt().getTime(), is(greaterThan(System.currentTimeMillis())));
    assertThat(expiringCode.getIntent(), is(REGISTRATION.name()));
    Map<String, String> data = JsonUtils.readValue(expiringCode.getData(), new TypeReference<Map<String, String>>() {
    });
    assertThat(data.get(USER_ID), is(notNullValue()));
    assertThat(data.get(CLIENT_ID), is(clientDetails.getClientId()));
    assertThat(data.get(REDIRECT_URI), is(HTTP_REDIRECT_EXAMPLE_COM));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ExpiringCode(org.cloudfoundry.identity.uaa.codestore.ExpiringCode) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 13 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method verification_link_is_authorized_endpoint.

@Test
void verification_link_is_authorized_endpoint() throws Exception {
    ScimUser joel = setUpScimUser();
    MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/Users/" + joel.getId() + "/verify-link").param("redirect_uri", HTTP_REDIRECT_EXAMPLE_COM).accept(APPLICATION_JSON);
    mockMvc.perform(get).andExpect(status().isUnauthorized());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsTests method patchIncorrectVersionFails.

@Test
void patchIncorrectVersionFails() {
    ScimUser user = new ScimUser(null, "uname", "gname", "fname");
    user.setPassword("password");
    user.addEmail("test@example.org");
    ScimUser createdUser = scimUserEndpoints.createUser(user, new MockHttpServletRequest(), new MockHttpServletResponse());
    assertThrows(ScimResourceConflictException.class, () -> scimUserEndpoints.patchUser(createdUser, createdUser.getId(), Integer.toString(createdUser.getVersion() + 1), new MockHttpServletRequest(), new MockHttpServletResponse(), null));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 15 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method testUserSelfAccess_Get_and_Post.

@Test
void testUserSelfAccess_Get_and_Post() throws Exception {
    ScimUser user = getScimUser();
    user.setPassword("secret");
    ScimUser savedUser = createUser(user, scimReadWriteToken, IdentityZone.getUaa().getSubdomain());
    String selfToken = testClient.getUserOAuthAccessToken("cf", "", savedUser.getUserName(), "secret", "");
    savedUser.setName(new ScimUser.Name("Given1", "Family1"));
    ScimUser updatedUser = updateUser(selfToken, HttpStatus.OK.value(), savedUser);
    getAndReturnUser(HttpStatus.OK.value(), updatedUser, selfToken);
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) Test(org.junit.jupiter.api.Test)

Aggregations

ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)495 Test (org.junit.jupiter.api.Test)301 Matchers.containsString (org.hamcrest.Matchers.containsString)136 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)80 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)75 Test (org.junit.Test)57 ExpiringCode (org.cloudfoundry.identity.uaa.codestore.ExpiringCode)56 MvcResult (org.springframework.test.web.servlet.MvcResult)50 Timestamp (java.sql.Timestamp)49 MockHttpSession (org.springframework.mock.web.MockHttpSession)47 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)43 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)41 HashMap (java.util.HashMap)39 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)35 Map (java.util.Map)34 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)33 RestTemplate (org.springframework.web.client.RestTemplate)30 ScimGroupMember (org.cloudfoundry.identity.uaa.scim.ScimGroupMember)29 List (java.util.List)27