@@ -354,6 +354,33 @@ def handler(event, context):
354
354
assert "Access-Control-Allow-Origin" not in result ["multiValueHeaders" ]
355
355
356
356
357
+ def test_cors_no_origin ():
358
+ # GIVEN a function with cors=True
359
+ # AND http method set to GET
360
+ app = ApiGatewayResolver ()
361
+
362
+ @app .get ("/my/path" , cors = True )
363
+ def with_cors () -> Response :
364
+ return Response (200 , content_types .TEXT_HTML , "test" )
365
+
366
+ def handler (event , context ):
367
+ return app .resolve (event , context )
368
+
369
+ # remove origin header from request
370
+ del LOAD_GW_EVENT ["multiValueHeaders" ]["Origin" ]
371
+
372
+ # WHEN calling the event handler
373
+ result = handler (LOAD_GW_EVENT , None )
374
+
375
+ # THEN the headers should include cors headers
376
+ assert "multiValueHeaders" in result
377
+ headers = result ["multiValueHeaders" ]
378
+ assert headers ["Content-Type" ] == [content_types .TEXT_HTML ]
379
+ assert headers ["Access-Control-Allow-Origin" ] == ["*" ]
380
+ assert "Access-Control-Allow-Credentials" not in headers
381
+ assert headers ["Access-Control-Allow-Headers" ] == ["," .join (sorted (CORSConfig ._REQUIRED_HEADERS ))]
382
+
383
+
357
384
def test_cors_preflight_body_is_empty_not_null ():
358
385
# GIVEN CORS is configured
359
386
app = ALBResolver (cors = CORSConfig ())
0 commit comments