From 84eab8880153ef582f8092356809b63c46e3fed8 Mon Sep 17 00:00:00 2001 From: Paul Nothaft <53005142+the-luap@users.noreply.github.com> Date: Tue, 18 Aug 2026 22:14:15 +0200 Subject: [PATCH] test(e2e): read the admin JWT from the cookie, not the login body (#1073) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stable twin of #1071. Three specs acquire an admin token with `const body = await res.json(); return body.token`. On this branch too the admin login sets the JWT as the httpOnly `admin_token` cookie and responds with `res.json({ user })` — verified in auth.js on stable, not assumed from main — so the token is undefined and each spec fails at its first assertion, before exercising anything it was written to cover. Cookie and Authorization: Bearer are interchangeable server-side, so the helpers read the value back out of the context cookie jar and keep threading it as a Bearer. Every downstream call is unchanged. Verification is weaker than the main twin's, deliberately: the three spec files are byte-identical to the ones measured there (0 passed / 6 failed before, 3 passed / 3 failed after, against a live stack), and they compile and enumerate on this branch. Standing up a full stable compose stack to re-measure test-only changes was not worth it — say the word if you want that done before merge. The remaining failures are UI staleness, not auth, and are not addressed here. No CI workflow runs tests/e2e on this branch either, which is why this rotted unnoticed. Claude-Session: https://claude.ai/code/session_01Ra4hcsYiKuQLbbRsg6EjAc Co-authored-by: Paul Nothaft --- tests/e2e/auth-smoke.spec.ts | 6 +++--- tests/e2e/customer-portal-flow.spec.ts | 11 ++++++++--- tests/e2e/optional-email-event-creation.spec.ts | 11 ++++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/e2e/auth-smoke.spec.ts b/tests/e2e/auth-smoke.spec.ts index d876caff..b62bdd44 100644 --- a/tests/e2e/auth-smoke.spec.ts +++ b/tests/e2e/auth-smoke.spec.ts @@ -18,9 +18,9 @@ async function createEventWithPhotos(page: Page, adminToken?: string, attempt = }, }); expect(loginResponse.ok()).toBeTruthy(); - const loginData = await loginResponse.json(); - token = loginData.token; - expect(token).toBeTruthy(); + const cookies = await page.context().cookies(); + token = cookies.find((c) => c.name === 'admin_token')?.value; + expect(token, 'admin_token cookie missing from the login response').toBeTruthy(); } const eventName = `Playwright Smoke ${Date.now()}`; diff --git a/tests/e2e/customer-portal-flow.spec.ts b/tests/e2e/customer-portal-flow.spec.ts index b50a3c96..f6f90381 100644 --- a/tests/e2e/customer-portal-flow.spec.ts +++ b/tests/e2e/customer-portal-flow.spec.ts @@ -40,9 +40,14 @@ async function adminLogin(page: Page): Promise { failOnStatusCode: false, }); expect(res.ok()).toBeTruthy(); - const json = await res.json(); - expect(json.token).toBeTruthy(); - return json.token; + // The admin JWT is delivered as the httpOnly `admin_token` cookie, not in + // the response body. Server-side the cookie and an Authorization: Bearer + // header are interchangeable, so read it back out of the context jar and + // keep threading it as a Bearer — every downstream call stays as it was. + const cookies = await page.context().cookies(); + const token = cookies.find((c) => c.name === 'admin_token')?.value; + expect(token, 'admin_token cookie missing from the login response').toBeTruthy(); + return token as string; } async function setCustomerPortalEnabled(page: Page, adminToken: string, enabled: boolean) { diff --git a/tests/e2e/optional-email-event-creation.spec.ts b/tests/e2e/optional-email-event-creation.spec.ts index 641a1bf2..56e018df 100644 --- a/tests/e2e/optional-email-event-creation.spec.ts +++ b/tests/e2e/optional-email-event-creation.spec.ts @@ -8,9 +8,14 @@ async function getAdminToken(page: Page): Promise { data: { username: ADMIN_EMAIL, password: ADMIN_PASSWORD }, }); expect(res.ok()).toBeTruthy(); - const body = await res.json(); - expect(body.token).toBeTruthy(); - return body.token; + // The admin JWT is delivered as the httpOnly `admin_token` cookie, not in + // the response body. Server-side the cookie and an Authorization: Bearer + // header are interchangeable, so read it back out of the context jar and + // keep threading it as a Bearer — every downstream call stays as it was. + const cookies = await page.context().cookies(); + const token = cookies.find((c) => c.name === 'admin_token')?.value; + expect(token, 'admin_token cookie missing from the login response').toBeTruthy(); + return token as string; } async function updateEventSettings(