release: WRNexusJS 0.4.0

This commit is contained in:
2026-07-27 12:42:18 +05:30
parent 8b728a3e5d
commit 30e5721e84
250 changed files with 10065 additions and 3923 deletions
+28 -1
View File
@@ -2,7 +2,15 @@ import { expect, test } from "bun:test";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { configureStorage, getStore, serveStoredFile, upload } from "../src/index.ts";
import {
configureStorage,
createSignedFileToken,
getStore,
safeObjectKey,
serveStoredFile,
upload,
verifySignedFileToken,
} from "../src/index.ts";
function configure() {
configureStorage(
@@ -34,3 +42,22 @@ test("public active content is attachment-only and cannot be MIME-sniffed", asyn
expect(response?.headers.get("x-content-type-options")).toBe("nosniff");
expect(response?.headers.get("content-disposition")).toStartWith("attachment");
});
test("safe object keys discard traversal-like prefixes", () => {
expect(safeObjectKey("report.pdf", "../../private/reports")).toMatch(/^private\/reports\//);
expect(safeObjectKey("report.pdf", "../..")).toMatch(/^uploads\//);
});
test("signed file tokens reject tampering and expired payloads", async () => {
const secret = "a-long-test-secret-for-files";
const token = await createSignedFileToken(
{ store: "private", key: "reports/a.pdf", expiresAt: 2_000 },
secret,
);
expect(await verifySignedFileToken(token, secret, 1_000)).toMatchObject({
store: "private",
key: "reports/a.pdf",
});
expect(await verifySignedFileToken(`${token}x`, secret, 1_000)).toBeNull();
expect(await verifySignedFileToken(token, secret, 2_000)).toBeNull();
});