Skip to content

Commit 203fd09

Browse files
committed
test: update CORS tests to verify allowed and disallowed origins
1 parent f872f16 commit 203fd09

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

test/test_main.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,24 @@ async def test_shutdown_event_failure(self, mock_logger, mock_database):
5656
assert any(call.args[0] == "Failed to disconnect from the database: Disconnection failed" for call in mock_logger.error.call_args_list)
5757

5858
def test_cors_middleware(self, client):
59-
# Test preflight request
59+
# Test preflight request with an allowed origin
6060
response = client.options("/health", headers={
61-
"Origin": "https://testorigin.com",
61+
"Origin": "https://app.map-action.com",
6262
"Access-Control-Request-Method": "GET",
6363
"Access-Control-Request-Headers": "Content-Type"
6464
})
6565
assert response.status_code == 200
6666
assert "access-control-allow-origin" in response.headers
67-
# When allow_credentials=True is set with allow_origins=["*"],
68-
# the middleware actually returns the specific origin instead of "*"
69-
# This is correct behavior according to the CORS spec for requests with credentials
70-
assert response.headers["access-control-allow-origin"] == "https://testorigin.com"
67+
# The middleware should return the specific origin since it's in our allowed list
68+
assert response.headers["access-control-allow-origin"] == "https://app.map-action.com"
69+
70+
# Also test with a disallowed origin - should return 400 Bad Request
71+
response = client.options("/health", headers={
72+
"Origin": "https://unauthorized-origin.com",
73+
"Access-Control-Request-Method": "GET",
74+
"Access-Control-Request-Headers": "Content-Type"
75+
})
76+
assert response.status_code == 400 # Preflight request should fail
7177

7278
@patch('app.main.logger')
7379
def test_log_requests_middleware(self, mock_logger, client):

0 commit comments

Comments
 (0)