From a4d9709d7c8d88c87b28f510d4aa04fb7f3836f0 Mon Sep 17 00:00:00 2001 From: Juerg Wullschleger Date: Wed, 14 Sep 2022 11:17:38 -0700 Subject: [PATCH] Add test with JWT payload with two identical claim names. Also, fix the name of one of the tests. PiperOrigin-RevId: 474342738 Change-Id: I7c0641fcb4cb07bb49e8a21b6dfc9fd141219882 --- .../java/com/google/crypto/tink/jwt/RawJwtTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/google/crypto/tink/jwt/RawJwtTest.java b/src/test/java/com/google/crypto/tink/jwt/RawJwtTest.java index a925a0685..40b7033be 100644 --- a/src/test/java/com/google/crypto/tink/jwt/RawJwtTest.java +++ b/src/test/java/com/google/crypto/tink/jwt/RawJwtTest.java @@ -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"); @@ -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\"}";