-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprivacy.spec.ts
More file actions
59 lines (47 loc) · 1.87 KB
/
Copy pathprivacy.spec.ts
File metadata and controls
59 lines (47 loc) · 1.87 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { expect, test } from "@playwright/test";
const headersFileUrl = new URL("../public/_headers", import.meta.url);
const remoteOnlyFixture = fileURLToPath(
new URL("../fixtures/remote-only.jpg", import.meta.url),
);
async function expectedContentSecurityPolicy(): Promise<string> {
const headerLine = (await readFile(headersFileUrl, "utf8"))
.split(/\r?\n/u)
.map((line) => line.trim())
.find((line) => line.startsWith("Content-Security-Policy:"));
if (headerLine === undefined) {
throw new Error("Content-Security-Policy is missing from public/_headers.");
}
return headerLine.slice("Content-Security-Policy:".length).trim();
}
test("initial load stays on-origin and serves the production CSP", async ({
page,
}) => {
const requests: string[] = [];
page.on("request", (request) => requests.push(request.url()));
const response = await page.goto("/");
expect(response).not.toBeNull();
expect(response?.headers()["content-security-policy"]).toBe(
await expectedContentSecurityPolicy(),
);
await expect(page.getByText("Sourceglass", { exact: true })).toBeVisible();
const baseOrigin = new URL(page.url()).origin;
const offOriginRequests = requests.filter(
(url) => new URL(url).origin !== baseOrigin,
);
expect(offOriginRequests).toEqual([]);
});
test("image inspection stays on-origin", async ({ page }) => {
const requests: string[] = [];
page.on("request", (request) => requests.push(request.url()));
await page.goto("/");
await page.getByLabel("Select Image").setInputFiles(remoteOnlyFixture);
await expect(
page.getByText("No AI-related record was found", { exact: true }),
).toBeVisible();
const baseOrigin = new URL(page.url()).origin;
expect(requests.filter((url) => new URL(url).origin !== baseOrigin)).toEqual(
[],
);
});