Skip to content

Commit

Permalink
Add test with JWT payload with two identical claim names.
Browse files Browse the repository at this point in the history
Also, fix the name of one of the tests.

PiperOrigin-RevId: 474342738
Change-Id: I7c0641fcb4cb07bb49e8a21b6dfc9fd141219882
  • Loading branch information
juergw authored and copybara-github committed Sep 14, 2022
1 parent 83b667c commit a4d9709
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/test/java/com/google/crypto/tink/jwt/RawJwtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public void fromInvalidJsonPayload_shouldThrow() throws Exception {
}

@Test
public void fromJsonPayloadWithValidJsonEscapedCharacter_shouldThrow() throws Exception {
public void fromJsonPayloadWithValidJsonEscapedCharacter_success() throws Exception {
RawJwt token = RawJwt.fromJsonPayload(Optional.empty(), "{\"iss\":\"\\uD834\\uDD1E\"}");
assertThat(token.hasIssuer()).isTrue();
assertThat(token.getIssuer()).isEqualTo("\uD834\uDD1E");
Expand Down Expand Up @@ -646,6 +646,15 @@ public void fromJsonPayloadWithComments_shouldThrow () throws Exception {
assertThrows(JwtInvalidException.class, () -> RawJwt.fromJsonPayload(Optional.empty(), input));
}

@Test
public void fromJsonPayloadWithTwoIdenticalClaimNames_firstIsIgnored() throws Exception {
String input = "{\"claim\": \"claim1\", \"claim\": \"claim2\"}";
RawJwt token = RawJwt.fromJsonPayload(Optional.empty(), input);
assertThat(token.hasStringClaim("claim")).isTrue();
assertThat(token.getStringClaim("claim")).isEqualTo("claim2");
}


@Test
public void fromJsonPayloadWithEscapedChars_success() throws Exception {
String input = "{\"i\\u0073\\u0073\": \"\\u0061lice\"}";
Expand Down

0 comments on commit a4d9709

Please sign in to comment.