Skip to content

Commit

Permalink
Add in test case to reproduce encoded redirect URL bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanik committed Jan 30, 2015
1 parent 0ee43ef commit 55a17f5
Showing 1 changed file with 46 additions and 1 deletion.
Expand Up @@ -177,12 +177,18 @@ private IdentityProvider setupIdentityProvider() {
}

protected void setUpClients(String id, String authorities, String scopes, String grantTypes, Boolean autoapprove) {
setUpClients(id,authorities,scopes,grantTypes,autoapprove,null);
}
protected void setUpClients(String id, String authorities, String scopes, String grantTypes, Boolean autoapprove, String redirectUri) {
BaseClientDetails c = new BaseClientDetails(id, "", scopes, grantTypes, authorities);
c.setClientSecret(SECRET);
c.setRegisteredRedirectUri(new HashSet<String>(Arrays.asList(TEST_REDIRECT_URI)));
c.setRegisteredRedirectUri(new HashSet<>(Arrays.asList(TEST_REDIRECT_URI)));
Map<String,String> additional = new HashMap<>();
additional.put("autoapprove",autoapprove.toString());
c.setAdditionalInformation(additional);
if (StringUtils.hasText(redirectUri)) {
c.setRegisteredRedirectUri(new HashSet<>(Arrays.asList(redirectUri)));
}
clientDetailsService.addClientDetails(c);
}

Expand Down Expand Up @@ -390,6 +396,45 @@ public void testOpenIdTokenHybridFlowWithNoImplicitGrantWhenStrictWhenAppNotAppr
assertEquals("Unauthorized grant type: implicit", ((List<String>) query.get("error_description")).get(0));
}

@Test
public void testAuthorizationCodeGrantWithEncodedRedirectURL() throws Exception {
String redirectUri = "https://example.com/dashboard/?appGuid=app-guid&ace_config=%7B%22orgGuid%22%3A%22org-guid%22%2C%22spaceGuid%22%3A%22space-guid%22%2C%22appGuid%22%3A%22app-guid%22%2C%22redirect%22%3A%22https%3A%2F%2Fexample.com%2F%22%7D";
//String redirectUri = "https://example.com/dashboard/?appGuid=app-guid&ace_config=test";
String clientId = "authclient-"+new RandomValueStringGenerator().generate();
String scopes = "openid";
setUpClients(clientId, scopes, scopes, GRANT_TYPES, true, redirectUri);
String username = "authuser"+new RandomValueStringGenerator().generate();
String userScopes = "openid";
ScimUser developer = setUpUser(username, userScopes);
String basicDigestHeaderValue = "Basic "
+ new String(org.apache.commons.codec.binary.Base64.encodeBase64((clientId + ":" + SECRET).getBytes()));
UaaPrincipal p = new UaaPrincipal(developer.getId(),developer.getUserName(),developer.getPrimaryEmail(), Origin.UAA,"", IdentityZoneHolder.get().getId());
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(p, "", UaaAuthority.USER_AUTHORITIES);
Assert.assertTrue(auth.isAuthenticated());

SecurityContextHolder.getContext().setAuthentication(auth);
MockHttpSession session = new MockHttpSession();
session.setAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
new MockSecurityContext(auth)
);

String state = new RandomValueStringGenerator().generate();
MockHttpServletRequestBuilder authRequest = get("/oauth/authorize")
.header("Authorization", basicDigestHeaderValue)
.session(session)
.param(OAuth2Utils.RESPONSE_TYPE, "code")
.param(OAuth2Utils.SCOPE, "openid")
.param(OAuth2Utils.STATE, state)
.param(OAuth2Utils.CLIENT_ID, clientId)
.param(OAuth2Utils.REDIRECT_URI, redirectUri);

MvcResult result = mockMvc.perform(authRequest).andExpect(status().is3xxRedirection()).andReturn();
String location = result.getResponse().getHeader("Location");
location = location.substring(0,location.indexOf("&code="));
assertEquals(redirectUri, location);
}

@Test
public void testOpenIdToken() throws Exception {
String clientId = "testclient"+new RandomValueStringGenerator().generate();
Expand Down

0 comments on commit 55a17f5

Please sign in to comment.