셸 동작을 보는 e2e(반응형, 스크롤 복원, 해시 링크, 타이포그래피, 건너뛰기 링크, 메뉴 이동, 운영 CSP, compact, en-US의 lang)가 지울 예제 화면을 열거나 그 메뉴를 누른다. 홈과 /examples/platform으로 옮겼다. 스크롤 복원은 계약 표가 그려진 뒤 스크롤하고, 해시 링크는 비동기 표보다 위에 있는 첫 절을 대상으로 한다. WebKit은 scroll anchoring이 없어 표 아래 대상이 1px 밀렸다. 갤러리 자체의 320px 리플로는 앞 커밋의 workshop 시험이 맡는다. 위험: 홈과 플랫폼 개요의 모양이 바뀌면 이 시험들의 대상도 바뀐다. 검증(desktop): 샘플을 지운 최종 트리에서 test:e2e 183 passed.
74 lines
2.9 KiB
TypeScript
74 lines
2.9 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
|
|
import { fulfillBuildScript } from "../support/browser/preload-use.ts";
|
|
import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
|
|
|
|
// 13-08. The Content-Security-Policy in config/hosting/security-headers.json was
|
|
// declared but never applied in a browser: `vite preview` sends no security
|
|
// headers. This smoke serves the build with the production headers attached
|
|
// and fails on any securitypolicyviolation event or console error.
|
|
const { headers: declaredHeaders } = JSON.parse(
|
|
readFileSync("config/hosting/security-headers.json", "utf8"),
|
|
) as { headers: Record<string, string> };
|
|
// The preview server is plain HTTP on loopback. `upgrade-insecure-requests` is a
|
|
// no-op for an HTTPS origin, but WebKit applies it to loopback and rewrites
|
|
// every same-origin request to https, which this server cannot answer. Every
|
|
// other directive is served exactly as declared.
|
|
const securityHeaders = {
|
|
...declaredHeaders,
|
|
"Content-Security-Policy": declaredHeaders["Content-Security-Policy"]!
|
|
.split(";")
|
|
.map((directive) => directive.trim())
|
|
.filter((directive) => directive !== "upgrade-insecure-requests")
|
|
.join("; "),
|
|
};
|
|
|
|
// F-7. No zod setup here: the app sets `jitless` in src/contracts/zod.ts before
|
|
// any schema is built, so zod's `Function("")` probe never reaches the policy.
|
|
test.beforeEach(async ({ page, baseURL }) => {
|
|
const origin = new URL(baseURL ?? "http://127.0.0.1:4173").origin;
|
|
await page.route(
|
|
(url) => url.origin === origin,
|
|
async (route) => {
|
|
const response = await route.fetch();
|
|
// 1103/11-09. Keeps the build scripts' evaluation mark for the
|
|
// fixture's preload check.
|
|
await fulfillBuildScript(route, response, {
|
|
...response.headers(),
|
|
...securityHeaders,
|
|
});
|
|
},
|
|
);
|
|
await page.addInitScript(() => {
|
|
const violations: string[] = [];
|
|
Object.defineProperty(window, "__cspViolations", { value: violations });
|
|
document.addEventListener("securitypolicyviolation", (event) => {
|
|
violations.push(`${event.effectiveDirective} ${event.blockedURI}`);
|
|
});
|
|
});
|
|
});
|
|
|
|
async function cspViolations(page: Page): Promise<string[]> {
|
|
return page.evaluate(() => (window as unknown as { __cspViolations: string[] }).__cspViolations);
|
|
}
|
|
|
|
test("boots and changes route under the production security headers", async ({ page }) => {
|
|
const response = await page.goto("/");
|
|
expect(response?.headers()["content-security-policy"]).toBe(
|
|
securityHeaders["Content-Security-Policy"],
|
|
);
|
|
await expect(page.getByRole("heading", { level: 1 })).toHaveText(
|
|
"Clean Architecture Frontend",
|
|
);
|
|
|
|
await page
|
|
.getByRole("navigation", { name: "주요 탐색" })
|
|
.getByRole("link", { name: "플랫폼 구성" })
|
|
.click();
|
|
await expect(
|
|
page.getByRole("heading", { level: 1, name: "플랫폼 구성" }),
|
|
).toBeFocused();
|
|
|
|
expect(await cspViolations(page)).toEqual([]);
|
|
});
|