Projet

Général

Profil

0002-auth_oidc-use-login-form-customization-fields-51363.patch

Valentin Deniaud, 27 juillet 2022 10:57

Télécharger (4,59 ko)

Voir les différences:

Subject: [PATCH 2/4] auth_oidc: use login form customization fields (#51363)

 .../migrations/0013_auto_20220726_1714.py     | 21 +++++++++++++++++++
 .../templates/authentic2_auth_oidc/login.html |  7 ++++++-
 tests/test_auth_oidc.py                       |  6 ++++++
 tests/test_manager_authenticators.py          |  6 ++++--
 4 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 src/authentic2_auth_oidc/migrations/0013_auto_20220726_1714.py
src/authentic2_auth_oidc/migrations/0013_auto_20220726_1714.py
1
# Generated by Django 2.2.26 on 2022-07-26 15:14
2

  
3
from django.db import migrations
4
from django.db.models import F
5

  
6

  
7
def set_default_button_label(apps, schema_editor):
8
    OIDCProvider = apps.get_model('authentic2_auth_oidc', 'OIDCProvider')
9
    OIDCProvider.objects.update(button_label=F('name'))
10

  
11

  
12
class Migration(migrations.Migration):
13

  
14
    dependencies = [
15
        ('authentic2_auth_oidc', '0012_auto_20220524_1147'),
16
        ('authenticators', '0004_auto_20220726_1708'),
17
    ]
18

  
19
    operations = [
20
        migrations.RunPython(set_default_button_label, reverse_code=migrations.RunPython.noop),
21
    ]
src/authentic2_auth_oidc/templates/authentic2_auth_oidc/login.html
1 1
{% block login %}
2

  
3
{% if provider.button_description %}
4
<p>{{ provider.button_description }}</p>
5
{% endif %}
6

  
2 7
<p id="oidc-p-{% firstof provider.slug provider.name|slugify %}">
3 8
  <a id="oidc-a-{% firstof provider.slug  provider.name|slugify %}"
4
     href="{{ login_url }}">{{ provider.name }}</a>
9
     href="{{ login_url }}" class="pk-button">{{ provider.button_label }}</a>
5 10
</p>
6 11
{% endblock %}
tests/test_auth_oidc.py
181 181
        jwkset_json=jwkset,
182 182
        idtoken_algo=idtoken_algo,
183 183
        claims_parameter_supported=claims_parameter_supported,
184
        button_label=name,
184 185
    )
185 186
    provider.full_clean()
186 187
    OIDCClaimMapping.objects.create(provider=provider, claim='sub', attribute='username', idtoken_claim=True)
......
418 419
        jwkset_json=None,
419 420
        idtoken_algo=OIDCProvider.ALGO_RSA,
420 421
        claims_parameter_supported=False,
422
        button_label='Test label',
423
        button_description='This is a test.',
421 424
    )
422 425

  
423 426
    response = app.get('/login/')
424 427
    assert response.pyquery('p#oidc-p-server')
425 428
    assert response.pyquery('p#oidc-p-oidcidp-2')
426 429

  
430
    assert 'Test label' in response.text
431
    assert 'This is a test.' in response.text
432

  
427 433

  
428 434
def test_login_with_conditional_authenticators(oidc_provider, oidc_provider_jwkset, app, settings, caplog):
429 435
    myidp = make_oidc_provider(name='My IDP', slug='myidp', jwkset=oidc_provider_jwkset)
tests/test_manager_authenticators.py
132 132
    resp.form['token_endpoint'] = 'https://oidc.example.com/token'
133 133
    resp.form['userinfo_endpoint'] = 'https://oidc.example.com/user_info'
134 134
    resp.form['idtoken_algo'] = 2
135
    resp.form['button_label'] = 'Test'
136
    resp.form['button_description'] = 'test'
135 137
    resp = resp.form.submit().follow()
136 138
    assert_event('authenticator.edit', user=superuser, session=app.session)
137 139

  
......
151 153
    resp = resp.click('Journal')
152 154
    assert 'enable' in resp.text
153 155
    assert (
154
        'edit (ou, issuer, scopes, strategy, idtoken_algo, token_endpoint, userinfo_endpoint, authorization_endpoint)'
155
        in resp.text
156
        'edit (ou, issuer, scopes, strategy, button_label, idtoken_algo, token_endpoint, '
157
        'userinfo_endpoint, button_description, authorization_endpoint)' in resp.text
156 158
    )
157 159
    assert 'creation' in resp.text
158 160

  
159
-