import { describe, it, expect, afterAll } from "vitest"; import type { AddressInfo } from "node:net"; import { request as httpRequest } from "node:http"; import { renderViewerDocument } from "../src/viewer/document.js"; import { buildAllowedHosts, isHostAllowed, startViewerServer, } from "../src/viewer/server.js"; describe("viewer document security", () => { it("serves a nonce-backed CSP without unsafe-inline script execution", () => { const rendered = renderViewerDocument(); expect(rendered.found).toBe(true); if (!rendered.found) return; expect(rendered.csp).toContain("script-src 'nonce-"); expect(rendered.csp).toContain("script-src-attr 'none'"); expect(rendered.csp).toContain("img-src 'self'"); expect(rendered.csp).not.toContain("script-src 'unsafe-inline'"); expect(rendered.html).toContain("