From 932f7a0456b2a8dcf2ae51b3155becaad0385982 Mon Sep 17 00:00:00 2001 From: "arrz.dev" <55147716+arrzdev@users.noreply.github.com> Date: Tue, 17 Nov 2026 05:30:54 +0000 Subject: [PATCH] test(e2e): assert the session cookie flags on a smoke sign-in The deployed-environment smoke signs in with an existing QA account from E2E_QA_EMAIL and E2E_QA_PASSWORD, checks the session Set-Cookie carries Secure, HttpOnly and SameSite=Lax, then signs out. Skipped when the account is not set. --- biome.json | 2 ++ e2e/smoke.spec.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/biome.json b/biome.json index 954a9e9a..84e30989 100644 --- a/biome.json +++ b/biome.json @@ -95,6 +95,8 @@ "E2E_API_PORT", "E2E_BASE_URL", "E2E_GAME_PORT", + "E2E_QA_EMAIL", + "E2E_QA_PASSWORD", "E2E_REUSE", "E2E_SHARD", "FORCE_ALL", diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index f98d2a5d..ee98840b 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -73,4 +73,46 @@ test.describe("deployed environment", () => { sha: expect.stringMatching(/^[0-9a-f]{40}$/), }) }) + + // The one exception to "no accounts": it signs in with an existing QA + // account (E2E_QA_EMAIL, E2E_QA_PASSWORD) and signs out again, so the only + // write is the session row that sign-out deletes. Skipped without them. + test("sign-in sets the session cookie Secure, HttpOnly and SameSite=Lax", async ({ + request, + baseURL, + }) => { + const email = process.env.E2E_QA_EMAIL + const password = process.env.E2E_QA_PASSWORD + test.skip( + !email || !password, + "needs E2E_QA_EMAIL and E2E_QA_PASSWORD", + ) + const headers = { origin: new URL(baseURL ?? "").origin } + + const signIn = await request.post("/api/v1/auth/sign-in/email", { + data: { email, password }, + headers, + }) + expect(signIn.status()).toBe(200) + const sessionCookie = signIn + .headersArray() + .filter((header) => header.name.toLowerCase() === "set-cookie") + .map((header) => header.value) + .find((cookie) => cookie.includes("session_token=")) + // only the attributes, so a failure never prints the token + const attributes = sessionCookie + ?.split(";") + .slice(1) + .map((attribute) => attribute.trim().toLowerCase()) + expect(attributes).toEqual( + expect.arrayContaining(["secure", "httponly", "samesite=lax"]), + ) + + // better-auth refuses a POST without a JSON body (415) + const signOut = await request.post("/api/v1/auth/sign-out", { + data: {}, + headers, + }) + expect(signOut.status()).toBe(200) + }) })