Improve test coverage of JwtGrantedAuthoritiesConverter
Some negative test cases were missing. Added these to have full test coverage for JwtGrantedAuthoritiesConverter.
This commit is contained in:
parent
0a058c973a
commit
766c4434d4
|
@ -139,6 +139,43 @@ public class JwtGrantedAuthoritiesConverterTests {
|
||||||
assertThat(authorities).isEmpty();
|
assertThat(authorities).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertWhenTokenHasEmptyScopeAndEmptyScpAttributeThenTranslatesToNoAuthorities() {
|
||||||
|
Map<String, Object> claims = new HashMap<>();
|
||||||
|
claims.put("scp", Collections.emptyList());
|
||||||
|
claims.put("scope", Collections.emptyList());
|
||||||
|
Jwt jwt = this.jwt(claims);
|
||||||
|
|
||||||
|
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
|
||||||
|
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
|
||||||
|
|
||||||
|
assertThat(authorities).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertWhenTokenHasNoScopeAndNoScpAttributeThenTranslatesToNoAuthorities() {
|
||||||
|
Map<String, Object> claims = new HashMap<>();
|
||||||
|
claims.put("roles", Arrays.asList("message:read", "message:write"));
|
||||||
|
Jwt jwt = this.jwt(claims);
|
||||||
|
|
||||||
|
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
|
||||||
|
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
|
||||||
|
|
||||||
|
assertThat(authorities).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertWhenTokenHasUnsupportedTypeForScopeThenTranslatesToNoAuthorities() {
|
||||||
|
Map<String, Object> claims = new HashMap<>();
|
||||||
|
claims.put("scope", new String[] {"message:read", "message:write"});
|
||||||
|
Jwt jwt = this.jwt(claims);
|
||||||
|
|
||||||
|
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
|
||||||
|
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
|
||||||
|
|
||||||
|
assertThat(authorities).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertWhenTokenHasCustomClaimNameThenCustomClaimNameAttributeIsTranslatedToAuthorities() {
|
public void convertWhenTokenHasCustomClaimNameThenCustomClaimNameAttributeIsTranslatedToAuthorities() {
|
||||||
Map<String, Object> claims = new HashMap<>();
|
Map<String, Object> claims = new HashMap<>();
|
||||||
|
|
Loading…
Reference in New Issue