test: lock CORS preflight allows write methods#59
Merged
Conversation
The CORS defaults already ship correct (`["*"]`), but nothing guarded the preflight contract. Add a regression test that sends an `OPTIONS /api/decks/` preflight from the shipped dev origin (`http://localhost:5173`) and asserts `POST`/`PUT` appear in `Access-Control-Allow-Methods`, exercising the real settings → lite-bootstrap → Starlette CORS middleware wiring. Ported from modern-python/litestar-sqlalchemy-template#34. Verified it fails (preflight 400, POST absent) if the methods default regresses to `[""]`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Context
Ports the regression test from modern-python/litestar-sqlalchemy-template#34.
That PR fixed a CORS bug where the defaults were
[""](neither allow-all["*"]nor empty[]). In this template thesettings.pydefaults already ship correct:…but there was no test guarding the preflight contract, so a future regression to
[""]would slip through silently.Change
Add
tests/test_cors.py: a preflightOPTIONS /api/decks/from the shipped dev origin (http://localhost:5173) withAccess-Control-Request-Method: POST, assertingPOST/PUTappear inAccess-Control-Allow-Methods. Exercises the real settings → lite-bootstrap → StarletteCORSMiddlewarewiring through the existingclientfixture. No DB needed (preflight is handled in middleware before routing).Verification
["*"]defaults.[""]: Starlette returns preflight400 Bad Request,POSTabsent — confirming the test is a genuine guard.ruff format --check,ruff check --no-fix,ty checkall pass.🤖 Generated with Claude Code