summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-25 08:20:03 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-04-05 12:31:45 (GMT)
commit24e85adc5a7a4ac3b82f9b33a44fefd0141ae7a6 (patch)
treebcda82aa3bdaf4fd068f654993ffec1c6eaf7339
parent401b65f8b34826f557f953a1ba384bec1b3d7f22 (diff)
downloaddjango-mellon-24e85adc5a7a4ac3b82f9b33a44fefd0141ae7a6.zip
django-mellon-24e85adc5a7a4ac3b82f9b33a44fefd0141ae7a6.tar.gz
django-mellon-24e85adc5a7a4ac3b82f9b33a44fefd0141ae7a6.tar.bz2
python3: handle differences in lasso/py2/py3 encodings
-rw-r--r--mellon/utils.py6
-rw-r--r--mellon/views.py18
2 files changed, 16 insertions, 8 deletions
diff --git a/mellon/utils.py b/mellon/utils.py
index 30f5970..524f402 100644
--- a/mellon/utils.py
+++ b/mellon/utils.py
@@ -228,16 +228,18 @@ def get_status_codes_and_message(profile):
assert profile.response, 'missing response in profile'
assert profile.response.status, 'missing status in response'
+ from .views import lasso_decode
+
status_codes = []
status = profile.response.status
a = status
while a.statusCode:
- status_codes.append(a.statusCode.value.decode('utf-8'))
+ status_codes.append(lasso_decode(a.statusCode.value))
a = a.statusCode
message = None
if status.statusMessage:
- message = status.statusMessage.decode('utf-8')
+ message = lasso_decode(status.statusMessage)
return status_codes, message
def login(request, user):
diff --git a/mellon/views.py b/mellon/views.py
index f77b8ff..76be9ed 100644
--- a/mellon/views.py
+++ b/mellon/views.py
@@ -13,6 +13,7 @@ from django.conf import settings
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.contrib.auth import REDIRECT_FIELD_NAME
from django.db import transaction
from django.utils.translation import ugettext as _
@@ -22,6 +23,11 @@ from . import app_settings, utils
lasso.setFlag('thin-sessions')
+if six.PY3:
+ lasso_decode = lambda x: x
+else:
+ lasso_decode = lambda x: x.decode('utf-8')
+
class LogMixin(object):
"""Initialize a module logger in new objects"""
@@ -157,20 +163,20 @@ class LoginView(ProfileMixin, LogMixin, View):
for value in at.attributeValue:
content = [any.exportToXml() for any in value.any]
content = ''.join(content)
- values.append(content.decode('utf8'))
+ values.append(lasso_decode(content))
attributes['issuer'] = login.remoteProviderId
if login.nameIdentifier:
name_id = login.nameIdentifier
- name_id_format = unicode(name_id.format
+ name_id_format = six.u(name_id.format
or lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED)
attributes.update({
- 'name_id_content': name_id.content.decode('utf8'),
+ 'name_id_content': lasso_decode(name_id.content),
'name_id_format': name_id_format
})
if name_id.nameQualifier:
- attributes['name_id_name_qualifier'] = unicode(name_id.nameQualifier)
+ attributes['name_id_name_qualifier'] = six.u(name_id.nameQualifier)
if name_id.spNameQualifier:
- attributes['name_id_sp_name_qualifier'] = unicode(name_id.spNameQualifier)
+ attributes['name_id_sp_name_qualifier'] = six.u(name_id.spNameQualifier)
authn_statement = login.assertion.authnStatement[0]
if authn_statement.authnInstant:
attributes['authn_instant'] = utils.iso8601_to_datetime(authn_statement.authnInstant)
@@ -302,7 +308,7 @@ class LoginView(ProfileMixin, LogMixin, View):
a = a.statusCode
args = ['SAML authentication failed: status is not success codes: %r', status_codes]
if status.statusMessage:
- idp_message = status.statusMessage.decode('utf-8')
+ idp_message = lasso_decode(status.statusMessage)
args[0] += ' message: %r'
args.append(status.statusMessage)
self.log.warning(*args)