forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders.test.ts
More file actions
34 lines (28 loc) · 1.24 KB
/
Copy pathheaders.test.ts
File metadata and controls
34 lines (28 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { describe, expect, it } from "vitest";
import nextConfig from "../../next.config";
describe("security headers configuration", () => {
it("defines headers for all routes", async () => {
expect(nextConfig.headers).toBeDefined();
if (typeof nextConfig.headers !== "function") {
throw new Error("headers must be a function in nextConfig");
}
const headerConfigs = await nextConfig.headers();
expect(headerConfigs.length).toBeGreaterThan(0);
const globalHeadersConfig = headerConfigs.find(
(h: { source: string }) => h.source === "/:path*",
);
expect(globalHeadersConfig).toBeDefined();
const headers = globalHeadersConfig?.headers ?? [];
const headerMap = new Map(
headers.map((h: { key: string; value: string }) => [h.key, h.value]),
);
expect(headerMap.get("Referrer-Policy")).toBe(
"strict-origin-when-cross-origin",
);
expect(headerMap.get("Permissions-Policy")).toContain("camera=()");
expect(headerMap.get("Permissions-Policy")).toContain("microphone=()");
expect(headerMap.get("Permissions-Policy")).toContain("geolocation=()");
expect(headerMap.get("X-Content-Type-Options")).toBe("nosniff");
expect(headerMap.get("X-Frame-Options")).toBe("DENY");
});
});