Skip to content

Commit

Permalink
Merge pull request #282 from mozilla-services/safety_check_in_service…
Browse files Browse the repository at this point in the history
…_methods

Safety check on CORS methods in Service
  • Loading branch information
almet committed Mar 13, 2015
2 parents 894dc5d + 2acc633 commit 47c78c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cornice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def cors_support_credentials(self, method=None):
The method to check the credentials support for
"""
for meth, view, args in self.definitions:
if meth.upper() == method.upper():
if method and meth.upper() == method.upper():
return args.get('cors_credentials', False)

if getattr(self, 'cors_credentials', False):
Expand All @@ -469,7 +469,7 @@ def cors_support_credentials(self, method=None):

def cors_max_age_for(self, method=None):
for meth, view, args in self.definitions:
if meth.upper() == method.upper():
if method and meth.upper() == method.upper():
return args.get('cors_max_age', False)

return getattr(self, 'cors_max_age', None)
Expand Down
3 changes: 3 additions & 0 deletions cornice/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,12 @@ def test_per_method_supported_origins(self):

def test_credential_support_can_be_enabled(self):
foo = Service(name='foo', path='/foo', cors_credentials=True)
foo.add_view('POST', _stub)
self.assertTrue(foo.cors_support_credentials())

def test_credential_support_is_disabled_by_default(self):
foo = Service(name='foo', path='/foo')
foo.add_view('POST', _stub)
self.assertFalse(foo.cors_support_credentials())

def test_per_method_credential_support(self):
Expand All @@ -440,6 +442,7 @@ def test_method_takes_precendence_for_credential_support(self):

def test_max_age_can_be_defined(self):
foo = Service(name='foo', path='/foo', cors_max_age=42)
foo.add_view('POST', _stub)
self.assertEqual(foo.cors_max_age_for(), 42)

def test_max_age_can_be_different_dependeing_methods(self):
Expand Down

0 comments on commit 47c78c9

Please sign in to comment.