Skip to content
Open
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
41 changes: 41 additions & 0 deletions test/option-nonce-supported.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const jwt = require('../');
const expect = require('chai').expect;
const testUtils = require('./test-utils')

describe('nonce and nonce_supported option', function () {

[
{
description: 'should succeed without nonce and without nonce support',
signParam: { nonce_supported: false },
verifyParam: { },
},
{
description: 'should succeed without nonce but with nonce support',
signParam: { nonce_supported: true },
verifyParam: { },
},
{
description: 'should succeed with nonce but without nonce support',
signParam: { nonce_supported: false },
verifyParam: { nonce: 'abcde' },
},
{
description: 'should succeed with nonce and nonce support',
signParam: { nonce: 'abcde', nonce_supported: true },
verifyParam: { nonce: 'abcde' },
},
].forEach((testCase) => {
it(testCase.description, function (done) {
var token = jwt.sign(testCase.signParam, undefined, { algorithm: 'none' });
testUtils.verifyJWTHelper(token, undefined, testCase.verifyParam, (err) => {
testUtils.asyncCheck(done, () => {
expect(err).to.be.null;
});
});
});
});

});
2 changes: 1 addition & 1 deletion verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module.exports = function (jwtString, secretOrPublicKey, options, callback) {
}

if (options.nonce) {
if (payload.nonce !== options.nonce) {
if (payload.nonce !== options.nonce && payload.nonce_supported !== false) {
return done(new JsonWebTokenError('jwt nonce invalid. expected: ' + options.nonce));
}
}
Expand Down