Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
return done(new JsonWebTokenError('jwt signature is required'));
}

if (!secretOrPublicKey) {
return done(new JsonWebTokenError('secret or public key must be provided'));
}

if (!options.algorithms) {
options.algorithms = ~secretOrPublicKey.toString().indexOf('BEGIN CERTIFICATE') ||
~secretOrPublicKey.toString().indexOf('BEGIN PUBLIC KEY') ?
Expand Down
20 changes: 20 additions & 0 deletions test/undefined_secretOrPublickey.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var fs = require('fs');
var jwt = require('../index');
var JsonWebTokenError = require('../lib/JsonWebTokenError');
var expect = require('chai').expect;

var TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M';

describe('verifying without specified secret or public key', function () {
it('should not verify null', function () {
expect(function () {
jwt.verify(TOKEN, null);
}).to.throw(JsonWebTokenError, /secret or public key must be provided/);
});

it('should not verify undefined', function () {
expect(function () {
jwt.verify(TOKEN);
}).to.throw(JsonWebTokenError, /secret or public key must be provided/);
});
});