Skip to content

Commit 6b32935

Browse files
committedDec 21, 2022
Disabled CORS and the OPTIONS method
1 parent 3b7c7e6 commit 6b32935

File tree

2 files changed

+1
-31
lines changed

2 files changed

+1
-31
lines changed
 

‎app/main.py

-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from fastapi import FastAPI, Request, status as fastapi_status
1010
from fastapi.exceptions import RequestValidationError
11-
from fastapi.middleware.cors import CORSMiddleware
1211
from fastapi.openapi.utils import get_openapi
1312
from fastapi.responses import JSONResponse
1413

@@ -25,14 +24,6 @@
2524
app.include_router(root.router)
2625
app.include_router(status.router)
2726

28-
app.add_middleware(
29-
CORSMiddleware,
30-
allow_origins=["*"],
31-
allow_credentials=True,
32-
allow_methods=['*'],
33-
allow_headers=["*"],
34-
)
35-
3627

3728
# --------------------------------------------------------------------------------
3829
# OpenAPI Customization

‎tests/integration/test_status.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,13 @@ def test_status_head(base_url):
5757
assert response.headers[header] == get_response.headers[header]
5858

5959

60-
# --------------------------------------------------------------------------------
61-
# Tests for OPTIONS
62-
# --------------------------------------------------------------------------------
63-
64-
def test_status_options(base_url):
65-
66-
# Call OPTIONS
67-
url = base_url.concat('/status')
68-
headers = {'Origin': 'localhost', 'Access-Control-Request-Method': 'GET'}
69-
response = requests.options(url, headers=headers)
70-
71-
# Response should be successful
72-
assert response.status_code == 200
73-
assert response.text == 'OK'
74-
75-
# Response header should list supported methods
76-
allow_string = response.headers['access-control-allow-methods']
77-
allowed = sorted(allow_string.split(', '))
78-
assert allowed == ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT']
79-
80-
8160
# --------------------------------------------------------------------------------
8261
# Tests for Unsupported Methods
8362
# --------------------------------------------------------------------------------
8463

8564
@pytest.mark.parametrize(
8665
'method',
87-
['DELETE', 'PATCH', 'POST', 'PUT']
66+
['DELETE', 'OPTIONS', 'PATCH', 'POST', 'PUT']
8867
)
8968
def test_status_invalid_method(base_url, method):
9069

0 commit comments

Comments
 (0)
Please sign in to comment.