30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("~/modules/booking/routes/PublicBooking.server", () => ({
|
|
publicBookingLoader: vi.fn(),
|
|
publicBookingAction: vi.fn(),
|
|
}));
|
|
vi.mock("~/modules/booking/components/PublicBookingRoute", () => ({ default: () => null }));
|
|
vi.mock("~/components/ui/errors/ServerError", () => ({ default: () => null }));
|
|
|
|
describe("booking embed CSP", () => {
|
|
it("keeps cross-origin framing while nonce-protecting document scripts", async () => {
|
|
const { headers } = await import("./b.$tenant.$slug.embed");
|
|
const nonce = "aBcDeFgHiJkLmNoPqRsTuVwX";
|
|
const responseHeaders = new Headers(
|
|
headers({
|
|
loaderHeaders: new Headers(),
|
|
parentHeaders: new Headers({ "x-hivegrid-csp-nonce": nonce }),
|
|
actionHeaders: new Headers(),
|
|
errorHeaders: undefined,
|
|
}),
|
|
);
|
|
const policy = responseHeaders.get("Content-Security-Policy") ?? "";
|
|
|
|
expect(policy).toContain(`script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`);
|
|
expect(policy).toContain("frame-ancestors *");
|
|
expect(policy).toContain("object-src 'none'");
|
|
expect(policy).toContain("form-action 'self'");
|
|
});
|
|
});
|