36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { loadModule } from "./test-helpers.mjs";
|
|
|
|
const contract = await loadModule("shared/utils/drop-contract.ts");
|
|
const types = await loadModule("shared/types/drop.ts");
|
|
const valid = {
|
|
version: 2,
|
|
chunkSize: types.CHUNK_SIZE,
|
|
chunkCount: 1,
|
|
noncePrefix: "AQIDBAUGBwg",
|
|
expiresIn: "24h",
|
|
maxReads: 1,
|
|
};
|
|
|
|
test("reservation validation accepts protocol geometry and rejects unsafe policies", () => {
|
|
assert.deepEqual(contract.validateReservation(valid), valid);
|
|
for (const bad of [
|
|
{ ...valid, chunkSize: 1 },
|
|
{ ...valid, chunkCount: 0 },
|
|
{ ...valid, chunkCount: 1.5 },
|
|
{ ...valid, expiresIn: "forever" },
|
|
{ ...valid, maxReads: 2 },
|
|
{ ...valid, unknown: true },
|
|
{ ...valid, noncePrefix: "AA" },
|
|
])
|
|
assert.throws(() => contract.validateReservation(bad));
|
|
});
|
|
|
|
test("manifest body must contain plaintext as well as the GCM tag", () => {
|
|
assert.throws(() => contract.validateManifestBodyLength(types.GCM_TAG_BYTES));
|
|
assert.doesNotThrow(() =>
|
|
contract.validateManifestBodyLength(types.GCM_TAG_BYTES + 1),
|
|
);
|
|
});
|