|
21 | 21 | import java.util.Collections;
|
22 | 22 |
|
23 | 23 | import org.junit.jupiter.api.Test;
|
| 24 | +import org.junit.jupiter.params.ParameterizedTest; |
| 25 | +import org.junit.jupiter.params.provider.NullSource; |
| 26 | +import org.junit.jupiter.params.provider.ValueSource; |
24 | 27 |
|
25 | 28 | import org.springframework.security.core.GrantedAuthority;
|
26 | 29 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
27 | 30 | import org.springframework.security.oauth2.jwt.Jwt;
|
28 | 31 | import org.springframework.security.oauth2.jwt.TestJwts;
|
| 32 | +import org.springframework.test.util.ReflectionTestUtils; |
29 | 33 |
|
30 | 34 | import static org.assertj.core.api.Assertions.assertThat;
|
31 | 35 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
@@ -270,4 +274,21 @@ public void convertWithCustomAuthoritiesSplitRegexWhenTokenHasScopeAttributeThen
|
270 | 274 | new SimpleGrantedAuthority("SCOPE_message:write"));
|
271 | 275 | }
|
272 | 276 |
|
| 277 | + @ParameterizedTest |
| 278 | + @ValueSource(strings = { "", " " }) |
| 279 | + @NullSource |
| 280 | + public void convertWhenAuthoritiesClaimNameIsBlankThenUsesWellKnownClaims(String invalidClaimName) |
| 281 | + throws Exception { |
| 282 | + // @formatter:off |
| 283 | + Jwt jwt = TestJwts.jwt() |
| 284 | + .claim("scope", "message:read message:write") |
| 285 | + .build(); |
| 286 | + // @formatter:on |
| 287 | + JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter(); |
| 288 | + ReflectionTestUtils.setField(jwtGrantedAuthoritiesConverter, "authoritiesClaimName", invalidClaimName); |
| 289 | + Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt); |
| 290 | + assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"), |
| 291 | + new SimpleGrantedAuthority("SCOPE_message:write")); |
| 292 | + } |
| 293 | + |
273 | 294 | }
|
0 commit comments