From d4fd7173eb18b22d86f85799cc50990dbde96569 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 16 May 2019 18:13:18 +0200 Subject: [PATCH] show change password link after user unlink (fixes #32953) --- src/authentic2_auth_fc/__init__.py | 7 ++++--- tests/test_auth_fc.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/authentic2_auth_fc/__init__.py b/src/authentic2_auth_fc/__init__.py index cd93fc3..13aaf1f 100644 --- a/src/authentic2_auth_fc/__init__.py +++ b/src/authentic2_auth_fc/__init__.py @@ -90,9 +90,10 @@ class AppConfig(django.apps.AppConfig): return None def a2_hook_user_can_change_password(self, user, request, **kwargs): - for authentication_event in get_authentication_events(request=request): - if authentication_event['how'] == 'france-connect': - return False + if 'fc_id_token' in request.session: + for authentication_event in get_authentication_events(request=request): + if authentication_event['how'] == 'france-connect': + return False return True diff --git a/tests/test_auth_fc.py b/tests/test_auth_fc.py index 8965d05..3c02d76 100644 --- a/tests/test_auth_fc.py +++ b/tests/test_auth_fc.py @@ -575,3 +575,16 @@ def test_can_change_password(app, fc_settings, caplog, hooks): assert path(response['Location']) == '/accounts/' response = response.follow() assert len(response.pyquery('[href*="password/change"]')) == 0 + + # Unlink + response = response.click('Delete link') + response.form.set('new_password1', 'ikKL1234') + response.form.set('new_password2', 'ikKL1234') + response = response.form.submit(name='unlink') + continue_url = response.pyquery('a#a2-continue').attr['href'] + state = urlparse.parse_qs(urlparse.urlparse(continue_url).query)['state'][0] + assert app.session['fc_states'][state]['next'] == '/accounts/' + response = app.get(reverse('fc-logout') + '?state=' + state) + assert path(response['Location']) == '/accounts/' + response = response.follow() + assert len(response.pyquery('[href*="password/change"]')) > 0