Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.Instant;
import java.util.*;

Expand Down Expand Up @@ -88,7 +89,13 @@ Instant getInstantFromSeconds(Map<String, JsonNode> tree, String claimName) {
"The claim '%s' value (%s) is out of the range representable as a NumericDate.",
claimName, node.asText()));
}
return Instant.ofEpochSecond(node.asLong());
try {
return Instant.ofEpochSecond(node.asLong());
} catch (DateTimeException e) {
throw new JWTDecodeException(String.format(
"The claim '%s' value (%s) is out of the range representable as a NumericDate.",
claimName, node.asText()), e);
}
}

String getString(Map<String, JsonNode> tree, String claimName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ public void shouldThrowOutOfRangeWhenNumericDateExceedsLong() {
deserializer.getInstantFromSeconds(tree, "key");
}

@Test
public void shouldThrowOutOfRangeWhenNumericDateExceedsInstantRange() {
exception.expect(JWTDecodeException.class);
exception.expectMessage(
"The claim 'key' value (9223372036854775807) is out of the range representable as a NumericDate.");

Map<String, JsonNode> tree = new HashMap<>();
tree.put("key", new LongNode(Long.MAX_VALUE));

deserializer.getInstantFromSeconds(tree, "key");
}

@Test
public void shouldGetNullStringWhenParsingNullNode() {
Map<String, JsonNode> tree = new HashMap<>();
Expand Down Expand Up @@ -299,4 +311,4 @@ public void shouldGetStringWhenParsingTextNode() {
assertThat(text, is("something here"));
}

}
}