Projet

Général

Profil

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

Nicolas Roche, 19 mars 2021 18:38

Télécharger (3,88 ko)

Voir les différences:

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

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

  
97 105
    @property
98 106
    def next_field_name(self):
99 107
        return self._setting('NEXT_FIELD_NAME', 'fc_next')
100 108

  
101 109
    @property
102 110
    def client_id(self):
103 111
        return self._setting('CLIENT_ID', '')
tests/auth_fc/test_auth_fc.py
11 11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 13
# GNU Affero General Public License for more details.
14 14
#
15 15
# You should have received a copy of the GNU Affero General Public License
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18 18
import datetime
19
import json
19 20
import mock
20 21

  
21 22
import requests
22 23

  
23 24
from django.contrib.auth import get_user_model
24 25
from django.urls import reverse
25 26
from django.utils.six.moves.urllib import parse as urlparse
26 27
from django.utils.timezone import now
......
394 395
    assert deleted_user.old_data.get('fc_accounts') == [
395 396
        {
396 397
            'sub': '1234',
397 398
        },
398 399
        {
399 400
            'sub': '4567',
400 401
        }
401 402
    ]
403

  
404

  
405
def test_update_user_with_redondant_email(app, franceconnect, settings):
406
    settings.A2_email_IS_UNIQUE = True
407

  
408
    # account1 is linked to FC
409
    email1 = 'fred@example.com'
410
    user = User.objects.create(email=email1, first_name='Frédérique', last_name='Ÿuñe')
411
    user.set_password('toto')
412
    user.save()
413
    models.FcAccount.objects.create(user=user, sub='1234', token='xxx')
414

  
415
    # FC account linked to account1's provides account2 email
416
    email2 = 'john.doe@example.com'
417
    User.objects.create(email=email2, first_name='John', last_name='Doe')
418
    franceconnect.user_info['email'] = email2
419

  
420
    franceconnect.login_with_fc_fixed_params(app)
421
    assert User.objects.get(first_name='Ÿuñe').email == email1
422

  
423

  
424
def test_create_user_with_redondant_email(settings, app, franceconnect):
425
    settings.A2_FC_CREATE = True
426
    settings.A2_EMAIL_IS_UNIQUE = True
427

  
428
    # A2 accounts not linked to FC
429
    mail = franceconnect.user_info['email']
430
    User.objects.create(email=mail, first_name='John', last_name='Doe')
431

  
432
    # connect with an unrelated FC account providing an email already used
433
    response = app.get('/login/?service=portail&next=/idp/')
434
    response = response.click(href='callback')
435

  
436
    assert User.objects.count() == 1
437
    response = franceconnect.handle_authorization(app, response.location, status=302)
438
    assert User.objects.count() == 2
439
    assert User.objects.get(first_name='Ÿuñe').email == mail  # Should be "!="
402
-