Skip to content

Commit 15a745f

Browse files
lesnik512claude
andcommitted
test: lock CORS preflight allows write methods
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>
1 parent 3dd4a6d commit 15a745f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/test_cors.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import TYPE_CHECKING
2+
3+
4+
if TYPE_CHECKING:
5+
from httpx import AsyncClient
6+
7+
8+
async def test_cors_preflight_allows_write_methods(client: AsyncClient) -> None:
9+
response = await client.options(
10+
"/api/decks/",
11+
headers={
12+
"Origin": "http://localhost:5173",
13+
"Access-Control-Request-Method": "POST",
14+
},
15+
)
16+
17+
allow_methods = response.headers.get("access-control-allow-methods", "")
18+
assert "POST" in allow_methods
19+
assert "PUT" in allow_methods

0 commit comments

Comments
 (0)