Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 42 additions & 0 deletions e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Loading