0001-use-force_text-for-python2-3-compatibility-24139.patch
mellon/adapters.py | ||
---|---|---|
10 | 10 |
from django.contrib import auth |
11 | 11 |
from django.contrib.auth.models import Group |
12 | 12 |
from django.utils import six |
13 |
from django.utils.encoding import force_text |
|
13 | 14 | |
14 | 15 |
from . import utils, app_settings, models |
15 | 16 | |
... | ... | |
83 | 84 |
realm = utils.get_setting(idp, 'REALM') |
84 | 85 |
username_template = utils.get_setting(idp, 'USERNAME_TEMPLATE') |
85 | 86 |
try: |
86 |
username = six.u(username_template).format(
|
|
87 |
username = force_text(username_template).format(
|
|
87 | 88 |
realm=realm, attributes=saml_attributes, idp=idp)[:30] |
88 | 89 |
except ValueError: |
89 | 90 |
self.logger.error(u'invalid username template %r', username_template) |
... | ... | |
161 | 162 |
attribute_set = False |
162 | 163 |
for field, tpl in attribute_mapping.items(): |
163 | 164 |
try: |
164 |
value = six.u(tpl).format(realm=realm, attributes=saml_attributes, idp=idp)
|
|
165 |
value = force_text(tpl).format(realm=realm, attributes=saml_attributes, idp=idp)
|
|
165 | 166 |
except ValueError: |
166 | 167 |
self.logger.warning(u'invalid attribute mapping template %r', tpl) |
167 | 168 |
except (AttributeError, KeyError, IndexError, ValueError) as e: |
mellon/views.py | ||
---|---|---|
14 | 14 |
from django.shortcuts import render, resolve_url |
15 | 15 |
from django.utils.http import urlencode |
16 | 16 |
from django.utils import six |
17 |
from django.utils.encoding import force_text |
|
17 | 18 |
from django.contrib.auth import REDIRECT_FIELD_NAME |
18 | 19 |
from django.db import transaction |
19 | 20 |
from django.utils.translation import ugettext as _ |
... | ... | |
167 | 168 |
attributes['issuer'] = login.remoteProviderId |
168 | 169 |
if login.nameIdentifier: |
169 | 170 |
name_id = login.nameIdentifier |
170 |
name_id_format = six.u(name_id.format
|
|
171 |
name_id_format = force_text(name_id.format
|
|
171 | 172 |
or lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED) |
172 | 173 |
attributes.update({ |
173 | 174 |
'name_id_content': lasso_decode(name_id.content), |
174 | 175 |
'name_id_format': name_id_format |
175 | 176 |
}) |
176 | 177 |
if name_id.nameQualifier: |
177 |
attributes['name_id_name_qualifier'] = six.u(name_id.nameQualifier)
|
|
178 |
attributes['name_id_name_qualifier'] = force_text(name_id.nameQualifier)
|
|
178 | 179 |
if name_id.spNameQualifier: |
179 |
attributes['name_id_sp_name_qualifier'] = six.u(name_id.spNameQualifier)
|
|
180 |
attributes['name_id_sp_name_qualifier'] = force_text(name_id.spNameQualifier)
|
|
180 | 181 |
authn_statement = login.assertion.authnStatement[0] |
181 | 182 |
if authn_statement.authnInstant: |
182 | 183 |
attributes['authn_instant'] = utils.iso8601_to_datetime(authn_statement.authnInstant) |
tests/test_default_adapter.py | ||
---|---|---|
77 | 77 |
def test_provision_user_attributes(settings, django_user_model, caplog): |
78 | 78 |
settings.MELLON_IDENTITY_PROVIDERS = [idp] |
79 | 79 |
settings.MELLON_ATTRIBUTE_MAPPING = { |
80 |
'email': '{attributes[email][0]}', |
|
81 |
'first_name': '{attributes[first_name][0]}', |
|
82 |
'last_name': '{attributes[last_name][0]}', |
|
80 |
'email': u'{attributes[email][0]}',
|
|
81 |
'first_name': u'{attributes[first_name][0]}',
|
|
82 |
'last_name': u'{attributes[last_name][0]}',
|
|
83 | 83 |
} |
84 | 84 |
user = SAMLBackend().authenticate(saml_attributes=saml_attributes) |
85 | 85 |
assert user.username == 'x' * 30 |
86 |
- |