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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var isString = require('lodash.isstring');
var once = require('lodash.once');

var sign_options_schema = {
expiresIn: { isValid: function(value) { return isInteger(value) || isString(value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
notBefore: { isValid: function(value) { return isInteger(value) || isString(value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' },
expiresIn: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
notBefore: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' },
audience: { isValid: function(value) { return isString(value) || Array.isArray(value); }, message: '"audience" must be a string or array' },
algorithm: { isValid: includes.bind(null, ['RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'none']), message: '"algorithm" must be a valid string enum value' },
header: { isValid: isPlainObject, message: '"header" must be an object' },
Expand Down
4 changes: 2 additions & 2 deletions test/claim-exp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ describe('expires', function() {
});
});

// TODO this should throw the same error as other invalid inputs
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.

});
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/claim-nbf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

});
});
});
Expand Down