Skip to content

Commit 7f9604a

Browse files
andrewnesterziluvatar
authored andcommitted
Fixed error message when empty string passed as expiresIn or notBefore option (#531)
* Fixed error message when empty string passed as expiresIn or notBefore option * Moved tests to option validation block
1 parent cfd1079 commit 7f9604a

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

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' },

test/claim-exp.test.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('expires', function() {
2929
Infinity,
3030
NaN,
3131
' ',
32+
'',
3233
'invalid',
3334
[],
3435
['foo'],
@@ -46,16 +47,6 @@ describe('expires', function() {
4647
});
4748
});
4849

49-
// TODO this should throw the same error as other invalid inputs
50-
it(`should error with with value ''`, function (done) {
51-
signWithExpiresIn('', {}, (err) => {
52-
testUtils.asyncCheck(done, () => {
53-
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=""');
55-
});
56-
});
57-
});
58-
5950
// undefined needs special treatment because {} is not the same as {expiresIn: undefined}
6051
it('should error with with value undefined', function (done) {
6152
testUtils.signJWTHelper({}, undefined, {expiresIn: undefined, algorithm: 'none'}, (err) => {

test/claim-nbf.test.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('not before', function() {
2828
-Infinity,
2929
Infinity,
3030
NaN,
31+
'',
3132
' ',
3233
'invalid',
3334
[],
@@ -46,16 +47,6 @@ describe('not before', function() {
4647
});
4748
});
4849

49-
// TODO this should throw the same error as other invalid inputs
50-
it(`should error with with value ''`, function (done) {
51-
signWithNotBefore('', {}, (err) => {
52-
testUtils.asyncCheck(done, () => {
53-
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=""');
55-
});
56-
});
57-
});
58-
5950
// undefined needs special treatment because {} is not the same as {notBefore: undefined}
6051
it('should error with with value undefined', function (done) {
6152
testUtils.signJWTHelper({}, undefined, {notBefore: undefined, algorithm: 'none'}, (err) => {

0 commit comments

Comments
 (0)