import { describe, it, expect } from "vitest"; import nextConfig from "./next.config"; import { FRAME_CSP } from "./app/lib/frameHtml"; // add-custom-html-block: config headers replace a route's own header of the same name, so the baseline // Content-Security-Policy would strip the frame's sandbox. A later rule for the frame paths puts it back // (Next.js: the last rule setting a key wins). describe("Custom HTML frame headers", () => { it("sends the sandbox policy on both frame paths, after the baseline rule", async () => { const rules = await nextConfig.headers!(); const baseline = rules.findIndex((r) => r.source === "/:path*"); for (const source of ["/p/:company/:slug/frame/:block", "/pages/:id/preview/frame/:block"]) { const at = rules.findIndex((r) => r.source === source); expect(at, source).toBeGreaterThan(baseline); const sent = Object.fromEntries(rules[at].headers.map((h) => [h.key, h.value])); expect(sent["Content-Security-Policy"]).toBe(FRAME_CSP); expect(sent["Referrer-Policy"]).toBe("no-referrer"); } expect(FRAME_CSP).toMatch(/^sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox; frame-ancestors 'self'/); }); });