-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@MitMaro @ziluvatar may I ask you to review this change? Thanks! :) |
I wonder if the error message should be normalized or if this validation should be moved into the |
Good one @MitMaro , yes, probably it is better to update the schema, so if it is an string it has to have some value. |
f05328f
to
8db0267
Compare
@MitMaro @ziluvatar thanks for comments! I moved validation to |
There was a problem hiding this 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. :)
test/claim-exp.test.js
Outdated
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/); |
There was a problem hiding this comment.
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.
test/claim-nbf.test.js
Outdated
@@ -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/); |
There was a problem hiding this comment.
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.
@MitMaro indeed, good point, thanks for the comments! Updated in latest commit. |
@ziluvatar sorry for bothering again, any other comments on this PR? :) |
@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. |
This PR fixes TODO items to change error message when empty string passed as
expiresIn
ornotBefore
options