2024-10-02 17:23:41 +09:00
|
|
|
import assert from "node:assert";
|
|
|
|
import { test } from "node:test";
|
2025-01-06 13:41:24 +09:00
|
|
|
import { IntegrityMetadataSet } from "../../src/index.ts";
|
2024-10-02 17:23:41 +09:00
|
|
|
|
|
|
|
test("pick the strongest metadata from set", function () {
|
|
|
|
const integrityMetadataSet = new IntegrityMetadataSet(`
|
2025-02-19 17:14:01 +09:00
|
|
|
sha256-gxZXfeA3KCK+ZyBybEt6liVPg+FWGf/KLVU6rufBujE=
|
|
|
|
sha384-LDW1hUX1OX+VZsNmW+LELiky69a4xF+FfVsTlqZOhqPiPj5YYo20jP6C8H8uXMZf
|
|
|
|
sha512-aqnrVqlE3w/CWs51jb3FHCsFSBwfpecdXHaFFYZNkxfW2Z1qyJm4mA9iCPK11KeWwEa8rbMDq7l6IrnevQuOQw==
|
|
|
|
sha512-P8q/bH6NoZs5MnZKL9D/r/oEZOlyEAmSfuXuJchD2WeXnKbnfcO3fF0WvO6CiqZUGWsEREs9BWLrv1xr3NPOLg==
|
2024-10-02 17:23:41 +09:00
|
|
|
`);
|
|
|
|
|
2025-01-06 13:41:24 +09:00
|
|
|
assert.deepEqual(
|
2025-02-19 17:14:01 +09:00
|
|
|
[...integrityMetadataSet.strongest],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
alg: "sha512",
|
|
|
|
val: "aqnrVqlE3w/CWs51jb3FHCsFSBwfpecdXHaFFYZNkxfW2Z1qyJm4mA9iCPK11KeWwEa8rbMDq7l6IrnevQuOQw==",
|
|
|
|
opt: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
alg: "sha512",
|
|
|
|
val: "P8q/bH6NoZs5MnZKL9D/r/oEZOlyEAmSfuXuJchD2WeXnKbnfcO3fF0WvO6CiqZUGWsEREs9BWLrv1xr3NPOLg==",
|
|
|
|
opt: [],
|
|
|
|
},
|
|
|
|
],
|
2025-01-06 13:41:24 +09:00
|
|
|
);
|
2024-10-02 17:23:41 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
test("if there are no supported algorithms, return the empty set", function () {
|
|
|
|
const integrityMetadataSet = new IntegrityMetadataSet(`
|
|
|
|
sha1-lDpwLQbzRZmu4fjajvn3KWAx1pk=
|
|
|
|
md5-bNNVbesNpUvKBgtMOUeYOQ==
|
|
|
|
`);
|
|
|
|
|
2025-02-19 17:19:45 +09:00
|
|
|
assert.deepEqual([...integrityMetadataSet.strongest], []);
|
2024-10-02 17:23:41 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
test("custom getPrioritizedHashAlgorithm function can be used", function () {
|
|
|
|
const integrityMetadataSet = new IntegrityMetadataSet(
|
|
|
|
`
|
|
|
|
sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=
|
|
|
|
sha384-VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r
|
|
|
|
sha512-wVJ82JPBJHc9gRkRlwyP5uhX1t9dySJr2KFgYUwM2WOk3eorlLt9NgIe+dhl1c6ilKgt1JoLsmn1H256V/eUIQ==
|
|
|
|
`,
|
|
|
|
{
|
|
|
|
getPrioritizedHashAlgorithm() {
|
|
|
|
return "sha384";
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2025-01-06 13:41:24 +09:00
|
|
|
assert.deepEqual(
|
2025-02-19 17:19:45 +09:00
|
|
|
[...integrityMetadataSet.strongest],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
alg: "sha384",
|
|
|
|
val: "VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r",
|
|
|
|
opt: [],
|
|
|
|
},
|
|
|
|
],
|
2025-01-06 13:41:24 +09:00
|
|
|
);
|
2024-10-02 17:23:41 +09:00
|
|
|
});
|