Release Network Tools 0.1.0

This commit is contained in:
2026-09-01 02:44:20 +02:00
commit 729430295b
61 changed files with 8357 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";
import { buildCsp, inspectHeaders } from "../../src/network/http";
import { lookupMime } from "../../src/network/mime";
describe("HTTP helpers", () => {
it("parses duplicates and reports missing security headers", () => {
const result = inspectHeaders(
"Content-Type: text/html\nSet-Cookie: a=1\nSet-Cookie: b=2",
);
expect(result.duplicates).toContain("set-cookie");
expect(result.findings).toContain(
"No Content-Security-Policy header is present.",
);
});
it("rejects folded headers", () => {
expect(() => inspectHeaders("X-Test: one\n two")).toThrow(/folded/u);
});
it("builds a restrictive CSP and makes dangerous sources visible", () => {
const result = buildCsp({
defaultSrc: "'self'",
scriptSrc: "'self' 'unsafe-eval'",
styleSrc: "'self'",
imgSrc: "'self' data:",
connectSrc: "'self'",
workerSrc: "'self' blob:",
});
expect(result.policy).toContain("object-src 'none'");
expect(result.warnings.join(" ")).toMatch(/unsafe-eval/u);
});
});
describe("MIME lookup", () => {
it("finds types by extension or media type", () => {
expect(lookupMime(".wasm")).toEqual([
{ extension: "wasm", mime: "application/wasm" },
]);
expect(lookupMime("epub")[0]?.mime).toBe("application/epub+zip");
});
});