Projet

Général

Profil

0005-auth_saml-lookup-by-attributes-using-model-67025.patch

Valentin Deniaud, 17 août 2022 11:43

Télécharger (2,35 ko)

Voir les différences:

Subject: [PATCH 5/8] auth_saml: lookup by attributes using model (#67025)

 src/authentic2_auth_saml/models.py |  9 +++++++++
 tests/test_auth_saml.py            | 10 ++++++++++
 2 files changed, 19 insertions(+)
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

  
......
248 250
        default_related_name = 'attribute_lookups'
249 251
        verbose_name = _('Attribute lookup')
250 252

  
253
    def as_dict(self):
254
        return {
255
            'user_field': self.user_field,
256
            'saml_attribute': self.saml_attribute,
257
            'ignore-case': self.ignore_case,
258
        }
259

  
251 260

  
252 261
class SetAttributeAction(SAMLRelatedObjectBase):
253 262
    attribute = models.CharField(_('User attribute name'), max_length=256)
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
)
......
330 331
    assert authenticator.settings['AUTHN_CLASSREF'] == []
331 332
    assert authenticator.settings['LOGIN_HINTS'] == []
332 333

  
334
    SAMLAttributeLookup.objects.create(
335
        authenticator=authenticator,
336
        user_field='email',
337
        saml_attribute='mail',
338
    )
339
    assert authenticator.settings['LOOKUP_BY_ATTRIBUTES'] == [
340
        {'saml_attribute': 'mail', 'user_field': 'email', 'ignore-case': False}
341
    ]
342

  
333 343

  
334 344
def test_saml_authenticator_data_migration(migration, settings):
335 345
    app = 'authentic2_auth_saml'
336
-