mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +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>
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
"use strict";
|
|
|
|
import { expect, describe, it } from "bun:test";
|
|
import testUtils from "./test-utils";
|
|
import jws from "jws";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
|
|
describe("complete option", function () {
|
|
const secret = fs.readFileSync(path.join(__dirname, "priv.pem"));
|
|
const pub = fs.readFileSync(path.join(__dirname, "pub.pem"));
|
|
|
|
const header = { alg: "RS256" };
|
|
const payload = { iat: Math.floor(Date.now() / 1000) };
|
|
const signed = jws.sign({ header, payload, secret, encoding: "utf8" });
|
|
const signature = jws.decode(signed).signature;
|
|
|
|
[
|
|
{
|
|
description: "should return header, payload and signature",
|
|
complete: true,
|
|
},
|
|
].forEach(testCase => {
|
|
it(testCase.description, function (done) {
|
|
testUtils.verifyJWTHelper(signed, pub, { typ: "JWT", complete: testCase.complete }, (err, decoded) => {
|
|
testUtils.asyncCheck(done, () => {
|
|
expect(err).toBeNull();
|
|
expect(decoded.header).toHaveProperty("alg", header.alg);
|
|
expect(decoded.payload).toHaveProperty("iat", payload.iat);
|
|
expect(decoded).toHaveProperty("signature", signature);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
[
|
|
{
|
|
description: "should return payload",
|
|
complete: false,
|
|
},
|
|
].forEach(testCase => {
|
|
it(testCase.description, function (done) {
|
|
testUtils.verifyJWTHelper(signed, pub, { typ: "JWT", complete: testCase.complete }, (err, decoded) => {
|
|
testUtils.asyncCheck(done, () => {
|
|
expect(err).toBeNull();
|
|
expect(decoded.header).toBeUndefined();
|
|
expect(decoded.payload).toBeUndefined();
|
|
expect(decoded.signature).toBeUndefined();
|
|
expect(decoded).toHaveProperty("iat", payload.iat);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|