0001-WIP-migration-django1.11.patch
debian/control | ||
---|---|---|
3 | 3 |
Section: python |
4 | 4 |
Priority: optional |
5 | 5 |
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.7), debhelper (>= 7.4.3), |
6 |
python-django (>= 1.5)
|
|
6 |
python-django (>= 1.11)
|
|
7 | 7 |
Standards-Version: 3.9.1 |
8 | 8 |
X-Python-Version: >= 2.7 |
9 | 9 | |
... | ... | |
11 | 11 |
Architecture: all |
12 | 12 |
Depends: ${misc:Depends}, ${python:Depends}, |
13 | 13 |
python (>= 2.7), |
14 |
python-django (>= 1.5),
|
|
14 |
python-django (>= 1.11),
|
|
15 | 15 |
python-isodate, |
16 | 16 |
python-lasso |
17 | 17 |
Breaks: python-hobo (<< 0.34.5) |
mellon/urls.py | ||
---|---|---|
12 | 12 |
url('metadata/$', views.metadata, |
13 | 13 |
name='mellon_metadata') |
14 | 14 |
] |
15 |
if django.VERSION < (1, 8): |
|
16 |
from django.conf.urls import patterns |
|
17 |
urlpatterns = patterns('', *urlpatterns) |
setup.py | ||
---|---|---|
91 | 91 |
include_package_data=True, |
92 | 92 |
packages=find_packages(), |
93 | 93 |
install_requires=[ |
94 |
'django>=1.5',
|
|
94 |
'django>=1.11',
|
|
95 | 95 |
'requests', |
96 | 96 |
'isodate', |
97 | 97 |
], |
tests/eoidp_metadata.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<ns0:EntityDescriptor xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ns1="http://www.w3.org/2000/09/xmldsig#" entityID="https://cresson.entrouvert.org/idp/saml2/metadata"><ns0:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:KeyDescriptor><ns1:KeyInfo><ns1:X509Data><ns1:X509Certificate>MIIC+TCCAeGgAwIBAgIJAJqAKDUDlSinMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV |
|
3 |
BAMMCHdob2NhcmVzMB4XDTE0M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ns0:KeyDescriptor><ns0:ArtifactResolutionService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="https://cresson.entrouvert.org/idp/saml2/artifact" index="0" /><ns0:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://cresson.entrouvert.org/idp/saml2/slo" ResponseLocation="https://cresson.entrouvert.org/idp/saml2/slo_return" /><ns0:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://cresson.entrouvert.org/idp/saml2/slo" ResponseLocation="https://cresson.entrouvert.org/idp/saml2/slo_return" /><ns0:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="https://cresson.entrouvert.org/idp/saml2/slo/soap" /><ns0:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://cresson.entrouvert.org/idp/saml2/sso" /><ns0:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://cresson.entrouvert.org/idp/saml2/sso" /></ns0:IDPSSODescriptor></ns0:EntityDescriptor> |
tests/test_default_adapter.py | ||
---|---|---|
12 | 12 |
pytestmark = pytest.mark.django_db |
13 | 13 | |
14 | 14 |
idp = { |
15 |
'METADATA': file('tests/metadata.xml').read(), |
|
15 |
'METADATA': file('tests/dummy_metadata.xml').read(),
|
|
16 | 16 |
} |
17 | 17 |
saml_attributes = { |
18 | 18 |
'name_id_format': lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT, |
tests/test_sso_slo.py | ||
---|---|---|
13 | 13 | |
14 | 14 |
@fixture |
15 | 15 |
def idp_metadata(): |
16 |
return open('tests/metadata.xml').read() |
|
16 |
return open('tests/dummy_metadata.xml').read()
|
|
17 | 17 | |
18 | 18 | |
19 | 19 |
@fixture |
tests/test_utils.py | ||
---|---|---|
75 | 75 |
] |
76 | 76 |
request = rf.get('/') |
77 | 77 |
with mock.patch( |
78 |
'mellon.adapters.file', mock.mock_open(read_data=file('tests/metadata.xml').read()), |
|
78 |
'mellon.adapters.file', mock.mock_open(read_data=file('tests/dummy_metadata.xml').read()),
|
|
79 | 79 |
create=True): |
80 | 80 |
server = create_server(request) |
81 | 81 |
assert 'ERROR' not in caplog.text |
... | ... | |
85 | 85 |
def test_create_server_good_metadata(mocker, rf, private_settings, caplog): |
86 | 86 |
private_settings.MELLON_IDENTITY_PROVIDERS = [ |
87 | 87 |
{ |
88 |
'METADATA': file('tests/metadata.xml').read(), |
|
88 |
'METADATA': file('tests/dummy_metadata.xml').read(),
|
|
89 | 89 |
} |
90 | 90 |
] |
91 | 91 |
request = rf.get('/') |
tests/test_views.py | ||
---|---|---|
165 | 165 | |
166 | 166 |
def test_sp_initiated_login(private_settings, client): |
167 | 167 |
private_settings.MELLON_IDENTITY_PROVIDERS = [{ |
168 |
'METADATA': open('tests/metadata.xml').read(), |
|
168 |
'METADATA': open('tests/dummy_metadata.xml').read(),
|
|
169 | 169 |
}] |
170 | 170 |
response = client.get('/login/?next=%2Fwhatever') |
171 | 171 |
assert response.status_code == 302 |
... | ... | |
179 | 179 | |
180 | 180 |
def test_sp_initiated_login_chosen(private_settings, client): |
181 | 181 |
private_settings.MELLON_IDENTITY_PROVIDERS = [{ |
182 |
'METADATA': open('tests/metadata.xml').read(), |
|
182 |
'METADATA': open('tests/dummy_metadata.xml').read(),
|
|
183 | 183 |
}] |
184 | 184 |
qs = urlencode({ |
185 | 185 |
'entityID': 'http://idp5/metadata', |
... | ... | |
197 | 197 | |
198 | 198 |
def test_sp_initiated_login_requested_authn_context(private_settings, client): |
199 | 199 |
private_settings.MELLON_IDENTITY_PROVIDERS = [{ |
200 |
'METADATA': open('tests/metadata.xml').read(), |
|
200 |
'METADATA': open('tests/dummy_metadata.xml').read(),
|
|
201 | 201 |
'AUTHN_CLASSREF': [u'urn:be:fedict:iam:fas:citizen:eid', |
202 | 202 |
u'urn:be:fedict:iam:fas:citizen:token'], |
203 | 203 |
}] |
... | ... | |
216 | 216 | |
217 | 217 |
def test_malfortmed_artifact(private_settings, client, caplog): |
218 | 218 |
private_settings.MELLON_IDENTITY_PROVIDERS = [{ |
219 |
'METADATA': open('tests/metadata.xml').read(), |
|
219 |
'METADATA': open('tests/dummy_metadata.xml').read(),
|
|
220 | 220 |
}] |
221 | 221 |
response = client.get('/login/?SAMLart=xxx', status=400) |
222 | 222 |
assert 'artifact is malformed' in response.content |
... | ... | |
224 | 224 | |
225 | 225 | |
226 | 226 |
@pytest.fixture |
227 |
def artifact(): |
|
227 |
def dummy_artifact():
|
|
228 | 228 |
entity_id = 'http://idp5/metadata' |
229 | 229 |
token = 'x' * 20 |
230 | 230 |
return base64.b64encode('\x00\x04\x00\x00' + hashlib.sha1(entity_id).digest() + token) |
231 | 231 | |
232 | 232 | |
233 |
def test_error_500_on_artifact_resolve(private_settings, client, caplog, artifact): |
|
233 |
@pytest.fixture |
|
234 |
def eoidp_artifact(): |
|
235 |
entity_id = 'https://cresson.entrouvert.org/idp/saml2/metadata' |
|
236 |
token = 'x' * 20 |
|
237 |
return base64.b64encode('\x00\x04\x00\x00' + hashlib.sha1(entity_id).digest() + token) |
|
238 | ||
239 | ||
240 |
def test_error_500_on_artifact_resolve(private_settings, client, caplog, dummy_artifact): |
|
234 | 241 |
private_settings.MELLON_IDENTITY_PROVIDERS = [{ |
235 |
'METADATA': open('tests/metadata.xml').read(), |
|
242 |
'METADATA': open('tests/dummy_metadata.xml').read(),
|
|
236 | 243 |
}] |
237 | 244 |
with HTTMock(error_500): |
238 |
client.get('/login/?SAMLart=%s' % artifact) |
|
245 |
client.get('/login/?SAMLart=%s' % dummy_artifact)
|
|
239 | 246 |
assert 'IdP returned 500' in caplog.text |
240 | 247 | |
241 | 248 | |
242 |
def test_invalid_msg_on_artifact_resolve(private_settings, client, caplog, artifact):
|
|
249 |
def test_valid_msg_on_artifact_resolve(private_settings, client, caplog, eoidp_artifact):
|
|
243 | 250 |
private_settings.MELLON_IDENTITY_PROVIDERS = [{ |
244 |
'METADATA': open('tests/metadata.xml').read(), |
|
251 |
'METADATA': open('tests/eoidp_metadata.xml').read(),
|
|
245 | 252 |
}] |
246 | 253 |
with HTTMock(html_response): |
247 |
client.get('/login/?SAMLart=%s' % artifact) |
|
248 |
assert 'ArtifactResolveResponse is malformed' in caplog.text |
|
254 |
client.get('/login/?SAMLart=%s' % eoidp_artifact) |
|
255 |
assert 'Got SAML Artifact Response' in caplog.text |
tests/urls_tests.py | ||
---|---|---|
1 | 1 |
import django |
2 | 2 | |
3 |
from django.conf.urls import patterns, url, include
|
|
3 |
from django.conf.urls import url, include |
|
4 | 4 |
from django.http import HttpResponse |
5 | 5 | |
6 | 6 | |
... | ... | |
11 | 11 |
url('^', include('mellon.urls')), |
12 | 12 |
url('^$', homepage, name='homepage'), |
13 | 13 |
] |
14 | ||
15 |
if django.VERSION < (1, 9): |
|
16 |
urlpatterns = patterns('', *urlpatterns) |
tests/utils.py | ||
---|---|---|
13 | 13 | |
14 | 14 |
@all_requests |
15 | 15 |
def metadata_response(url, request): |
16 |
return response(200, content=file('tests/metadata.xml').read()) |
|
16 |
return response(200, content=file('tests/dummy_metadata.xml').read())
|
|
17 | 17 | |
18 | 18 | |
19 | 19 |
def reset_caplog(cap): |
testsettings.py | ||
---|---|---|
28 | 28 |
TEMPLATE_DIRS = [ |
29 | 29 |
'tests/templates/', |
30 | 30 |
] |
31 |
if django.VERSION >= (1, 8):
|
|
31 |
if django.VERSION >= (1, 11):
|
|
32 | 32 |
TEMPLATES = [ |
33 | 33 |
{ |
34 | 34 |
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
tox.ini | ||
---|---|---|
1 | 1 |
[tox] |
2 |
envlist = {coverage-,}{dj18,dj19}-{pg,sqlite} |
|
2 |
envlist = {coverage-,}{dj18,dj19,dj111}-{pg,sqlite}
|
|
3 | 3 |
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/django-mellon/ |
4 | 4 | |
5 | 5 |
[testenv] |
... | ... | |
17 | 17 |
deps = |
18 | 18 |
dj18: django>1.8,<1.9 |
19 | 19 |
dj19: django>1.9,<1.10 |
20 |
dj111: django>1.11,<1.12 |
|
20 | 21 |
pg: psycopg2 |
21 | 22 |
httmock |
22 | 23 |
pytest |
23 |
- |