@Test public void setClaimSetConverterWhenIsNullThenThrowsIllegalArgumentException() { assertThatCode(() -> jwtDecoder.setClaimSetConverter(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void decodeWhenUsingSignedJwtThenReturnsClaimsGivenByClaimSetConverter() throws Exception { try ( MockWebServer server = new MockWebServer() ) { server.enqueue(new MockResponse().setBody(JWK_SET)); String jwkSetUrl = server.url("/.well-known/jwks.json").toString(); NimbusJwtDecoderJwkSupport decoder = new NimbusJwtDecoderJwkSupport(jwkSetUrl); Converter<Map<String, Object>, Map<String, Object>> claimSetConverter = mock(Converter.class); when(claimSetConverter.convert(any(Map.class))).thenReturn(Collections.singletonMap("custom", "value")); decoder.setClaimSetConverter(claimSetConverter); Jwt jwt = decoder.decode(SIGNED_JWT); assertThat(jwt.getClaims().size()).isEqualTo(1); assertThat(jwt.getClaims().get("custom")).isEqualTo("value"); } }
@Test public void decodeWhenExpClaimNullThenDoesNotThrowException() throws Exception { NimbusJwtDecoderJwkSupport jwtDecoder = new NimbusJwtDecoderJwkSupport(JWK_SET_URL); jwtDecoder.setRestOperations(mockJwkSetResponse(JWK_SET)); jwtDecoder.setClaimSetConverter(map -> { Map<String, Object> claims = new HashMap<>(map); claims.remove(JwtClaimNames.EXP); return claims; }); assertThatCode(() -> jwtDecoder.decode(SIGNED_JWT)).doesNotThrowAnyException(); }