MCPcopy
hub / github.com/auth0/node-jsonwebtoken / verifyJWTHelper

Function verifyJWTHelper

test/test-utils.js:59–87  ·  view source on GitHub ↗

* Verify a JWT, ensuring that the asynchronous and synchronous calls to `verify` have the same result * @param {string} jwtString The JWT as a string * @param {string} secretOrPrivateKey The shared secret or private key * @param {object} options Verify options * @param {function(err, token):void

(jwtString, secretOrPrivateKey, options, callback)

Source from the content-addressed store, hash-verified

57 * @param {function(err, token):void} callback
58 */
59function verifyJWTHelper(jwtString, secretOrPrivateKey, options, callback) {
60 // freeze the time to ensure the clock remains stable across the async and sync calls
61 const fakeClock = sinon.useFakeTimers({now: Date.now()});
62 let error;
63 let syncVerified;
64 try {
65 syncVerified = jwt.verify(jwtString, secretOrPrivateKey, options);
66 }
67 catch (err) {
68 error = err;
69 }
70 jwt.verify(jwtString, secretOrPrivateKey, options, (err, asyncVerifiedToken) => {
71 try {
72 if (error) {
73 expectEqualError(err, error);
74 callback(err);
75 }
76 else {
77 expect(syncVerified, 'Async/Sync token equality').to.deep.equal(asyncVerifiedToken);
78 callback(null, syncVerified);
79 }
80 }
81 finally {
82 if (fakeClock) {
83 fakeClock.restore();
84 }
85 }
86 });
87}
88
89/**
90 * Sign a payload to create a JWT, ensuring that the asynchronous and synchronous calls to `sign` have the same result

Callers

nothing calls this directly

Calls 2

expectEqualErrorFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected