Skip to content

Commit 2a46cb7

Browse files
committed
Add healthz endpoint and CORS tests
1 parent 1c6d656 commit 2a46cb7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

backend/app/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def custom_generate_unique_id(route: APIRoute) -> str:
2020
generate_unique_id_function=custom_generate_unique_id,
2121
)
2222

23+
@app.get("/healthz", include_in_schema=False)
24+
def healthz() -> dict[str, str]:
25+
return {"status": "ok"}
26+
27+
2328
# Set all CORS enabled origins
2429
if settings.all_cors_origins:
2530
app.add_middleware(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from fastapi.testclient import TestClient
2+
3+
from app.core.config import settings
4+
5+
6+
def test_healthz(client: TestClient) -> None:
7+
response = client.get("/healthz")
8+
assert response.status_code == 200
9+
assert response.json() == {"status": "ok"}
10+
11+
12+
def test_cors_allows_configured_origin(client: TestClient) -> None:
13+
response = client.get("/healthz", headers={"Origin": settings.FRONTEND_HOST})
14+
assert response.headers.get("access-control-allow-origin") == settings.FRONTEND_HOST
15+
16+
17+
def test_cors_blocks_unknown_origin(client: TestClient) -> None:
18+
response = client.get("/healthz", headers={"Origin": "https://unknown.example"})
19+
assert "access-control-allow-origin" not in response.headers

0 commit comments

Comments
 (0)