summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-05-29 10:21:13 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-05-29 10:21:13 (GMT)
commitedb09ed8fd9fafc68e0369ad9a6cf1ba101f7782 (patch)
treecf28f1f949e8265d42b54bbe11154b96eea578ff
parent9498e35cf4ba530b523ab2b6d8ba4f48ab456d6d (diff)
downloaddjango-mellon-edb09ed8fd9fafc68e0369ad9a6cf1ba101f7782.zip
django-mellon-edb09ed8fd9fafc68e0369ad9a6cf1ba101f7782.tar.gz
django-mellon-edb09ed8fd9fafc68e0369ad9a6cf1ba101f7782.tar.bz2
use force_text for python2/3 compatibility (#24139)v1.2.36
-rw-r--r--mellon/adapters.py5
-rw-r--r--mellon/views.py7
-rw-r--r--tests/test_default_adapter.py6
3 files changed, 10 insertions, 8 deletions
diff --git a/mellon/adapters.py b/mellon/adapters.py
index e7bdece..460d1a6 100644
--- a/mellon/adapters.py
+++ b/mellon/adapters.py
@@ -10,6 +10,7 @@ from django.core.exceptions import PermissionDenied
from django.contrib import auth
from django.contrib.auth.models import Group
from django.utils import six
+from django.utils.encoding import force_text
from . import utils, app_settings, models
@@ -83,7 +84,7 @@ class DefaultAdapter(object):
realm = utils.get_setting(idp, 'REALM')
username_template = utils.get_setting(idp, 'USERNAME_TEMPLATE')
try:
- username = six.u(username_template).format(
+ username = force_text(username_template).format(
realm=realm, attributes=saml_attributes, idp=idp)[:30]
except ValueError:
self.logger.error(u'invalid username template %r', username_template)
@@ -161,7 +162,7 @@ class DefaultAdapter(object):
attribute_set = False
for field, tpl in attribute_mapping.items():
try:
- value = six.u(tpl).format(realm=realm, attributes=saml_attributes, idp=idp)
+ value = force_text(tpl).format(realm=realm, attributes=saml_attributes, idp=idp)
except ValueError:
self.logger.warning(u'invalid attribute mapping template %r', tpl)
except (AttributeError, KeyError, IndexError, ValueError) as e:
diff --git a/mellon/views.py b/mellon/views.py
index 263fbad..f4ee9f7 100644
--- a/mellon/views.py
+++ b/mellon/views.py
@@ -14,6 +14,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render, resolve_url
from django.utils.http import urlencode
from django.utils import six
+from django.utils.encoding import force_text
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.db import transaction
from django.utils.translation import ugettext as _
@@ -167,16 +168,16 @@ class LoginView(ProfileMixin, LogMixin, View):
attributes['issuer'] = login.remoteProviderId
if login.nameIdentifier:
name_id = login.nameIdentifier
- name_id_format = six.u(name_id.format
+ name_id_format = force_text(name_id.format
or lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED)
attributes.update({
'name_id_content': lasso_decode(name_id.content),
'name_id_format': name_id_format
})
if name_id.nameQualifier:
- attributes['name_id_name_qualifier'] = six.u(name_id.nameQualifier)
+ attributes['name_id_name_qualifier'] = force_text(name_id.nameQualifier)
if name_id.spNameQualifier:
- attributes['name_id_sp_name_qualifier'] = six.u(name_id.spNameQualifier)
+ attributes['name_id_sp_name_qualifier'] = force_text(name_id.spNameQualifier)
authn_statement = login.assertion.authnStatement[0]
if authn_statement.authnInstant:
attributes['authn_instant'] = utils.iso8601_to_datetime(authn_statement.authnInstant)
diff --git a/tests/test_default_adapter.py b/tests/test_default_adapter.py
index d52b432..1b891bf 100644
--- a/tests/test_default_adapter.py
+++ b/tests/test_default_adapter.py
@@ -77,9 +77,9 @@ def test_lookup_user_transaction(transactional_db, concurrency):
def test_provision_user_attributes(settings, django_user_model, caplog):
settings.MELLON_IDENTITY_PROVIDERS = [idp]
settings.MELLON_ATTRIBUTE_MAPPING = {
- 'email': '{attributes[email][0]}',
- 'first_name': '{attributes[first_name][0]}',
- 'last_name': '{attributes[last_name][0]}',
+ 'email': u'{attributes[email][0]}',
+ 'first_name': u'{attributes[first_name][0]}',
+ 'last_name': u'{attributes[last_name][0]}',
}
user = SAMLBackend().authenticate(saml_attributes=saml_attributes)
assert user.username == 'x' * 30