Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Poole committed Mar 26, 2017
1 parent 4fb82ff commit a698173
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function JwtStrategy(options, verify) {
if (this._secretOrKeyProvider) {
throw new TypeError('JwtStrategy has been given both a secretOrKey and a secretOrKeyProvider');
}
this._secretOrKeyProvider = (token, done) => done(options.secretOrKey);
this._secretOrKeyProvider = function (token, done) {
done(options.secretOrKey)
};
}

if (!this._secretOrKeyProvider) {
Expand Down
7 changes: 5 additions & 2 deletions lib/verify_jwt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
var jwt = require('jsonwebtoken');

module.exports = function(token, secretOrKeyProvider, options, callback, verify = jwt.verify) {
return secretOrKeyProvider(token, (err, secretOrKey) => {
module.exports = function(token, secretOrKeyProvider, options, callback, verify) {
if (!verify) {
verify = jwt.verify;
}
return secretOrKeyProvider(token, function (err, secretOrKey) {
if (err) {
callback(err);
return;
Expand Down
14 changes: 9 additions & 5 deletions test/strategy-verify-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,22 @@ describe('Strategy', function() {

});

describe('verify function', () => {
it('should call the secretOrKeyProvider with the token and pass it to verify', () => {
const provider = sinon.spy((token, done) => done(null, 'secret'));
describe('verify function', function() {
it('should call the secretOrKeyProvider with the token and pass it to verify', function() {
const provider = sinon.spy(function(token, done) {
done(null, 'secret');
});
const verifyStub = sinon.stub();
verify(test_data.valid_jwt.payload, provider, null, null, verifyStub);
expect(provider.calledOnce).to.be.true;
expect(provider.calledWith(test_data.valid_jwt.payload)).to.be.true;
expect(verifyStub.calledWith(test_data.valid_jwt.payload, 'secret')).to.be.true;
});

it('should call the callback with an error if the secretOrKeyProvider fails to return a key', () => {
const providerStub = (token, done) => done(new Error('invalid key'));
it('should call the callback with an error if the secretOrKeyProvider fails to return a key', function() {
const providerStub = function(token, done) {
done(new Error('invalid key'));
};
const callback = sinon.spy();
verify(test_data.valid_jwt.payload, providerStub, null, callback);
expect(callback.calledWith(sinon.match.instanceOf(Error)));
Expand Down

0 comments on commit a698173

Please sign in to comment.