Projet

Général

Profil

0002-auth_fc-do-not-update-redondant-email-returned-by-FC.patch

Nicolas Roche, 09 avril 2021 16:09

Télécharger (3,16 ko)

Voir les différences:

Subject: [PATCH 2/2] auth_fc: do not update redondant email returned by FC
 (#45199)

 src/authentic2_auth_fc/app_settings.py | 11 ++++++++++-
 tests/auth_fc/test_auth_fc.py          |  4 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)
src/authentic2_auth_fc/app_settings.py
81 81
                'last_name': {
82 82
                    'ref': 'family_name',
83 83
                    'verified': True,
84 84
                },
85 85
                'first_name': {
86 86
                    'ref': 'given_name',
87 87
                    'verified': True,
88 88
                },
89
                'email': 'email',
89
                'email': {
90
                    'ref': 'email',
91
                    'if-empty': True,
92
                    'tag': 'email',
93
                },
94
                'email_verified': {
95
                    'ref': 'email',
96
                    'translation': 'notempty',
97
                    'if-tag': 'email',
98
                },
90 99
            },
91 100
        )
92 101

  
93 102
    @property
94 103
    def next_field_name(self):
95 104
        return self._setting('NEXT_FIELD_NAME', 'fc_next')
96 105

  
97 106
    @property
tests/auth_fc/test_auth_fc.py
362 362

  
363 363
    # user1 FC email has changed
364 364
    assert franceconnect.sub == '1234'
365 365
    assert franceconnect.user_info['given_name'] == 'Ÿuñe'
366 366
    franceconnect.user_info['email'] = 'jhonny@example.com'
367 367

  
368 368
    # connection using FC sub 1234 will affect user1 (as expected)
369 369
    franceconnect.login_with_fc_fixed_params(app)
370
    assert User.objects.get(pk=user1.pk).email == 'jhonny@example.com'
370
    assert User.objects.get(pk=user1.pk).email == 'john.doe@example.com'
371 371
    assert User.objects.get(pk=user1.pk).first_name == 'Ÿuñe'
372 372
    assert User.objects.get(pk=user2.pk).email == 'joe@example.com'
373 373
    assert app.session['_auth_user_id'] == str(user1.pk)
374 374

  
375 375

  
376 376
def test_update_fc_redondant_email(settings, app, franceconnect):
377 377
    settings.A2_EMAIL_IS_UNIQUE = True
378 378

  
......
386 386

  
387 387
    # user1 FC email has changed and provide user2 email
388 388
    assert franceconnect.sub == '1234'
389 389
    assert franceconnect.user_info['given_name'] == 'Ÿuñe'
390 390
    franceconnect.user_info['email'] = 'joe@example.com'
391 391

  
392 392
    # connection using FC sub 1234 will affect user2
393 393
    franceconnect.login_with_fc_fixed_params(app)
394
    assert User.objects.get(pk=user1.pk).email == 'joe@example.com'
394
    assert User.objects.get(pk=user1.pk).email == 'john.doe@example.com'
395 395
    assert User.objects.get(pk=user1.pk).first_name == 'Ÿuñe'
396 396
    assert User.objects.get(pk=user2.pk).email == 'joe@example.com'
397 397
    assert app.session.get('_auth_user_id')
398
-