fix(e2e): read CSRF token from storageState cookies before seeding#441
Open
fix(e2e): read CSRF token from storageState cookies before seeding#441
Conversation
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>
Completed Working on "Code Review"✅ Workflow completed successfully. |
|
🚅 Deployed to the QueryWeaver-pr-441 environment in queryweaver
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Playwright E2E tests in CI fail with
"CSRF token missing or invalid"on all POST/DELETE API calls (database connection tests, chat tests viaensureDatabaseConnected).Root Cause
The
getCsrfToken()function ine2e/infra/api/apiRequests.tsonly extracts the CSRF token from theSet-Cookieresponse header. When the Playwrightrequestfixture loadsstorageState(frome2e/.auth/user.json), thecsrf_tokencookie is already present. The server's_ensure_csrf_cookie()skips emitting a newSet-Cookiewhen it detects the cookie already exists in the request. Result:getCsrfToken()returnsundefined, and theX-CSRF-Tokenheader is never sent.Fix
Check the context's
storageState()for an existingcsrf_tokencookie before falling back to the seed GET request. This handles both cases:Failing CI checks on PR #438
Playwright Tests/test (push)❌Playwright Tests/test (pull_request)❌Changes
e2e/infra/api/apiRequests.ts: ModifiedgetCsrfToken()to read cookies fromctx.storageState()first