From 019159d30e510f1a2579253beea75cedb7ac1ab3 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Fri, 14 May 2021 18:09:19 +0200 Subject: [PATCH] auth_fc: do not update user email with email returned by FC (#45199) --- src/authentic2_auth_fc/app_settings.py | 11 ++++++++++- tests/auth_fc/test_auth_fc.py | 26 ++------------------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/authentic2_auth_fc/app_settings.py b/src/authentic2_auth_fc/app_settings.py index 8a04e967a..5b2978de7 100644 --- a/src/authentic2_auth_fc/app_settings.py +++ b/src/authentic2_auth_fc/app_settings.py @@ -72,7 +72,16 @@ class AppSettings(object): 'ref': 'given_name', 'verified': True, }, - 'email': 'email', + 'email': { + 'ref': 'email', + 'if-empty': True, + 'tag': 'email', + }, + 'email_verified': { + 'ref': 'email', + 'translation': 'notempty', + 'if-tag': 'email', + }, }, ) diff --git a/tests/auth_fc/test_auth_fc.py b/tests/auth_fc/test_auth_fc.py index 478feed13..fd1a3b831 100644 --- a/tests/auth_fc/test_auth_fc.py +++ b/tests/auth_fc/test_auth_fc.py @@ -587,30 +587,8 @@ def test_update_fc_email(settings, app, franceconnect): assert franceconnect.user_info['given_name'] == 'Ÿuñe' franceconnect.user_info['email'] = 'jhonny@example.com' - # connection using FC sub 1234 will update user1 email + # connection using FC sub 1234 will not update user1 email franceconnect.login_with_fc_fixed_params(app) - assert User.objects.get(pk=user.pk).email == 'jhonny@example.com' + assert User.objects.get(pk=user.pk).email == 'john.doe@example.com' assert User.objects.get(pk=user.pk).first_name == 'Ÿuñe' assert app.session['_auth_user_id'] == str(user.pk) - - -def test_update_fc_redondant_email(settings, app, franceconnect): - settings.A2_EMAIL_IS_UNIQUE = True - user1 = User(email='john.doe@example.com', first_name='John', last_name='Doe') - user1.save() - models.FcAccount.objects.create(user=user1, sub='1234') - user2 = User(email='joe@example.com', first_name='Joe', last_name='Dalton') - user2.save() - models.FcAccount.objects.create(user=user2, sub='4567') - - # user1 FC email has changed and provide user2 email - assert franceconnect.sub == '1234' - assert franceconnect.user_info['given_name'] == 'Ÿuñe' - franceconnect.user_info['email'] = 'joe@example.com' - - # connection using FC sub 1234 will introduce a redondant mail - franceconnect.login_with_fc_fixed_params(app) - assert User.objects.get(pk=user1.pk).email == 'joe@example.com' - assert User.objects.get(pk=user1.pk).first_name == 'Ÿuñe' - assert User.objects.get(pk=user2.pk).email == 'joe@example.com' - assert app.session['_auth_user_id'] == str(user1.pk)