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

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

Merged
merged 2 commits into from
Oct 22, 2018

Conversation

andrewnester
Copy link
Contributor

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

@andrewnester
Copy link
Contributor Author

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

@MitMaro
Copy link
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
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
Contributor Author

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

Copy link
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. :)

it(`should error with with value ''`, function (done) {
signWithExpiresIn('', {}, (err) => {
testUtils.asyncCheck(done, () => {
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
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.

@@ -51,7 +51,8 @@ describe('not before', function() {
signWithNotBefore('', {}, (err) => {
testUtils.asyncCheck(done, () => {
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
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
Contributor Author

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

@andrewnester
Copy link
Contributor Author

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

@ziluvatar
Copy link
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