|
15 | 15 | import java.security.interfaces.RSAPrivateKey; |
16 | 16 | import java.util.*; |
17 | 17 |
|
| 18 | +import static org.hamcrest.Matchers.anEmptyMap; |
18 | 19 | import static org.hamcrest.Matchers.is; |
19 | 20 | import static org.hamcrest.Matchers.notNullValue; |
20 | 21 | import static org.junit.Assert.assertThat; |
@@ -574,6 +575,40 @@ public void shouldAcceptCustomClaimForNullListItem() throws Exception { |
574 | 575 | .sign(Algorithm.HMAC256("secret")); |
575 | 576 | } |
576 | 577 |
|
| 578 | + @Test |
| 579 | + @SuppressWarnings("unchecked") |
| 580 | + public void shouldAcceptCustomClaimWithNullMapAndRemoveClaim() throws Exception { |
| 581 | + String jwt = JWTCreator.init() |
| 582 | + .withClaim("map", "stubValue") |
| 583 | + .withClaim("map", (Map<String, ?>) null) |
| 584 | + .sign(Algorithm.HMAC256("secret")); |
| 585 | + |
| 586 | + assertThat(jwt, is(notNullValue())); |
| 587 | + String[] parts = jwt.split("\\."); |
| 588 | + |
| 589 | + String body = new String(Base64.decodeBase64(parts[1]), StandardCharsets.UTF_8); |
| 590 | + ObjectMapper mapper = new ObjectMapper(); |
| 591 | + Map<String, Object> map = (Map<String, Object>) mapper.readValue(body, Map.class); |
| 592 | + assertThat(map, anEmptyMap()); |
| 593 | + } |
| 594 | + |
| 595 | + @Test |
| 596 | + @SuppressWarnings("unchecked") |
| 597 | + public void shouldAcceptCustomClaimWithNullListAndRemoveClaim() throws Exception { |
| 598 | + String jwt = JWTCreator.init() |
| 599 | + .withClaim("list", "stubValue") |
| 600 | + .withClaim("list", (List<String>) null) |
| 601 | + .sign(Algorithm.HMAC256("secret")); |
| 602 | + |
| 603 | + assertThat(jwt, is(notNullValue())); |
| 604 | + String[] parts = jwt.split("\\."); |
| 605 | + |
| 606 | + String body = new String(Base64.decodeBase64(parts[1]), StandardCharsets.UTF_8); |
| 607 | + ObjectMapper mapper = new ObjectMapper(); |
| 608 | + Map<String, Object> map = (Map<String, Object>) mapper.readValue(body, Map.class); |
| 609 | + assertThat(map, anEmptyMap()); |
| 610 | + } |
| 611 | + |
577 | 612 | @Test |
578 | 613 | public void shouldRefuseCustomClaimForNullMapValue() throws Exception { |
579 | 614 | Map<String, Object> data = new HashMap<>(); |
|
0 commit comments