aboutsummaryrefslogtreecommitdiff
path: root/test/js/third_party/jsonwebtoken/issue_304.test.js
blob: 257bcc09d9a52587302526434b5cacaa315ec4a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import jwt from "jsonwebtoken";
import { describe, it, expect } from "bun:test";

describe("issue 304 - verifying values other than strings", function () {
  it("should fail with numbers", function (done) {
    jwt.verify(123, "foo", function (err) {
      expect(err.name).toEqual("JsonWebTokenError");
      done();
    });
  });

  it("should fail with objects", function (done) {
    jwt.verify({ foo: "bar" }, "biz", function (err) {
      expect(err.name).toEqual("JsonWebTokenError");
      done();
    });
  });

  it("should fail with arrays", function (done) {
    jwt.verify(["foo"], "bar", function (err) {
      expect(err.name).toEqual("JsonWebTokenError");
      done();
    });
  });

  it("should fail with functions", function (done) {
    jwt.verify(
      function () {},
      "foo",
      function (err) {
        expect(err.name).toEqual("JsonWebTokenError");
        done();
      },
    );
  });

  it("should fail with booleans", function (done) {
    jwt.verify(true, "foo", function (err) {
      expect(err.name).toEqual("JsonWebTokenError");
      done();
    });
  });
});