mirror of
https://github.com/hanzoai/node-jsonwebtoken.git
synced 2026-09-24 17:00:48 +00:00
* fix(sign&verify)!: Remove default none support from sign and verify methods, and require it to be explicitly configured BREAKING CHANGE: Removes fallback for none algorithm for the verify method.
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const jwt = require('../');
|
|
const expect = require('chai').expect;
|
|
const util = require('util');
|
|
const testUtils = require('./test-utils')
|
|
|
|
describe('nonce option', function () {
|
|
let token;
|
|
|
|
beforeEach(function () {
|
|
token = jwt.sign({ nonce: 'abcde' }, 'secret', { algorithm: 'HS256' });
|
|
});
|
|
[
|
|
{
|
|
description: 'should work with a string',
|
|
nonce: 'abcde',
|
|
},
|
|
].forEach((testCase) => {
|
|
it(testCase.description, function (done) {
|
|
testUtils.verifyJWTHelper(token, 'secret', { nonce: testCase.nonce }, (err, decoded) => {
|
|
testUtils.asyncCheck(done, () => {
|
|
expect(err).to.be.null;
|
|
expect(decoded).to.have.property('nonce', 'abcde');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
[
|
|
true,
|
|
false,
|
|
null,
|
|
-1,
|
|
0,
|
|
1,
|
|
-1.1,
|
|
1.1,
|
|
-Infinity,
|
|
Infinity,
|
|
NaN,
|
|
'',
|
|
' ',
|
|
[],
|
|
['foo'],
|
|
{},
|
|
{ foo: 'bar' },
|
|
].forEach((nonce) => {
|
|
it(`should error with value ${util.inspect(nonce)}`, function (done) {
|
|
testUtils.verifyJWTHelper(token, 'secret', { nonce }, (err) => {
|
|
testUtils.asyncCheck(done, () => {
|
|
expect(err).to.be.instanceOf(jwt.JsonWebTokenError);
|
|
expect(err).to.have.property('message', 'nonce must be a non-empty string')
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|