auth_fc: do not update user email with email returned by FC (#45199)

This commit is contained in:
Nicolas Roche 2021-05-14 18:09:19 +02:00
parent f148399793
commit 019159d30e
2 changed files with 12 additions and 25 deletions

View File

@ -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',
},
},
)

View File

@ -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)