-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Facelift, support for py3 and modern django version, wheel support. (#61
) * Facelift, support for py3 and modern django version, wheel support. * Add support for Python 3 and PyPy * Move to pytest for testing * Add wheel build support * Drops support for Django < 1.6, adds support for Django 1.6, 1.7 1.8 and 1.9 This adds a proper tox config and uses this in travis, moves to pytest instead of nose and cleans up some old stuff.
- Loading branch information
Showing
17 changed files
with
506 additions
and
332 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
*.egg-info | ||
*.db | ||
*.sw[po] | ||
.cache | ||
.tox | ||
dist |
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 |
---|---|---|
@@ -1,9 +1,28 @@ | ||
sudo: false | ||
|
||
language: python | ||
env: | ||
- DJANGO_VERSION=1.4.5 | ||
- DJANGO_VERSION=1.5.1 | ||
|
||
python: | ||
- "2.6" | ||
- "2.7" | ||
install: pip install -q Django==${DJANGO_VERSION} --use-mirrors | ||
script: ./run.sh test | ||
- '2.7' | ||
- '3.4' | ||
- '3.5' | ||
- pypy | ||
|
||
env: | ||
- DJANGO_VERSION=1.9.x | ||
- DJANGO_VERSION=1.8.x | ||
- DJANGO_VERSION=1.7.x | ||
- DJANGO_VERSION=1.6.x | ||
|
||
matrix: | ||
exclude: | ||
- python: '3.5' | ||
env: DJANGO_VERSION=1.7.x | ||
- python: '3.5' | ||
env: DJANGO_VERSION=1.6.x | ||
|
||
install: | ||
- pip install tox | ||
|
||
script: | ||
- tox -e "$TRAVIS_PYTHON_VERSION-$DJANGO_VERSION" |
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 |
---|---|---|
@@ -1,2 +0,0 @@ | ||
VERSION = (2, 0, 3) | ||
__version__ = '.'.join(map(str, VERSION)) | ||
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 |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from csp.tests.test_decorators import DecoratorTests # noqa | ||
from csp.tests.test_middleware import MiddlewareTests # noqa | ||
from csp.tests.test_utils import UtilsTests # noqa | ||
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,19 @@ | ||
CSP_REPORT_ONLY = False | ||
|
||
DATABASES = { | ||
'default': { | ||
'NAME': 'test.db', | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
} | ||
} | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.sites', | ||
'csp', | ||
) | ||
|
||
SECRET_KEY = 'csp-test-key' |
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 |
---|---|---|
@@ -1,58 +1,65 @@ | ||
from django.http import HttpResponse | ||
from django.test import RequestFactory, TestCase | ||
from django.test import RequestFactory | ||
from django.test.utils import override_settings | ||
|
||
from nose.tools import eq_ | ||
|
||
from csp.decorators import csp, csp_replace, csp_update, csp_exempt | ||
from csp.middleware import CSPMiddleware | ||
|
||
|
||
REQUEST = RequestFactory().get('/') | ||
mw = CSPMiddleware() | ||
|
||
class DecoratorTests(TestCase): | ||
def test_csp_exempt(self): | ||
@csp_exempt | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
assert response._csp_exempt | ||
|
||
@override_settings(CSP_IMG_SRC=['foo.com']) | ||
def test_csp_update(self): | ||
@csp_update(IMG_SRC='bar.com') | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
eq_(response._csp_update, {'img-src': 'bar.com'}) | ||
|
||
@override_settings(CSP_IMG_SRC=['foo.com']) | ||
def test_csp_replace(self): | ||
@csp_replace(IMG_SRC='bar.com') | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
eq_(response._csp_replace, {'img-src': 'bar.com'}) | ||
|
||
def test_csp(self): | ||
@csp(IMG_SRC=['foo.com'], FONT_SRC=['bar.com']) | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
eq_(response._csp_config, | ||
{'img-src': ['foo.com'], 'font-src': ['bar.com']}) | ||
mw.process_response(REQUEST, response) | ||
policy_list = sorted(response['Content-Security-Policy'].split("; ")) | ||
eq_(policy_list, ["font-src bar.com", "img-src foo.com"]) | ||
|
||
def test_csp_string_values(self): | ||
# Test backwards compatibility where values were strings | ||
@csp(IMG_SRC='foo.com', FONT_SRC='bar.com') | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
eq_(response._csp_config, | ||
{'img-src': ['foo.com'], 'font-src': ['bar.com']}) | ||
mw.process_response(REQUEST, response) | ||
policy_list = sorted(response['Content-Security-Policy'].split("; ")) | ||
eq_(policy_list, ["font-src bar.com", "img-src foo.com"]) | ||
|
||
def test_csp_exempt(): | ||
@csp_exempt | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
assert response._csp_exempt | ||
|
||
|
||
@override_settings(CSP_IMG_SRC=['foo.com']) | ||
def test_csp_update(): | ||
@csp_update(IMG_SRC='bar.com') | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
assert response._csp_update == {'img-src': 'bar.com'} | ||
|
||
|
||
@override_settings(CSP_IMG_SRC=['foo.com']) | ||
def test_csp_replace(): | ||
@csp_replace(IMG_SRC='bar.com') | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
assert response._csp_replace == {'img-src': 'bar.com'} | ||
|
||
|
||
def test_csp(): | ||
@csp(IMG_SRC=['foo.com'], FONT_SRC=['bar.com']) | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
assert response._csp_config == { | ||
'img-src': ['foo.com'], 'font-src': ['bar.com'] | ||
} | ||
|
||
mw.process_response(REQUEST, response) | ||
policy_list = sorted(response['Content-Security-Policy'].split("; ")) | ||
assert policy_list == ["font-src bar.com", "img-src foo.com"] | ||
|
||
|
||
def test_csp_string_values(): | ||
# Test backwards compatibility where values were strings | ||
@csp(IMG_SRC='foo.com', FONT_SRC='bar.com') | ||
def view(request): | ||
return HttpResponse() | ||
response = view(REQUEST) | ||
assert response._csp_config == { | ||
'img-src': ['foo.com'], 'font-src': ['bar.com'] | ||
} | ||
|
||
mw.process_response(REQUEST, response) | ||
policy_list = sorted(response['Content-Security-Policy'].split("; ")) | ||
assert policy_list == ["font-src bar.com", "img-src foo.com"] |
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
Oops, something went wrong.