Projet

Général

Profil

0002-auth_fc-do-not-update-user-email-with-email-returned.patch

Nicolas Roche, 14 mai 2021 18:20

Télécharger (3,41 ko)

Voir les différences:

Subject: [PATCH 2/2] 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(-)
src/authentic2_auth_fc/app_settings.py
67 67
                'last_name': {
68 68
                    'ref': 'family_name',
69 69
                    'verified': True,
70 70
                },
71 71
                'first_name': {
72 72
                    'ref': 'given_name',
73 73
                    'verified': True,
74 74
                },
75
                'email': 'email',
75
                'email': {
76
                    'ref': 'email',
77
                    'if-empty': True,
78
                    'tag': 'email',
79
                },
80
                'email_verified': {
81
                    'ref': 'email',
82
                    'translation': 'notempty',
83
                    'if-tag': 'email',
84
                },
76 85
            },
77 86
        )
78 87

  
79 88
    @property
80 89
    def client_id(self):
81 90
        return self._setting('CLIENT_ID', '')
82 91

  
83 92
    @property
tests/auth_fc/test_auth_fc.py
582 582
    user.save()
583 583
    models.FcAccount.objects.create(user=user, sub='1234')
584 584

  
585 585
    # user1 FC email has changed
586 586
    assert franceconnect.sub == '1234'
587 587
    assert franceconnect.user_info['given_name'] == 'Ÿuñe'
588 588
    franceconnect.user_info['email'] = 'jhonny@example.com'
589 589

  
590
    # connection using FC sub 1234 will update user1 email
590
    # connection using FC sub 1234 will not update user1 email
591 591
    franceconnect.login_with_fc_fixed_params(app)
592
    assert User.objects.get(pk=user.pk).email == 'jhonny@example.com'
592
    assert User.objects.get(pk=user.pk).email == 'john.doe@example.com'
593 593
    assert User.objects.get(pk=user.pk).first_name == 'Ÿuñe'
594 594
    assert app.session['_auth_user_id'] == str(user.pk)
595

  
596

  
597
def test_update_fc_redondant_email(settings, app, franceconnect):
598
    settings.A2_EMAIL_IS_UNIQUE = True
599
    user1 = User(email='john.doe@example.com', first_name='John', last_name='Doe')
600
    user1.save()
601
    models.FcAccount.objects.create(user=user1, sub='1234')
602
    user2 = User(email='joe@example.com', first_name='Joe', last_name='Dalton')
603
    user2.save()
604
    models.FcAccount.objects.create(user=user2, sub='4567')
605

  
606
    # user1 FC email has changed and provide user2 email
607
    assert franceconnect.sub == '1234'
608
    assert franceconnect.user_info['given_name'] == 'Ÿuñe'
609
    franceconnect.user_info['email'] = 'joe@example.com'
610

  
611
    # connection using FC sub 1234 will introduce a redondant mail
612
    franceconnect.login_with_fc_fixed_params(app)
613
    assert User.objects.get(pk=user1.pk).email == 'joe@example.com'
614
    assert User.objects.get(pk=user1.pk).first_name == 'Ÿuñe'
615
    assert User.objects.get(pk=user2.pk).email == 'joe@example.com'
616
    assert app.session['_auth_user_id'] == str(user1.pk)
617
-