File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff 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
2429if settings .all_cors_origins :
2530 app .add_middleware (
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments