-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ | |
@TestPropertySource(properties = { | ||
// @formatter:off | ||
"iam.jwt-profile.default-profile=wlcg", | ||
"iam.access_token.include_authn_info=true", | ||
"scope.matchers[0].name=storage.read", | ||
"scope.matchers[0].type=path", | ||
"scope.matchers[0].prefix=storage.read", | ||
|
@@ -736,7 +737,7 @@ public void attributesAreNotIncludedInAccessTokenWhenNotRequested() throws Excep | |
} | ||
|
||
@Test | ||
public void attributesAreIncludedInAccessTokenWhenNotRequested() throws Exception { | ||
public void attributesAreIncludedInAccessTokenWhenRequested() throws Exception { | ||
IamAccount testAccount = | ||
repo.findByUsername(TEST_USER).orElseThrow(assertionError(EXPECTED_USER_NOT_FOUND)); | ||
|
||
|
@@ -762,4 +763,55 @@ public void attributesAreIncludedInAccessTokenWhenNotRequested() throws Exceptio | |
assertThat(claims.getJSONObjectClaim("attr").get("test"), is("test")); | ||
} | ||
|
||
@Test | ||
public void additionalClaimsAreIncludedInAccessTokenWhenRequested() throws Exception { | ||
|
||
String tokenResponseJson = mvc | ||
.perform(post("/token").param("grant_type", "password") | ||
.param("client_id", CLIENT_ID) | ||
.param("client_secret", CLIENT_SECRET) | ||
.param("username", "test") | ||
.param("password", "password") | ||
.param("scope", "openid profile email")) | ||
.andExpect(status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
JWTClaimsSet claims = | ||
JWTParser.parse(mapper.readTree(tokenResponseJson).get("access_token").asText()) | ||
.getJWTClaimsSet(); | ||
|
||
assertThat(claims.getClaim("email"), notNullValue()); | ||
assertThat(claims.getClaim("email"), is("[email protected]")); | ||
assertThat(claims.getClaim("name"), notNullValue()); | ||
assertThat(claims.getClaim("name"), is("Test User")); | ||
assertThat(claims.getClaim("preferred_username"), notNullValue()); | ||
assertThat(claims.getClaim("preferred_username"), is("test")); | ||
} | ||
|
||
@Test | ||
public void additionalClaimsAreNotIncludedInAccessTokenWhenRNotequested() throws Exception { | ||
|
||
String tokenResponseJson = mvc | ||
.perform(post("/token").param("grant_type", "password") | ||
.param("client_id", CLIENT_ID) | ||
.param("client_secret", CLIENT_SECRET) | ||
.param("username", "test") | ||
.param("password", "password") | ||
.param("scope", "openid address")) | ||
.andExpect(status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
JWTClaimsSet claims = | ||
JWTParser.parse(mapper.readTree(tokenResponseJson).get("access_token").asText()) | ||
.getJWTClaimsSet(); | ||
|
||
assertThat(claims.getClaim("email"), nullValue()); | ||
assertThat(claims.getClaim("name"), nullValue()); | ||
assertThat(claims.getClaim("preferred_username"), nullValue()); | ||
} | ||
|
||
} |