Skip to content

fix(e2e): read CSRF token from storageState cookies before seeding#441

Open
gkorland wants to merge 1 commit intostagingfrom
fix/e2e-csrf-token-extraction
Open

fix(e2e): read CSRF token from storageState cookies before seeding#441
gkorland wants to merge 1 commit intostagingfrom
fix/e2e-csrf-token-extraction

Conversation

@gkorland
Copy link
Contributor

Problem

Playwright E2E tests in CI fail with "CSRF token missing or invalid" on all POST/DELETE API calls (database connection tests, chat tests via ensureDatabaseConnected).

Root Cause

The getCsrfToken() function in e2e/infra/api/apiRequests.ts only extracts the CSRF token from the Set-Cookie response header. When the Playwright request fixture loads storageState (from e2e/.auth/user.json), the csrf_token cookie is already present. The server's _ensure_csrf_cookie() skips emitting a new Set-Cookie when it detects the cookie already exists in the request. Result: getCsrfToken() returns undefined, and the X-CSRF-Token header is never sent.

Fix

Check the context's storageState() for an existing csrf_token cookie before falling back to the seed GET request. This handles both cases:

  • Fresh context (no storageState): seeds via GET → extracts from Set-Cookie ✅
  • Authenticated context (storageState loaded): reads existing cookie directly ✅

Failing CI checks on PR #438

  • Playwright Tests/test (push)
  • Playwright Tests/test (pull_request)

Changes

  • e2e/infra/api/apiRequests.ts: Modified getCsrfToken() to read cookies from ctx.storageState() first

When the Playwright request fixture loads storageState (from auth setup),
the csrf_token cookie is already present. The server's _ensure_csrf_cookie
skips setting a new Set-Cookie when the cookie already exists in the
request. This caused getCsrfToken() to return undefined, so all POST/DELETE
API calls in E2E tests failed with 'CSRF token missing or invalid'.

Fix: check the context's storageState for an existing csrf_token cookie
before falling back to the seed GET request.

Fixes CI Playwright test failures for database connection and chat tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@overcut-ai
Copy link

overcut-ai bot commented Feb 27, 2026

Completed Working on "Code Review"

✅ Workflow completed successfully.


👉 View complete log

@railway-app
Copy link

railway-app bot commented Feb 27, 2026

🚅 Deployed to the QueryWeaver-pr-441 environment in queryweaver

Service Status Web Updated (UTC)
QueryWeaver ✅ Success (View Logs) Web Feb 27, 2026 at 11:22 pm

@github-actions
Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/e2e-csrf-token-extraction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant