Skip to content

Commit

Permalink
Test cors more thoroughly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarlyl committed Apr 28, 2017
1 parent b87c45b commit 107db6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler

from chalice.app import Chalice, CORSConfig # noqa
from typing import List, Any, Dict, Tuple, Callable # noqa
from typing import List, Any, Dict, Tuple, Callable # noqa
from chalice.compat import urlparse, parse_qs


Expand Down
11 changes: 8 additions & 3 deletions tests/integration/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def test_can_support_cors(smoke_test_app):
headers = response.headers
assert headers['Access-Control-Allow-Origin'] == '*'
assert headers['Access-Control-Allow-Headers'] == (
'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token')
'Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,'
'X-Api-Key')
assert headers['Access-Control-Allow-Methods'] == 'GET,POST,PUT,OPTIONS'


Expand All @@ -203,11 +204,15 @@ def test_can_support_custom_cors(smoke_test_app):
response = requests.options(smoke_test_app.url + '/custom_cors')
response.raise_for_status()
headers = response.headers
print(headers)
assert headers['Access-Control-Allow-Origin'] == expected_allow_origin
assert headers['Access-Control-Allow-Headers'] == (
'X-Special-Header,Content-Type,X-Amz-Date,Authorization,X-Api-Key,'
'X-Amz-Security-Token')
'Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,'
'X-Api-Key,X-Special-Header')
assert headers['Access-Control-Allow-Methods'] == 'GET,POST,PUT,OPTIONS'
assert headers['Access-Control-Max-Age'] == '600'
assert headers['Access-Control-Expose-Headers'] == 'X-Special-Header'
assert headers['Access-Control-Allow-Credentials'] == 'true'


def test_to_dict_is_also_json_serializable(smoke_test_app):
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/testapp/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from chalice import Chalice, BadRequestError, NotFoundError, Response,\
CORSConfig
from chalice.compat import parse_qs

try:
from urllib.parse import parse_qs
except:
from urlparse import parse_qs

# This is a test app that is used by integration tests.
# This app exercises all the major features of chalice
Expand Down Expand Up @@ -81,7 +85,7 @@ def supports_cors():
allow_headers=['X-Special-Header'],
max_age=600,
expose_headers=['X-Special-Header'],
allow_credentials=False))
allow_credentials=True))
def supports_custom_cors():
return {'cors': True}

Expand Down

0 comments on commit 107db6a

Please sign in to comment.