This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from gratipay/109054-whitelist-methods
only allow certain methods
- Loading branch information
Showing
4 changed files
with
56 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from aspen import Response | ||
from aspen.http.request import Request | ||
from gratipay import security | ||
from gratipay.testing import Harness | ||
from pytest import raises | ||
|
||
|
||
class TestSecurity(Harness): | ||
|
||
# oacm - only_allow_certain_methods | ||
|
||
def test_oacm_is_installed_properly(self): | ||
assert self.client.hxt('TRaCE', '/').code == 405 | ||
|
||
def test_oacm_allows_certain_methods(self): | ||
for allowed in ('GEt', 'HEaD', 'PosT'): | ||
request = Request(allowed) | ||
assert security.only_allow_certain_methods(request) is None | ||
|
||
def test_oacm_disallows_a_bunch_of_other_stuff(self): | ||
for disallowed in ('OPTIONS', 'TRACE', 'TRACK', 'PUT', 'DELETE'): | ||
request = Request(disallowed) | ||
response = raises(Response, security.only_allow_certain_methods, request).value | ||
assert response.code == 405 | ||
|
||
|
||
# ahtr - add_headers_to_response | ||
|
||
def test_ahtr_sets_x_frame_options(self): | ||
headers = self.client.GET('/about/').headers | ||
assert headers['X-Frame-Options'] == 'SAMEORIGIN' | ||
|
||
def test_ahtr_sets_x_content_type_options(self): | ||
headers = self.client.GET('/about/').headers | ||
assert headers['X-Content-Type-Options'] == 'nosniff' | ||
|
||
def test_ahtr_sets_x_xss_protection(self): | ||
headers = self.client.GET('/about/').headers | ||
assert headers['X-XSS-Protection'] == '1; mode=block' |