0005-auth_saml-lookup-by-attributes-using-model-67025.patch
src/authentic2_auth_saml/models.py | ||
---|---|---|
191 | 191 |
if not settings[setting]: |
192 | 192 |
del settings[setting] |
193 | 193 | |
194 |
settings['LOOKUP_BY_ATTRIBUTES'] = [lookup.as_dict() for lookup in self.attribute_lookups.all()] |
|
195 | ||
194 | 196 |
settings['authenticator'] = self |
195 | 197 |
return settings |
196 | 198 | |
... | ... | |
231 | 233 |
class Meta: |
232 | 234 |
verbose_name = _('Attribute lookup') |
233 | 235 | |
236 |
def as_dict(self): |
|
237 |
return { |
|
238 |
'user_field': self.user_field, |
|
239 |
'saml_attribute': self.saml_attribute, |
|
240 |
'ignore-case': self.ignore_case, |
|
241 |
} |
|
242 | ||
234 | 243 |
class RenameAttributeAction(models.Model): |
235 | 244 |
authenticator = models.ForeignKey(SAMLAuthenticator, on_delete=models.CASCADE) |
236 | 245 |
from_name = models.CharField(_('From'), max_length=128) |
tests/test_auth_saml.py | ||
---|---|---|
31 | 31 |
from authentic2_auth_saml.models import ( |
32 | 32 |
AddRoleAction, |
33 | 33 |
RenameAttributeAction, |
34 |
SAMLAttributeLookup, |
|
34 | 35 |
SAMLAuthenticator, |
35 | 36 |
SetAttributeAction, |
36 | 37 |
) |
... | ... | |
363 | 364 |
assert authenticator.settings['AUTHN_CLASSREF'] == [] |
364 | 365 |
assert authenticator.settings['LOGIN_HINTS'] == [] |
365 | 366 | |
367 |
SAMLAttributeLookup.objects.create( |
|
368 |
authenticator=authenticator, |
|
369 |
user_field='email', |
|
370 |
saml_attribute='mail', |
|
371 |
) |
|
372 |
assert authenticator.settings['LOOKUP_BY_ATTRIBUTES'] == [ |
|
373 |
{'saml_attribute': 'mail', 'user_field': 'email', 'ignore-case': False} |
|
374 |
] |
|
375 | ||
366 | 376 | |
367 | 377 |
def test_saml_authenticator_data_migration(migration, settings): |
368 | 378 |
app = 'authentic2_auth_saml' |
369 |
- |