build cassé suite à mise à jour bookworm sur jenkins (#86402) #14

Merged
bdauvergne merged 3 commits from wip/86402-build-casse-suite-a-mise-a-jour into main 2024-02-01 10:49:52 +01:00
10 changed files with 41 additions and 37 deletions

View File

@ -1,5 +0,0 @@
[run]
dynamic_context = test_function
[html]
show_contexts = True

View File

@ -135,7 +135,7 @@ class DefaultAdapter:
logger.error('invalid METADATA_URL %r: %s', url, e)
return
if not hostname:
logger.error('no hostname in METADATA_URL %r: %s', url)
logger.error('no hostname in METADATA_URL %r', url)
return
try:
@ -359,8 +359,8 @@ class DefaultAdapter:
name_id=name_id, issuer=models_utils.get_issuer(entity_id)
)
# nid_* attributes are new, we must update them if they are not initialized, eventually
for key in to_update:
if getattr(saml_identifier, key) != to_update[key]:
for key, value in to_update.items():
if getattr(saml_identifier, key) != value:
models.UserSAMLIdentifier.objects.filter(pk=saml_identifier.pk).update(**to_update)
break
user = saml_identifier.user
@ -506,8 +506,8 @@ class DefaultAdapter:
},
)
# nid_* attributes are new, we must update them eventually
for key in to_update:
if getattr(saml_id, key) != to_update[key]:
for key, value in to_update.items():
if getattr(saml_id, key) != value:
models.UserSAMLIdentifier.objects.filter(pk=saml_id.pk).update(**to_update)
break
if created:
@ -531,7 +531,7 @@ class DefaultAdapter:
value = tpl.format(realm=realm, attributes=saml_attributes, idp=idp)
except ValueError:
logger.warning('mellon: invalid attribute mapping template %r', tpl)
except (AttributeError, KeyError, IndexError, ValueError) as e:
except (AttributeError, KeyError, IndexError) as e:
logger.warning('mellon: invalid reference in attribute mapping template %r: %s', tpl, e)
else:
model_field = user._meta.get_field(field)
@ -591,7 +591,7 @@ class DefaultAdapter:
groups = []
for value in set(values):
if create_group:
group, created = Group.objects.get_or_create(name=value)
group, _ = Group.objects.get_or_create(name=value)
else:
try:
group = Group.objects.get(name=value)

View File

@ -26,5 +26,5 @@ def get_issuer(entity_id):
issuer.entity_id = entity_id
issuer.save()
if not slug or not issuer:
issuer, created = models.Issuer.objects.update_or_create(entity_id=entity_id, defaults={'slug': slug})
issuer, _ = models.Issuer.objects.update_or_create(entity_id=entity_id, defaults={'slug': slug})
return issuer

View File

@ -13,10 +13,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.sessions.backends.db import SessionStore
from django.contrib.sessions.backends.cached_db import SessionStore as BaseSessionStore
from . import db
class SessionStore(db.SessionStore, SessionStore):
class SessionStore(db.SessionStore, BaseSessionStore):
pass

View File

@ -13,12 +13,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.sessions.backends.db import SessionStore
from django.contrib.sessions.backends.db import SessionStore as BaseSessionStore
from mellon import utils
class SessionStore(SessionStore):
class SessionStore(BaseSessionStore):
def get_session_not_on_or_after(self):
session_not_on_or_after = self.get('mellon_session', {}).get('session_not_on_or_after')
if session_not_on_or_after:

View File

@ -1,4 +1,3 @@
import django
from django.urls import path
from . import views

View File

@ -27,7 +27,6 @@ from django.conf import settings
from django.contrib import auth
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.encoding import force_str
from django.utils.timezone import get_default_timezone, is_aware, make_aware, make_naive, now
from . import app_settings
@ -47,7 +46,8 @@ def create_metadata(request):
for public_key in app_settings.PUBLIC_KEYS:
if public_key.startswith('/'):
# clean PEM file
content = open(public_key).read()
with open(public_key) as fd:
content = fd.read()
public_key = ''.join(content.splitlines()[1:-1])
public_keys.append(public_key)
name_id_formats = app_settings.NAME_ID_FORMATS
@ -191,7 +191,7 @@ def import_object(path):
@to_list
def get_adapters(idp={}, **kwargs):
def get_adapters(idp=None, **kwargs):
idp = idp or {}
adapters = tuple(idp.get('ADAPTER', ())) + tuple(app_settings.ADAPTER)
for adapter in adapters:

View File

@ -195,8 +195,7 @@ class LoginView(ProfileMixin, LogMixin, View):
if not entity_id:
for idp in utils.get_idps():
return idp
else:
return {}
return {}
else:
return utils.get_idp(entity_id)
@ -260,7 +259,7 @@ class LoginView(ProfileMixin, LogMixin, View):
content = self.get_attribute_value(at, attribute_value)
if content is not None:
values.append(content)
entity_id = attributes['issuer'] = login.remoteProviderId
attributes['issuer'] = login.remoteProviderId
in_response_to = login.response.inResponseTo
if in_response_to:
attributes['nonce'] = request.session.get('mellon-nonce-%s' % in_response_to)
@ -427,7 +426,7 @@ class LoginView(ProfileMixin, LogMixin, View):
self.log.warning('unable to reach %r: %s', login.msgUrl, e)
return self.failure(
request,
reason=_('IdP is temporarily down, please try again ' 'later.'),
reason=_('IdP is temporarily down, please try again later.'),
status_codes=status_codes,
)
if result.status_code != 200:
@ -712,7 +711,7 @@ class LogoutView(ProfileMixin, LogMixin, View):
try:
logout.validateRequest()
except lasso.Error as e:
self.log.warning('error validating logout request: %r' % e)
self.log.warning('error validating logout request: %s', e)
else:
if session_indexes:
self.log.info('logout requested for sessionIndexes %s', session_indexes)

View File

@ -1,7 +1,5 @@
#!/bin/sh
set -e -x
env
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
PYLINT_RC=/var/lib/jenkins/pylint.django.rc
elif [ -f pylint.django.rc ]; then

31
tox.ini
View File

@ -1,22 +1,21 @@
[tox]
envlist = code-style,py3-django{2,3}2-coverage
envlist = py3,code-style
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/django-mellon/
[testenv]
whitelist_externals =
/bin/mv
setenv =
DJANGO_SETTINGS_MODULE=testsettings
PYTHONPATH=.
SETUPTOOLS_USE_DISTUTILS=stdlib
DJANGO_SETTINGS_MODULE=testsettings
JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
COVERAGE={tty::--cov --cov-append --cov-report xml --cov-report html --cov-context=test --cov-config=tox.ini}
coverage: COVERAGE=--cov=mellon --cov-branch --cov-append --cov-report xml --cov-report html --cov-config .coveragerc
usedevelop =
coverage: true
deps =
django22: django>=2.2,<2.3
psycopg2-binary
django22: psycopg2-binary<2.9
django32: django>=3.2.12,<3.3
django>=3.2.12,<3.3
mock<4
httmock
pytest
@ -24,7 +23,7 @@ deps =
pytest-random
pytest-mock
pytest-django
pytest-freezegun
pytest-freezer
pytz
lxml
cssselect
@ -36,7 +35,7 @@ allowlist_externals =
./getlasso3.sh
commands =
./getlasso3.sh
py.test -o junit_suite_name={envname} --junit-xml=junit-{envname}.xml --random {env:COVERAGE:} {posargs:tests}
py.test {env:JUNIT:} {env:COVERAGE:} {posargs:tests}
[testenv:pylint]
basepython = python3
@ -44,7 +43,10 @@ deps =
pylint<3
astroid<3
pylint-django
psycopg2<2.9
psycopg2-binary
allowlist_externals =
./getlasso3.sh
./pylint.sh
commands =
./getlasso3.sh
./pylint.sh mellon
@ -57,6 +59,8 @@ setenv =
PYTHONPATH=.:tests
deps =
psycopg2-binary
allowlist_externals =
./getlasso3.sh
commands =
./getlasso3.sh
django-admin {posargs:--help}
@ -70,3 +74,12 @@ commands =
[pytest]
junit_family=legacy
[coverage:run]
source =
mellon
tests
branch = True
[coverage:html]
show_contexts = True