Skip to content

Commit c584d1c

Browse files
committed
sign: add check to be sure secret has a value
1 parent 43739dc commit c584d1c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: sign.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ module.exports = function (payload, secretOrPrivateKey, options, callback) {
6666
throw err;
6767
}
6868

69+
if (!secretOrPrivateKey) {
70+
return failure(new Error('secretOrPrivateKey must have a value'));
71+
}
6972

7073
if (typeof payload === 'undefined') {
7174
return failure(new Error('payload is required'));

Diff for: test/async_sign.tests.js

+14
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,19 @@ describe('signing a token asynchronously', function() {
6363
done();
6464
});
6565
});
66+
67+
describe('secret must have a value', function(){
68+
[undefined, '', 0].forEach(function(secret){
69+
it('should return an error if the secret is falsy: ' + (typeof secret === 'string' ? '(empty string)' : secret), function(done) {
70+
// This is needed since jws will not answer for falsy secrets
71+
jwt.sign('string', secret, {}, function(err, token) {
72+
expect(err).to.be.exist();
73+
expect(err.message).to.equal('secretOrPrivateKey must have a value');
74+
expect(token).to.not.exist;
75+
done();
76+
});
77+
});
78+
});
79+
});
6680
});
6781
});

0 commit comments

Comments
 (0)