Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Change-Id: I2c6d3fe0533b626f13239fce6906aaa7962c580e
  • Loading branch information
mikeroda committed Sep 27, 2024
1 parent d5bb2d3 commit acae8b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ private JsonWebKeySet<JsonWebKey> getTokenKeyFromOAuth(AbstractExternalOAuthIden
}
}

private String getTokenFromCode(ExternalOAuthCodeToken codeToken, AbstractExternalOAuthIdentityProviderDefinition config) {
protected String getTokenFromCode(ExternalOAuthCodeToken codeToken, AbstractExternalOAuthIdentityProviderDefinition config) {
if (StringUtils.hasText(codeToken.getIdToken()) && "id_token".equals(getResponseType(config))) {
logger.debug("ExternalOAuthCodeToken contains id_token, not exchanging code.");
return codeToken.getIdToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,38 @@ public void populateAuthenticationAttributes_setsIdpIdToken() {
authManager.populateAuthenticationAttributes(authentication, oidcAuthentication, authenticationData);
assertEquals(idTokenJwt, authentication.getIdpIdToken());
}

@Test
public void getClaimsFromToken_setsIdToken() {
Map<String, Object> header = map(
entry(HeaderParameterNames.ALGORITHM, JWSAlgorithm.RS256.getName()),
entry(HeaderParameterNames.KEY_ID, OIDC_PROVIDER_KEY)
);
JWSSigner signer = new KeyInfo("uaa-key", oidcProviderTokenSigningKey, DEFAULT_UAA_URL).getSigner();
Map<String, Object> entryMap = map(
entry("external_map_name", Arrays.asList("bar", "baz"))
);
Map<String, Object> claims = map(
entry("external_family_name", entryMap),
entry(ISS, oidcConfig.getIssuer()),
entry(AUD, "uaa-relying-party"),
entry(EXPIRY_IN_SECONDS, ((int) (System.currentTimeMillis()/1000L)) + 60),
entry(SUB, "abc-def-asdf")
);
Map<String, Object> externalGroupMapping = map(
entry(FAMILY_NAME_ATTRIBUTE_NAME, "external_family_name")
);
String idTokenJwt = UaaTokenUtils.constructToken(header, claims, signer);
ExternalOAuthCodeToken codeToken = new ExternalOAuthCodeToken("thecode", origin, "http://google.com", null, "accesstoken", "signedrequest");

authManager = new ExternalOAuthAuthenticationManager(identityProviderProvisioning, new RestTemplate(), new RestTemplate(), tokenEndpointBuilder, new KeyInfoService(uaaIssuerBaseUrl), null) {
@Override
protected String getTokenFromCode(ExternalOAuthCodeToken codeToken, AbstractExternalOAuthIdentityProviderDefinition config) {
return idTokenJwt;
}
};

authManager.getClaimsFromToken(codeToken, oidcConfig);
assertEquals(idTokenJwt, codeToken.getIdToken());
}
}

0 comments on commit acae8b0

Please sign in to comment.