From cab9327d47aed43783dc3885e54dd2e90a0c703a Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 26 Jul 2022 17:29:40 +0200 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 diff --git a/src/authentic2_auth_oidc/migrations/0013_auto_20220726_1714.py b/src/authentic2_auth_oidc/migrations/0013_auto_20220726_1714.py new file mode 100644 index 00000000..e38be280 --- /dev/null +++ b/src/authentic2_auth_oidc/migrations/0013_auto_20220726_1714.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.26 on 2022-07-26 15:14 + +from django.db import migrations +from django.db.models import F + + +def set_default_button_label(apps, schema_editor): + OIDCProvider = apps.get_model('authentic2_auth_oidc', 'OIDCProvider') + OIDCProvider.objects.update(button_label=F('name')) + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentic2_auth_oidc', '0012_auto_20220524_1147'), + ('authenticators', '0004_auto_20220726_1708'), + ] + + operations = [ + migrations.RunPython(set_default_button_label, reverse_code=migrations.RunPython.noop), + ] diff --git a/src/authentic2_auth_oidc/templates/authentic2_auth_oidc/login.html b/src/authentic2_auth_oidc/templates/authentic2_auth_oidc/login.html index 92350091..733eb0af 100644 --- a/src/authentic2_auth_oidc/templates/authentic2_auth_oidc/login.html +++ b/src/authentic2_auth_oidc/templates/authentic2_auth_oidc/login.html @@ -1,6 +1,11 @@ {% block login %} + +{% if provider.button_description %} +

{{ provider.button_description }}

+{% endif %} +

{{ provider.name }} + href="{{ login_url }}" class="pk-button">{{ provider.button_label }}

{% endblock %} diff --git a/tests/test_auth_oidc.py b/tests/test_auth_oidc.py index 22325053..83735e24 100644 --- a/tests/test_auth_oidc.py +++ b/tests/test_auth_oidc.py @@ -181,6 +181,7 @@ def make_oidc_provider( jwkset_json=jwkset, idtoken_algo=idtoken_algo, claims_parameter_supported=claims_parameter_supported, + button_label=name, ) provider.full_clean() OIDCClaimMapping.objects.create(provider=provider, claim='sub', attribute='username', idtoken_claim=True) @@ -418,12 +419,17 @@ def test_providers_on_login_page(oidc_provider, app): jwkset_json=None, idtoken_algo=OIDCProvider.ALGO_RSA, claims_parameter_supported=False, + button_label='Test label', + button_description='This is a test.', ) response = app.get('/login/') assert response.pyquery('p#oidc-p-server') assert response.pyquery('p#oidc-p-oidcidp-2') + assert 'Test label' in response.text + assert 'This is a test.' in response.text + def test_login_with_conditional_authenticators(oidc_provider, oidc_provider_jwkset, app, settings, caplog): myidp = make_oidc_provider(name='My IDP', slug='myidp', jwkset=oidc_provider_jwkset) diff --git a/tests/test_manager_authenticators.py b/tests/test_manager_authenticators.py index 0eac00b6..da272295 100644 --- a/tests/test_manager_authenticators.py +++ b/tests/test_manager_authenticators.py @@ -132,6 +132,8 @@ def test_authenticators_oidc(app, superuser, ou1, ou2): resp.form['token_endpoint'] = 'https://oidc.example.com/token' resp.form['userinfo_endpoint'] = 'https://oidc.example.com/user_info' resp.form['idtoken_algo'] = 2 + resp.form['button_label'] = 'Test' + resp.form['button_description'] = 'test' resp = resp.form.submit().follow() assert_event('authenticator.edit', user=superuser, session=app.session) @@ -151,8 +153,8 @@ def test_authenticators_oidc(app, superuser, ou1, ou2): resp = resp.click('Journal') assert 'enable' in resp.text assert ( - 'edit (ou, issuer, scopes, strategy, idtoken_algo, token_endpoint, userinfo_endpoint, authorization_endpoint)' - in resp.text + 'edit (ou, issuer, scopes, strategy, button_label, idtoken_algo, token_endpoint, ' + 'userinfo_endpoint, button_description, authorization_endpoint)' in resp.text ) assert 'creation' in resp.text -- 2.30.2