mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
* Move ReadFile and WriteFile to separate file * Use libuv for Bun.write() * Update windows_event_loop.zig * build * Get bun-write tests to pass. Implement Bun.write with two files. * UPdate * Update * Update failing test list * update * More * More * More * More * Mark the rest * ok * oops * Update bun-write.test.js * Update blob.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dave Caruso <me@paperdave.net> Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com>
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
var PS_SUPPORTED = true;
|
|
import jwt from "jsonwebtoken";
|
|
import { expect, describe, it } from "bun:test";
|
|
import path from "path";
|
|
import fs from "fs";
|
|
|
|
var pub = fs.readFileSync(path.join(__dirname, "pub.pem"), "utf8");
|
|
// priv is never used
|
|
// var priv = fs.readFileSync(path.join(__dirname, 'priv.pem'));
|
|
|
|
var TOKEN =
|
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MjY1NDY5MTl9.ETgkTn8BaxIX4YqvUWVFPmum3moNZ7oARZtSBXb_vP4";
|
|
|
|
describe("when setting a wrong `header.alg`", function () {
|
|
describe("signing with pub key as symmetric", function () {
|
|
it("should not verify", function () {
|
|
expect(function () {
|
|
jwt.verify(TOKEN, pub);
|
|
}).toThrow(/invalid algorithm/);
|
|
});
|
|
});
|
|
|
|
describe("signing with pub key as HS256 and whitelisting only RS256", function () {
|
|
it("should not verify", function () {
|
|
expect(function () {
|
|
jwt.verify(TOKEN, pub, { algorithms: ["RS256"] });
|
|
}).toThrow(/invalid algorithm/);
|
|
});
|
|
});
|
|
|
|
if (PS_SUPPORTED) {
|
|
describe("signing with pub key as HS256 and whitelisting only PS256", function () {
|
|
it("should not verify", function () {
|
|
expect(function () {
|
|
jwt.verify(TOKEN, pub, { algorithms: ["PS256"] });
|
|
}).toThrow(/invalid algorithm/);
|
|
});
|
|
});
|
|
}
|
|
|
|
describe("signing with HS256 and checking with HS384", function () {
|
|
it("should not verify", function () {
|
|
expect(function () {
|
|
var token = jwt.sign({ foo: "bar" }, "secret", { algorithm: "HS256" });
|
|
jwt.verify(token, "some secret", { algorithms: ["HS384"] });
|
|
}).toThrow(/invalid algorithm/);
|
|
});
|
|
});
|
|
});
|