Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmiccoli committed Sep 14, 2023
1 parent 79d0353 commit d7d6041
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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));

Expand All @@ -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());
}

}

0 comments on commit d7d6041

Please sign in to comment.