Projet

Général

Profil

0002-code-style-10196.patch

Benjamin Dauvergne, 18 juin 2019 00:53

Télécharger (18,4 ko)

Voir les différences:

Subject: [PATCH 2/3] code style (#10196)

 mellon/adapters.py                    | 19 +++++++++++--
 mellon/middleware.py                  | 15 ++++++++++
 mellon/models.py                      | 15 ++++++++++
 mellon/sessions_backends/cached_db.py | 15 ++++++++++
 mellon/sessions_backends/db.py        | 15 ++++++++++
 mellon/utils.py                       | 40 +++++++++++++++++++--------
 mellon/views.py                       | 15 ++++++++++
 tests/conftest.py                     | 15 ++++++++++
 tests/test_default_adapter.py         | 15 ++++++++++
 tests/test_sso_slo.py                 | 15 ++++++++++
 tests/test_utils.py                   | 15 ++++++++++
 tests/test_views.py                   | 15 ++++++++++
 tests/urls_tests.py                   | 15 ++++++++++
 tests/utils.py                        | 15 ++++++++++
 tests/xml_utils.py                    | 15 ++++++++++
 15 files changed, 240 insertions(+), 14 deletions(-)
mellon/adapters.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import logging
2 17
import uuid
3 18
from xml.etree import ElementTree as ET
......
76 91
                    self.logger.error(u'METADATA of %d-th idp has no EntityDescriptor root tag', i)
77 92
                    continue
78 93

  
79
                if not 'entityID' in doc.attrib:
94
                if 'entityID' not in doc.attrib:
80 95
                    self.logger.error(
81 96
                        u'METADATA of %d-th idp has no entityID attribute on its root tag', i)
82 97
                    continue
......
105 120
        except (AttributeError, KeyError, IndexError) as e:
106 121
            self.logger.error(
107 122
                u'invalid reference in username template %r: %s', username_template, e)
108
        except Exception as e:
123
        except Exception:
109 124
            self.logger.exception(u'unknown error when formatting username')
110 125
        else:
111 126
            return username
mellon/middleware.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
from django.utils.http import urlencode
2 17
from django.http import HttpResponseRedirect
3 18
from django.core.urlresolvers import reverse
mellon/models.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
from django.db import models
2 17
from django.utils.translation import ugettext_lazy as _
3 18
from django.conf import settings
mellon/sessions_backends/cached_db.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
from django.contrib.sessions.backends.db import SessionStore
2 17

  
3 18
from . import db
mellon/sessions_backends/db.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
from django.contrib.sessions.backends.db import SessionStore
2 17

  
3 18
from mellon import utils
mellon/utils.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import logging
2 17
import datetime
3 18
import importlib
......
29 44
        public_keys.append(public_key)
30 45
    name_id_formats = app_settings.NAME_ID_FORMATS
31 46
    return render_to_string('mellon/metadata.xml', {
32
            'entity_id': request.build_absolute_uri(entity_id),
33
            'login_url': request.build_absolute_uri(login_url),
34
            'logout_url': request.build_absolute_uri(logout_url),
35
            'public_keys': public_keys,
36
            'name_id_formats': name_id_formats,
37
            'default_assertion_consumer_binding': app_settings.DEFAULT_ASSERTION_CONSUMER_BINDING,
38
            'organization': app_settings.ORGANIZATION,
39
            'contact_persons': app_settings.CONTACT_PERSONS,
40
            'discovery_endpoint_url': request.build_absolute_uri(reverse('mellon_login')),
41
        })
47
        'entity_id': request.build_absolute_uri(entity_id),
48
        'login_url': request.build_absolute_uri(login_url),
49
        'logout_url': request.build_absolute_uri(logout_url),
50
        'public_keys': public_keys,
51
        'name_id_formats': name_id_formats,
52
        'default_assertion_consumer_binding': app_settings.DEFAULT_ASSERTION_CONSUMER_BINDING,
53
        'organization': app_settings.ORGANIZATION,
54
        'contact_persons': app_settings.CONTACT_PERSONS,
55
        'discovery_endpoint_url': request.build_absolute_uri(reverse('mellon_login')),
56
    })
42 57

  
43 58

  
44 59
def create_server(request):
......
130 145
       This function ignores the sub-second resolution'''
131 146
    try:
132 147
        dt = isodate.parse_datetime(date_string)
133
    except:
148
    except Exception:
134 149
        return default
135 150
    if is_aware(dt):
136 151
        if not settings.USE_TZ:
......
209 224

  
210 225

  
211 226
def is_nonnull(s):
212
    return not '\x00' in s
227
    return '\x00' not in s
213 228

  
214 229

  
215 230
def same_origin(url1, url2):
......
244 259
        message = lasso_decode(status.statusMessage)
245 260
    return status_codes, message
246 261

  
262

  
247 263
def login(request, user):
248 264
    for adapter in get_adapters():
249 265
        if hasattr(adapter, 'auth_login'):
mellon/views.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import logging
2 17
import requests
3 18
import lasso
tests/conftest.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import logging
2 17
import pytest
3 18
import django_webtest
tests/test_default_adapter.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import pytest
2 17
import re
3 18
import lasso
tests/test_sso_slo.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import re
2 17
import base64
3 18
import zlib
tests/test_utils.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import re
2 17
import datetime
3 18

  
tests/test_views.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import pytest
2 17
import mock
3 18
import lasso
tests/urls_tests.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
import django
2 17

  
3 18
from django.conf.urls import url, include
tests/utils.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
from httmock import all_requests, response
2 17

  
3 18

  
tests/xml_utils.py
1
# django-mellon - SAML2 authentication for Django
2
# Copyright (C) 2014-2019 Entr'ouvert
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as
5
# published by the Free Software Foundation, either version 3 of the
6
# License, or (at your option) any later version.
7

  
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12

  
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

  
1 16
from lxml import etree as ET
2 17

  
3 18

  
4
-