Skip to content

Commit 8db0267

Browse files
committed
Fixed error message when empty string passed as expiresIn or notBefore option
1 parent 88bc965 commit 8db0267

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Diff for: sign.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var isString = require('lodash.isstring');
99
var once = require('lodash.once');
1010

1111
var sign_options_schema = {
12-
expiresIn: { isValid: function(value) { return isInteger(value) || isString(value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
13-
notBefore: { isValid: function(value) { return isInteger(value) || isString(value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' },
12+
expiresIn: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
13+
notBefore: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' },
1414
audience: { isValid: function(value) { return isString(value) || Array.isArray(value); }, message: '"audience" must be a string or array' },
1515
algorithm: { isValid: includes.bind(null, ['RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'none']), message: '"algorithm" must be a valid string enum value' },
1616
header: { isValid: isPlainObject, message: '"header" must be an object' },

Diff for: test/claim-exp.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ describe('expires', function() {
4646
});
4747
});
4848

49-
// TODO this should throw the same error as other invalid inputs
5049
it(`should error with with value ''`, function (done) {
5150
signWithExpiresIn('', {}, (err) => {
5251
testUtils.asyncCheck(done, () => {
5352
expect(err).to.be.instanceOf(Error);
54-
expect(err).to.have.property('message', 'val is not a non-empty string or a valid number. val=""');
53+
expect(err).to.have.property('message')
54+
.match(/"expiresIn" should be a number of seconds or string representing a timespan/);
5555
});
5656
});
5757
});

Diff for: test/claim-nbf.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('not before', function() {
5151
signWithNotBefore('', {}, (err) => {
5252
testUtils.asyncCheck(done, () => {
5353
expect(err).to.be.instanceOf(Error);
54-
expect(err).to.have.property('message', 'val is not a non-empty string or a valid number. val=""');
54+
expect(err).to.have.property('message')
55+
.match(/"notBefore" should be a number of seconds or string representing a timespan/);
5556
});
5657
});
5758
});

0 commit comments

Comments
 (0)