diff --git a/mellon/adapters.py b/mellon/adapters.py index 8c869a3..ce71629 100644 --- a/mellon/adapters.py +++ b/mellon/adapters.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import logging import uuid from xml.etree import ElementTree as ET @@ -76,7 +91,7 @@ class DefaultAdapter(object): self.logger.error(u'METADATA of %d-th idp has no EntityDescriptor root tag', i) continue - if not 'entityID' in doc.attrib: + if 'entityID' not in doc.attrib: self.logger.error( u'METADATA of %d-th idp has no entityID attribute on its root tag', i) continue @@ -105,7 +120,7 @@ class DefaultAdapter(object): except (AttributeError, KeyError, IndexError) as e: self.logger.error( u'invalid reference in username template %r: %s', username_template, e) - except Exception as e: + except Exception: self.logger.exception(u'unknown error when formatting username') else: return username diff --git a/mellon/middleware.py b/mellon/middleware.py index a0b814a..8e79218 100644 --- a/mellon/middleware.py +++ b/mellon/middleware.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from django.utils.http import urlencode from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse diff --git a/mellon/models.py b/mellon/models.py index 9368a1d..62cf842 100644 --- a/mellon/models.py +++ b/mellon/models.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from django.db import models from django.utils.translation import ugettext_lazy as _ from django.conf import settings diff --git a/mellon/sessions_backends/cached_db.py b/mellon/sessions_backends/cached_db.py index 7e3aed0..b30a977 100644 --- a/mellon/sessions_backends/cached_db.py +++ b/mellon/sessions_backends/cached_db.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from django.contrib.sessions.backends.db import SessionStore from . import db diff --git a/mellon/sessions_backends/db.py b/mellon/sessions_backends/db.py index 9c89e86..a45eadf 100644 --- a/mellon/sessions_backends/db.py +++ b/mellon/sessions_backends/db.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from django.contrib.sessions.backends.db import SessionStore from mellon import utils diff --git a/mellon/utils.py b/mellon/utils.py index 1c48f1a..d50153b 100644 --- a/mellon/utils.py +++ b/mellon/utils.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import logging import datetime import importlib @@ -29,16 +44,16 @@ def create_metadata(request): public_keys.append(public_key) name_id_formats = app_settings.NAME_ID_FORMATS return render_to_string('mellon/metadata.xml', { - 'entity_id': request.build_absolute_uri(entity_id), - 'login_url': request.build_absolute_uri(login_url), - 'logout_url': request.build_absolute_uri(logout_url), - 'public_keys': public_keys, - 'name_id_formats': name_id_formats, - 'default_assertion_consumer_binding': app_settings.DEFAULT_ASSERTION_CONSUMER_BINDING, - 'organization': app_settings.ORGANIZATION, - 'contact_persons': app_settings.CONTACT_PERSONS, - 'discovery_endpoint_url': request.build_absolute_uri(reverse('mellon_login')), - }) + 'entity_id': request.build_absolute_uri(entity_id), + 'login_url': request.build_absolute_uri(login_url), + 'logout_url': request.build_absolute_uri(logout_url), + 'public_keys': public_keys, + 'name_id_formats': name_id_formats, + 'default_assertion_consumer_binding': app_settings.DEFAULT_ASSERTION_CONSUMER_BINDING, + 'organization': app_settings.ORGANIZATION, + 'contact_persons': app_settings.CONTACT_PERSONS, + 'discovery_endpoint_url': request.build_absolute_uri(reverse('mellon_login')), + }) def create_server(request): @@ -130,7 +145,7 @@ def iso8601_to_datetime(date_string, default=None): This function ignores the sub-second resolution''' try: dt = isodate.parse_datetime(date_string) - except: + except Exception: return default if is_aware(dt): if not settings.USE_TZ: @@ -209,7 +224,7 @@ def create_logout(request): def is_nonnull(s): - return not '\x00' in s + return '\x00' not in s def same_origin(url1, url2): @@ -244,6 +259,7 @@ def get_status_codes_and_message(profile): message = lasso_decode(status.statusMessage) return status_codes, message + def login(request, user): for adapter in get_adapters(): if hasattr(adapter, 'auth_login'): diff --git a/mellon/views.py b/mellon/views.py index 5a39adf..9a685e9 100644 --- a/mellon/views.py +++ b/mellon/views.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import logging import requests import lasso diff --git a/tests/conftest.py b/tests/conftest.py index bfa8788..9458b5f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import logging import pytest import django_webtest diff --git a/tests/test_default_adapter.py b/tests/test_default_adapter.py index 43c9064..7efe2f0 100644 --- a/tests/test_default_adapter.py +++ b/tests/test_default_adapter.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import pytest import re import lasso diff --git a/tests/test_sso_slo.py b/tests/test_sso_slo.py index 42ab8ef..fdd2087 100644 --- a/tests/test_sso_slo.py +++ b/tests/test_sso_slo.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import re import base64 import zlib diff --git a/tests/test_utils.py b/tests/test_utils.py index 8c4cf9c..b0f0b2b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import re import datetime diff --git a/tests/test_views.py b/tests/test_views.py index 014af86..6babf67 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import pytest import mock import lasso diff --git a/tests/urls_tests.py b/tests/urls_tests.py index d95e2c0..52500a4 100644 --- a/tests/urls_tests.py +++ b/tests/urls_tests.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import django from django.conf.urls import url, include diff --git a/tests/utils.py b/tests/utils.py index 388e6c0..d4b7883 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from httmock import all_requests, response diff --git a/tests/xml_utils.py b/tests/xml_utils.py index 670c6b4..a154f15 100644 --- a/tests/xml_utils.py +++ b/tests/xml_utils.py @@ -1,3 +1,18 @@ +# django-mellon - SAML2 authentication for Django +# Copyright (C) 2014-2019 Entr'ouvert +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from lxml import etree as ET