Skip to content

Commit 6825cd3

Browse files
committed
Tests for Long type updated.
1 parent d27b121 commit 6825cd3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

lib/src/main/java/com/auth0/jwt/JWTVerifier.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ public Verification withClaim(String name, Integer value) throws IllegalArgument
197197
return this;
198198
}
199199

200+
/**
201+
* Require a specific Claim value.
202+
*
203+
* @param name the Claim's name.
204+
* @param value the Claim's value.
205+
* @return this same Verification instance.
206+
* @throws IllegalArgumentException if the name is null.
207+
*/
208+
@Override
209+
public Verification withClaim(String name, Long value) throws IllegalArgumentException {
210+
assertNonNull(name);
211+
requireClaim(name, value);
212+
return this;
213+
}
214+
200215
/**
201216
* Require a specific Claim value.
202217
*

lib/src/main/java/com/auth0/jwt/interfaces/Verification.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public interface Verification {
2525

2626
Verification withClaim(String name, Integer value) throws IllegalArgumentException;
2727

28+
Verification withClaim(String name, Long value) throws IllegalArgumentException;
29+
2830
Verification withClaim(String name, Double value) throws IllegalArgumentException;
2931

3032
Verification withClaim(String name, String value) throws IllegalArgumentException;

lib/src/test/java/com/auth0/jwt/JWTVerifierTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ public void shouldValidateCustomClaimOfTypeInteger() throws Exception {
222222
assertThat(jwt, is(notNullValue()));
223223
}
224224

225+
@Test
226+
public void shouldValidateCustomClaimOfTypeLong() throws Exception {
227+
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjo5MjIzMzcyMDM2ODU0Nzc2MDB9.km-IwQ5IDnTZFmuJzhSgvjTzGkn_Z5X29g4nAuVC56I";
228+
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
229+
.withClaim("name", 922337203685477600L)
230+
.build()
231+
.verify(token);
232+
233+
assertThat(jwt, is(notNullValue()));
234+
}
235+
225236
@Test
226237
public void shouldValidateCustomClaimOfTypeDouble() throws Exception {
227238
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoyMy40NX0.7pyX2OmEGaU9q15T8bGFqRm-d3RVTYnqmZNZtxMKSlA";

lib/src/test/java/com/auth0/jwt/impl/NullClaimTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public void shouldGetAsInt() throws Exception {
3131
assertThat(claim.asInt(), is(nullValue()));
3232
}
3333

34+
@Test
35+
public void shouldGetAsLong() throws Exception {
36+
assertThat(claim.asLong(), is(nullValue()));
37+
}
38+
3439
@Test
3540
public void shouldGetAsDouble() throws Exception {
3641
assertThat(claim.asDouble(), is(nullValue()));

0 commit comments

Comments
 (0)