Projet

Général

Profil

0001-auth_saml-remove-login-hints-field-68223.patch

Valentin Deniaud, 17 août 2022 17:33

Télécharger (3,62 ko)

Voir les différences:

Subject: [PATCH] auth_saml: remove login hints field (#68223)

 ...0004_remove_samlauthenticator_login_hints.py | 17 +++++++++++++++++
 src/authentic2_auth_saml/models.py              |  6 +-----
 tests/test_auth_saml.py                         |  5 +----
 3 files changed, 19 insertions(+), 9 deletions(-)
 create mode 100644 src/authentic2_auth_saml/migrations/0004_remove_samlauthenticator_login_hints.py
src/authentic2_auth_saml/migrations/0004_remove_samlauthenticator_login_hints.py
1
# Generated by Django 2.2.26 on 2022-08-17 15:31
2

  
3
from django.db import migrations
4

  
5

  
6
class Migration(migrations.Migration):
7

  
8
    dependencies = [
9
        ('authentic2_auth_saml', '0003_auto_20220726_1713'),
10
    ]
11

  
12
    operations = [
13
        migrations.RemoveField(
14
            model_name='samlauthenticator',
15
            name='login_hints',
16
        ),
17
    ]
src/authentic2_auth_saml/models.py
121 121
        ),
122 122
        blank=True,
123 123
    )
124
    login_hints = models.CharField(
125
        _('Login hints'), max_length=512, help_text=_('Comma separated list.'), blank=True
126
    )
127 124
    lookup_by_attributes = JSONField(
128 125
        _('Lookup by attributes'),
129 126
        default=list,
......
183 180
    def settings(self):
184 181
        settings = {k.upper(): v for k, v in self.__dict__.items()}
185 182

  
186
        for setting in ('AUTHN_CLASSREF', 'LOGIN_HINTS'):
187
            settings[setting] = [x.strip() for x in settings[setting].split(',') if x.strip()]
183
        settings['AUTHN_CLASSREF'] = [x.strip() for x in settings['AUTHN_CLASSREF'].split(',') if x.strip()]
188 184

  
189 185
        for setting in ('METADATA', 'METADATA_PATH', 'METADATA_URL'):
190 186
            if not settings[setting]:
tests/test_auth_saml.py
340 340

  
341 341
def test_saml_authenticator_settings(db):
342 342
    authenticator = SAMLAuthenticator.objects.create(
343
        enabled=True, metadata='meta1.xml', slug='idp1', authn_classref='a, b', login_hints='b , c'
343
        enabled=True, metadata='meta1.xml', slug='idp1', authn_classref='a, b'
344 344
    )
345 345

  
346 346
    assert 'METADATA' in authenticator.settings
347 347
    assert 'METADATA_PATH' not in authenticator.settings
348 348
    assert 'METADATA_URL' not in authenticator.settings
349 349
    assert authenticator.settings['AUTHN_CLASSREF'] == ['a', 'b']
350
    assert authenticator.settings['LOGIN_HINTS'] == ['b', 'c']
351 350

  
352 351
    authenticator.metadata = ''
353 352
    authenticator.metadata_path = '/some/path/metadata.xml'
......
358 357
    assert 'METADATA_URL' not in authenticator.settings
359 358

  
360 359
    authenticator.authn_classref = ''
361
    authenticator.login_hints = ', '
362 360
    authenticator.save()
363 361

  
364 362
    assert authenticator.settings['AUTHN_CLASSREF'] == []
365
    assert authenticator.settings['LOGIN_HINTS'] == []
366 363

  
367 364

  
368 365
def test_saml_authenticator_data_migration(migration, settings):
369
-