Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chalice local 200s CORS OPTIONS rather than 403 #554

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions chalice/local.py
Expand Up @@ -200,10 +200,6 @@ class NotAuthorizedError(LocalGatewayException):
CODE = 401


class NoOptionsRouteDefined(LocalGatewayException):
CODE = 403


class LambdaContext(object):
def __init__(self, function_name, memory_size,
max_runtime_ms=3000, time_source=None):
Expand Down Expand Up @@ -458,7 +454,11 @@ def handle_request(self, method, path, headers, body):
# No options route was defined for this path. API Gateway should
# automatically generate our CORS headers.
options_headers = self._autogen_options_headers(lambda_event)
raise NoOptionsRouteDefined(options_headers)
return {
'statusCode': 200,
'headers': options_headers,
'body': None
}
# The authorizer call will be a noop if there is no authorizer method
# defined for route. Otherwise it will raise a ForbiddenError
# which will be caught by the handler that called this and a 403 or
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_local.py
Expand Up @@ -345,6 +345,7 @@ def test_will_respond_with_custom_cors_enabled(handler):
headers=headers)
handler.do_GET()
response = handler.wfile.getvalue().splitlines()
assert b'HTTP/1.1 200 OK' in response
assert b'Access-Control-Allow-Origin: https://foo.bar' in response
assert (b'Access-Control-Allow-Headers: Authorization,Content-Type,'
b'Header-A,Header-B,X-Amz-Date,X-Amz-Security-Token,'
Expand All @@ -360,6 +361,7 @@ def test_will_respond_with_custom_cors_enabled_options(handler):
headers=headers)
handler.do_OPTIONS()
response = handler.wfile.getvalue().decode().splitlines()
assert 'HTTP/1.1 200 OK' in response
assert 'Access-Control-Allow-Origin: https://foo.bar' in response
assert ('Access-Control-Allow-Headers: Authorization,Content-Type,'
'Header-A,Header-B,X-Amz-Date,X-Amz-Security-Token,'
Expand Down