FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: lock CORS preflight allows write methods by lesnik512 · Pull Request #59 · modern-python/fastapi-sqlalchemy-template · GitHub

test: lock CORS preflight allows write methods - #59

Merged
lesnik512 merged 1 commit into
mainfrom
fix/cors-preflight-test
Jun 26, 2026
Merged

test: lock CORS preflight allows write methods#59
lesnik512 merged 1 commit into
mainfrom
fix/cors-preflight-test

Conversation

Copy link
Copy Markdown
Member

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 the settings.py defaults already ship correct:

cors_allowed_methods: list[str] = ["*"]
cors_allowed_headers: list[str] = ["*"]

…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 preflight OPTIONS /api/decks/ from the shipped dev origin (http://localhost:5173) with Access-Control-Request-Method: POST, asserting POST/PUT appear in Access-Control-Allow-Methods. Exercises the real settings → lite-bootstrap → Starlette CORSMiddleware wiring through the existing client fixture. No DB needed (preflight is handled in middleware before routing).

Verification

  • GREEN with the current ["*"] defaults.
  • RED if methods regress to [""]: Starlette returns preflight 400 Bad Request, POST absent — confirming the test is a genuine guard.
  • ruff format --check, ruff check --no-fix, ty check all pass.

🤖 Generated with Claude Code

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>
lesnik512 merged commit 18195dc into main Jun 26, 2026
2 checks passed
lesnik512 deleted the fix/cors-preflight-test branch June 26, 2026 18:18
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL