From 43ec22ee20f1039b2f4b3fedb2208f0ebddfb2fa Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 23 Aug 2026 02:46:10 +0200 Subject: [PATCH] fix(e2e): read the CSP off the response, not a second fetch readCspString re-fetched the current URL through the Playwright API request context and, when that failed, waited actionTimeout (30s) for a that no template in this repo emits. On a healthy runner that path works and costs one extra request; when name resolution degrades it collapses, because the API request context resolves DNS separately from the browser: the re-fetch burns its 10s cap and the meta wait then drains whatever is left of the caller's test budget. That is what killed web-svc-logout's guest persona in run 32597248629, job Pretix#0, whose swarm manager had a single resolver on 127.0.0.1 with dnsmasq no longer answering. Every guest test on that host inflated to ~40s and the logout one, loading two external assets on top, died on its 60s timeout having asserted nothing. The same role in Bluesky#0 and YOURLS#0 of the same run, same role set, finished in 0.85s and 0.82s - so this is a resilience fix, not a repair of a broken assertion. gotoOnion now installs a page.on("response") recorder, so the header is taken from the document the browser already received. That also covers the surface reached through an SSO round trip, where no navigation Response is in scope at the assertion - only guest.js holds one, biber, admin and the suitecrm saml spec discard theirs. The re-fetch stays as the fallback for a spec that navigates without gotoOnion; the meta fallback is deleted. The suite pins the header precedence (enforced over report-only) and every guard in assertCspInjections: a disabled injector, a gate that throws, an enabled injector without a base URL, a missing gate, a second enabled injector, and the case-insensitive host match. Inverting the precedence or dropping toLowerCase each trips exactly one test. Verified against a headless Chromium and a local server counting requests: the header survives a 302, no extra request is issued, a missing injector host still fails the assertion, and a header-less page falls back to exactly one re-fetch. Co-Authored-By: Claude Opus 5 (1M context) --- .../files/personas/utils/csp.js | 69 +++-- .../files/personas/utils/env.js | 2 + .../files/personas/utils/csp.test.js | 271 ++++++++++++++++++ 3 files changed, 322 insertions(+), 20 deletions(-) create mode 100644 tests/unit/javascript/roles/test-e2e-playwright/files/personas/utils/csp.test.js diff --git a/roles/test-e2e-playwright/files/personas/utils/csp.js b/roles/test-e2e-playwright/files/personas/utils/csp.js index 996f33babd..0b93d95a0f 100644 --- a/roles/test-e2e-playwright/files/personas/utils/csp.js +++ b/roles/test-e2e-playwright/files/personas/utils/csp.js @@ -1,11 +1,11 @@ /** * CSP injection assertion shared by every persona scenario. * - * `assertCspInjections` re-fetches the current URL via - * `page.request.get` so it can read the raw `content-security-policy` - * (or `content-security-policy-report-only`) header off the response, - * then verifies that every service whose JavaScript / CSS / asset is - * actually injected on the page is also covered by the role's CSP. + * `assertCspInjections` reads the raw `content-security-policy` (or + * `content-security-policy-report-only`) header of the document the + * browser is currently showing, then verifies that every service whose + * JavaScript / CSS / asset is actually injected on the page is also + * covered by the role's CSP. * * The intent is symmetric: when an injector role like `mastodon`, * `web-svc-asset`, `web-svc-cdn`, `web-svc-css`, `web-svc-javascript` @@ -14,9 +14,10 @@ * any rendered `