Skip to content

Commit

Permalink
Fix tests and refactor random string generation
Browse files Browse the repository at this point in the history
  • Loading branch information
rdgallagher committed Jan 28, 2015
1 parent 32fbc2d commit 9d0711f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void testCreatingAnAccount() throws Exception {
.param("code", "test"+generator.counter.get()))
.andDo(print())
.andExpect(status().isFound())
.andExpect(redirectedUrl("http://localhost:8080/uaa/home"))
.andExpect(redirectedUrl("home"))
.andReturn();

SecurityContext securityContext = (SecurityContext) mvcResult.getRequest().getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
Expand Down Expand Up @@ -187,7 +187,7 @@ public void testCreatingAnAccountWithAnEmptyClientId() throws Exception {
.param("code", "test"+generator.counter.get()))
.andDo(print())
.andExpect(status().isFound())
.andExpect(redirectedUrl("http://localhost:8080/uaa/home"))
.andExpect(redirectedUrl("home"))
.andReturn();

SecurityContext securityContext = (SecurityContext) mvcResult.getRequest().getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
Expand Down Expand Up @@ -276,7 +276,7 @@ public void testCreatingAnAccountInAnotherZoneWithNoClientRedirect() throws Exce
.with(new SetServerNameRequestPostProcessor("mysubdomain.localhost")))
.andDo(print())
.andExpect(status().isFound())
.andExpect(redirectedUrl("http://mysubdomain.localhost:8080/uaa/home"))
.andExpect(redirectedUrl("home"))
.andReturn();

SecurityContext securityContext = (SecurityContext) mvcResult.getRequest().getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.scim.endpoints;

import org.apache.commons.lang.RandomStringUtils;
import org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification;
import org.cloudfoundry.identity.uaa.scim.ScimUser;
import org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning;
Expand Down Expand Up @@ -42,7 +41,6 @@

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -141,7 +139,7 @@ public void testVerifyUserWithScimCreateToken() throws Exception {

@Test
public void testCreateUserInZone() throws Exception {
String subdomain = RandomStringUtils.random(8);
String subdomain = generator.generate();
createOtherIdentityZone(subdomain);

String zoneAdminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "admin-secret", "scim.write", subdomain);
Expand All @@ -151,10 +149,10 @@ public void testCreateUserInZone() throws Exception {

@Test
public void testCreateUserInOtherZoneIsUnauthorized() throws Exception {
String subdomain = RandomStringUtils.random(8);
String subdomain = generator.generate();
createOtherIdentityZone(subdomain);

String otherSubdomain = RandomStringUtils.random(8);
String otherSubdomain = generator.generate();
createOtherIdentityZone(otherSubdomain);

String zoneAdminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "admin-secret", "scim.write", subdomain);
Expand All @@ -173,7 +171,7 @@ public void testCreateUserInOtherZoneIsUnauthorized() throws Exception {

private IdentityZone createOtherIdentityZone(String subdomain) throws Exception {

String identityToken = testClient.getClientCredentialsOAuthAccessToken("identity", "identitysecret", "zones.create", null);
String identityToken = testClient.getClientCredentialsOAuthAccessToken("identity", "identitysecret", "zones.create");

IdentityZone identityZone = MultitenancyFixture.identityZone(subdomain, subdomain);
IdentityZoneCreationRequest creationRequest = new IdentityZoneCreationRequest();
Expand All @@ -185,7 +183,7 @@ private IdentityZone createOtherIdentityZone(String subdomain) throws Exception
clientDetails.add(client);
creationRequest.setClientDetails(clientDetails);

mockMvc.perform(put("/identity-zones/" + subdomain)
mockMvc.perform(post("/identity-zones")
.header("Authorization", "Bearer " + identityToken)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
Expand Down

0 comments on commit 9d0711f

Please sign in to comment.