auth_saml: rename user attribute field for consistency (#68384)
This commit is contained in:
parent
99236eafe1
commit
e26211af52
|
@ -138,7 +138,7 @@ class AuthenticAdapter(DefaultAdapter):
|
|||
if action.saml_attribute not in saml_attributes:
|
||||
raise MappingError(_('unknown saml_attribute (%s)') % action.saml_attribute)
|
||||
|
||||
attribute = action.attribute
|
||||
attribute = action.user_field
|
||||
value = saml_attributes[action.saml_attribute]
|
||||
if isinstance(value, list):
|
||||
if len(value) == 0:
|
||||
|
|
|
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
|
|||
'id',
|
||||
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
('attribute', models.CharField(max_length=256, verbose_name='User attribute name')),
|
||||
('attribute', models.CharField(max_length=256, verbose_name='User field')),
|
||||
('saml_attribute', models.CharField(max_length=1024, verbose_name='SAML attribute name')),
|
||||
(
|
||||
'mandatory',
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.26 on 2022-09-13 09:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentic2_auth_saml', '0007_remove_jsonfields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='setattributeaction',
|
||||
old_name='attribute',
|
||||
new_name='user_field',
|
||||
),
|
||||
]
|
|
@ -250,7 +250,7 @@ class SAMLAttributeLookup(SAMLRelatedObjectBase):
|
|||
|
||||
|
||||
class SetAttributeAction(SAMLRelatedObjectBase):
|
||||
attribute = models.CharField(_('User attribute name'), max_length=256)
|
||||
user_field = models.CharField(_('User field'), max_length=256)
|
||||
saml_attribute = models.CharField(_('SAML attribute name'), max_length=1024)
|
||||
mandatory = models.BooleanField(_('Mandatory'), default=False, help_text=_('Deny login if action fails.'))
|
||||
|
||||
|
@ -260,7 +260,7 @@ class SetAttributeAction(SAMLRelatedObjectBase):
|
|||
|
||||
def __str__(self):
|
||||
label = _('"%(attribute)s" from "%(saml_attribute)s"') % {
|
||||
'attribute': self.attribute,
|
||||
'attribute': self.user_field,
|
||||
'saml_attribute': self.saml_attribute,
|
||||
}
|
||||
if self.mandatory:
|
||||
|
|
|
@ -87,18 +87,18 @@ def idp(db):
|
|||
)
|
||||
SetAttributeAction.objects.create(
|
||||
authenticator=authenticator,
|
||||
attribute='email',
|
||||
user_field='email',
|
||||
saml_attribute='mail',
|
||||
mandatory=True,
|
||||
)
|
||||
SetAttributeAction.objects.create(
|
||||
authenticator=authenticator,
|
||||
attribute='title',
|
||||
user_field='title',
|
||||
saml_attribute='title',
|
||||
)
|
||||
SetAttributeAction.objects.create(
|
||||
authenticator=authenticator,
|
||||
attribute='first_name',
|
||||
user_field='first_name',
|
||||
saml_attribute='first_name',
|
||||
)
|
||||
RenameAttributeAction.objects.create(
|
||||
|
@ -164,7 +164,7 @@ def test_apply_attribute_mapping_missing_attribute_exception(
|
|||
adapter, idp, saml_attributes, title_attribute, user, rf
|
||||
):
|
||||
saml_attributes['http://nice/attribute/givenName'] = []
|
||||
SetAttributeAction.objects.filter(attribute='first_name').update(mandatory=True)
|
||||
SetAttributeAction.objects.filter(user_field='first_name').update(mandatory=True)
|
||||
with pytest.raises(MappingError, match='no value'):
|
||||
adapter.provision_a2_attributes(user, idp, saml_attributes)
|
||||
|
||||
|
|
|
@ -351,7 +351,7 @@ def test_authenticators_saml_set_attribute(app, superuser):
|
|||
resp = login(app, superuser, path=authenticator.get_absolute_url())
|
||||
|
||||
resp = resp.click('Add', href='setattributeaction')
|
||||
resp.form['attribute'] = 'email'
|
||||
resp.form['user_field'] = 'email'
|
||||
resp.form['saml_attribute'] = 'mail'
|
||||
resp = resp.form.submit().follow()
|
||||
assert escape('"email" from "mail"') in resp.text
|
||||
|
|
Loading…
Reference in New Issue