Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw JWTDecodeException when date claim format is invalid #241

Merged
merged 2 commits into from
Jun 4, 2018

Conversation

lbalmaceda
Copy link
Contributor

WDYT about the exception message?

Fixes #240

return null;
}
if (!node.canConvertToLong()) {
throw new JWTDecodeException(String.format("The claim '%s' contained an unexpected value.", claimName));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe better non-numeric

Copy link

@uwinkelvos uwinkelvos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just did pretty much exactly the same thing, until i saw you alread fixed it. Looks good to me, apart from that comment regarding the ex message.

Map<String, JsonNode> tree = new HashMap<>();
TextNode node = new TextNode("123456789");
tree.put("key", node);

Date date = deserializer.getDateFromSeconds(tree, "key");
assertThat(date, is(nullValue()));
deserializer.getDateFromSeconds(tree, "key");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no assertions as now caught by the exception.expect? if getDateFromSeconds explodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. Because the ExpectedException is "none" for every method but for those in which we override it, when we run tests they expect (or don't) to fail with X exception and Y message.

@@ -65,9 +65,12 @@ public Payload deserialize(JsonParser p, DeserializationContext ctxt) throws IOE

Date getDateFromSeconds(Map<String, JsonNode> tree, String claimName) {
JsonNode node = tree.get(claimName);
if (node == null || node.isNull() || !node.canConvertToLong()) {
if (node == null || node.isNull()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So non Java person here, what is the difference here in checking for null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node is the instance of the JsonNode we're checking. The check is asserting that the instance of this object is null OR that the parsed JSON value is null. This second check wouldn't be possible if the instance is null as that would throw a NPE when calling some method on it.

@lbalmaceda lbalmaceda added this to the v3-Next milestone Jun 4, 2018
@lbalmaceda lbalmaceda merged commit c8f23a1 into master Jun 4, 2018
@lbalmaceda lbalmaceda deleted the throw-date branch June 4, 2018 16:48
@lbalmaceda lbalmaceda modified the milestones: v3-Next, 3.4.0 Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants