Skip to content

Fixed error message when empty string passed as expiresIn or notBefore option#531

Merged
ziluvatar merged 2 commits intoauth0:masterfrom
andrewnester:update-tests
Oct 22, 2018
Merged

Fixed error message when empty string passed as expiresIn or notBefore option#531
ziluvatar merged 2 commits intoauth0:masterfrom
andrewnester:update-tests

Conversation

@andrewnester
Copy link
Copy Markdown
Contributor

This PR fixes TODO items to change error message when empty string passed as expiresIn or notBefore options

@andrewnester
Copy link
Copy Markdown
Contributor Author

@MitMaro @ziluvatar may I ask you to review this change? Thanks! :)

@MitMaro
Copy link
Copy Markdown
Contributor

MitMaro commented Oct 16, 2018

I wonder if the error message should be normalized or if this validation should be moved into the sign_options_schema block. But that's a decision for @ziluvatar, not I.

@ziluvatar
Copy link
Copy Markdown
Contributor

Good one @MitMaro , yes, probably it is better to update the schema, so if it is an string it has to have some value.
https://github.com/auth0/node-jsonwebtoken/blob/master/sign.js#L12-L13

@andrewnester
Copy link
Copy Markdown
Contributor Author

@MitMaro @ziluvatar thanks for comments! I moved validation to sign_options_schema

Copy link
Copy Markdown
Contributor

@MitMaro MitMaro left a comment

Choose a reason for hiding this comment

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

Awesome work!

Left two minor comment on cleaning up the tests a bit. :)

expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', 'val is not a non-empty string or a valid number. val=""');
expect(err).to.have.property('message')
.match(/"expiresIn" should be a number of seconds or string representing a timespan/);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should be able to move this test above into the array in jwt.sign "expiresIn" option validation block.

expect(err).to.be.instanceOf(Error);
expect(err).to.have.property('message', 'val is not a non-empty string or a valid number. val=""');
expect(err).to.have.property('message')
.match(/"notBefore" should be a number of seconds or string representing a timespan/);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto to above, you should be able to move this test above into the array in jwt.sign "expiresIn" option validation block.

@andrewnester
Copy link
Copy Markdown
Contributor Author

@MitMaro indeed, good point, thanks for the comments! Updated in latest commit.

@andrewnester
Copy link
Copy Markdown
Contributor Author

@ziluvatar sorry for bothering again, any other comments on this PR? :)

@ziluvatar
Copy link
Copy Markdown
Contributor

@andrewnester nothing to sorry about, thanks for the interest! I will merge this one since we were returning an error anyway, however, in this case it will return a better known descriptive error.

@ziluvatar ziluvatar merged commit 7f9604a into auth0:master Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants