websri/test/create-integrity-metadata-set.ts

36 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2024-10-02 17:23:41 +09:00
import assert from "node:assert/strict";
import { test } from "node:test";
import {
createIntegrityMetadataSet,
IntegrityMetadata,
IntegrityMetadataSet,
} from "../src/index.ts";
2024-10-02 17:23:41 +09:00
test("instantiate a new IntegrityMetadataSet", async function () {
const res = new Response("Hello, world!");
const data = await res.arrayBuffer();
const set = await createIntegrityMetadataSet("sha256", data);
2024-10-02 17:23:41 +09:00
assert(set instanceof IntegrityMetadataSet);
});
test("instantiate with the specified hash algorithms and ArrayBuffer", async function () {
const res = new Response("Hello, world!");
const data = await res.arrayBuffer();
const set = await createIntegrityMetadataSet(["sha384", "sha512"], data);
assert.deepEqual(
[...set],
[
new IntegrityMetadata({
alg: "sha384",
val: "VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r",
}),
new IntegrityMetadata({
alg: "sha512",
val: "wVJ82JPBJHc9gRkRlwyP5uhX1t9dySJr2KFgYUwM2WOk3eorlLt9NgIe+dhl1c6ilKgt1JoLsmn1H256V/eUIQ==",
}),
],
);
});