diff options
author | 2023-10-14 12:58:30 -0700 | |
---|---|---|
committer | 2023-10-14 12:58:30 -0700 | |
commit | f9add8b6bea4df3cdbd56a21f17e4cab1a854e4e (patch) | |
tree | 8e5306104d81c67b771181337bba02cd9ec39453 /test/js/third_party/jsonwebtoken/option-nonce.test.js | |
parent | 81a1a58d66c598ea35c42453d0ba4c6341a940fc (diff) | |
parent | 9b5e66453b0879ed77b71dcdbe50e4efa184261e (diff) | |
download | bun-sdl.tar.gz bun-sdl.tar.zst bun-sdl.zip |
Merge branch 'main' into sdlsdl
Diffstat (limited to 'test/js/third_party/jsonwebtoken/option-nonce.test.js')
-rw-r--r-- | test/js/third_party/jsonwebtoken/option-nonce.test.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/js/third_party/jsonwebtoken/option-nonce.test.js b/test/js/third_party/jsonwebtoken/option-nonce.test.js new file mode 100644 index 000000000..abe918d42 --- /dev/null +++ b/test/js/third_party/jsonwebtoken/option-nonce.test.js @@ -0,0 +1,41 @@ +"use strict"; + +import jwt from "jsonwebtoken"; +import { expect, describe, it, beforeEach } from "bun:test"; +import util from "util"; +import testUtils from "./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).toBeNull(); + expect(decoded).toHaveProperty("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).toBeInstanceOf(jwt.JsonWebTokenError); + expect(err).toHaveProperty("message", "nonce must be a non-empty string"); + }); + }); + }); + }, + ); +}); |