Skip to content

Commit e0038a3

Browse files
committed
Merge branch 'JackuB-empty_secretOrPublicKey'
2 parents 815a1a1 + cfe05e9 commit e0038a3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ JWT.verify = function(jwtString, secretOrPublicKey, options, callback) {
122122
return done(new JsonWebTokenError('jwt signature is required'));
123123
}
124124

125+
if (!secretOrPublicKey) {
126+
return done(new JsonWebTokenError('secret or public key must be provided'));
127+
}
128+
125129
if (!options.algorithms) {
126130
options.algorithms = ~secretOrPublicKey.toString().indexOf('BEGIN CERTIFICATE') ||
127131
~secretOrPublicKey.toString().indexOf('BEGIN PUBLIC KEY') ?
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var fs = require('fs');
2+
var jwt = require('../index');
3+
var JsonWebTokenError = require('../lib/JsonWebTokenError');
4+
var expect = require('chai').expect;
5+
6+
var TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M';
7+
8+
describe('verifying without specified secret or public key', function () {
9+
it('should not verify null', function () {
10+
expect(function () {
11+
jwt.verify(TOKEN, null);
12+
}).to.throw(JsonWebTokenError, /secret or public key must be provided/);
13+
});
14+
15+
it('should not verify undefined', function () {
16+
expect(function () {
17+
jwt.verify(TOKEN);
18+
}).to.throw(JsonWebTokenError, /secret or public key must be provided/);
19+
});
20+
});

0 commit comments

Comments
 (0)