Skip to content

Commit 946a620

Browse files
committed
fix: cors is opt out if enabled
1 parent 4931d56 commit 946a620

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/functional/event_handler/required_dependencies/test_api_gateway.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def test_cors():
331331
def with_cors() -> Response:
332332
return Response(200, content_types.TEXT_HTML, "test")
333333

334-
@app.get("/without-cors")
334+
@app.get("/without-cors", cors=False)
335335
def without_cors() -> Response:
336336
return Response(200, content_types.TEXT_HTML, "test")
337337

@@ -350,17 +350,17 @@ def handler(event, context):
350350
assert headers["Access-Control-Allow-Headers"] == [",".join(sorted(CORSConfig._REQUIRED_HEADERS))]
351351

352352
# THEN for routes without cors flag return no cors headers
353-
mock_event = {"path": "/my/request", "httpMethod": "GET"}
353+
mock_event = {"path": "/without-cors", "httpMethod": "GET"}
354354
result = handler(mock_event, None)
355355
assert "Access-Control-Allow-Origin" not in result["multiValueHeaders"]
356356

357357

358358
def test_cors_no_request_origin():
359-
# GIVEN a function with cors=True
359+
# GIVEN a function
360360
# AND http method set to GET
361-
app = ApiGatewayResolver()
361+
app = ApiGatewayResolver(cors=CORSConfig())
362362

363-
@app.get("/my/path", cors=True)
363+
@app.get("/my/path")
364364
def with_cors() -> Response:
365365
return Response(200, content_types.TEXT_HTML, "test")
366366

@@ -381,7 +381,7 @@ def handler(event, context):
381381

382382

383383
def test_cors_allow_all_request_origins():
384-
# GIVEN a function with cors=True
384+
# GIVEN a function
385385
# AND http method set to GET
386386
app = ApiGatewayResolver(
387387
cors=CORSConfig(
@@ -390,11 +390,11 @@ def test_cors_allow_all_request_origins():
390390
),
391391
)
392392

393-
@app.get("/my/path", cors=True)
393+
@app.get("/my/path")
394394
def with_cors() -> Response:
395395
return Response(200, content_types.TEXT_HTML, "test")
396396

397-
@app.get("/without-cors")
397+
@app.get("/without-cors", cors=False)
398398
def without_cors() -> Response:
399399
return Response(200, content_types.TEXT_HTML, "test")
400400

@@ -413,7 +413,7 @@ def handler(event, context):
413413
assert headers["Access-Control-Allow-Headers"] == [",".join(sorted(CORSConfig._REQUIRED_HEADERS))]
414414

415415
# THEN for routes without cors flag return no cors headers
416-
mock_event = {"path": "/my/request", "httpMethod": "GET"}
416+
mock_event = {"path": "/without-cors", "httpMethod": "GET"}
417417
result = handler(mock_event, None)
418418
assert "Access-Control-Allow-Origin" not in result["multiValueHeaders"]
419419

0 commit comments

Comments
 (0)