From 12fc2bca25882d2c777f62329ce5b852fe07247a Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 8 Apr 2021 11:16:18 +0200 Subject: [PATCH] auth_fc: save unusable password of new users (#52855) --- src/authentic2_auth_fc/backends.py | 3 ++- tests/auth_fc/test_auth_fc.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/authentic2_auth_fc/backends.py b/src/authentic2_auth_fc/backends.py index 513bac832..24bb63cec 100644 --- a/src/authentic2_auth_fc/backends.py +++ b/src/authentic2_auth_fc/backends.py @@ -56,8 +56,9 @@ class FcBackend(ModelBackend): user = user_qs.get() if not user: - user = User.objects.create(ou=get_default_ou()) + user = User(ou=get_default_ou()) user.set_unusable_password() + user.save() try: models.FcAccount.objects.create( user=user, sub=sub, order=0, token=json.dumps(kwargs['token']) diff --git a/tests/auth_fc/test_auth_fc.py b/tests/auth_fc/test_auth_fc.py index 393782f35..c1c7d7403 100644 --- a/tests/auth_fc/test_auth_fc.py +++ b/tests/auth_fc/test_auth_fc.py @@ -336,3 +336,14 @@ def test_save_account_on_delete_user(db): 'sub': '4567', }, ] + + +def test_create_missing_email(settings, app, franceconnect, hooks): + del franceconnect.user_info['email'] + response = app.get('/login/?service=portail&next=/idp/') + response = response.click(href='callback') + + response = franceconnect.handle_authorization(app, response.location, status=302) + assert User.objects.count() == 1 + + response = app.get('/accounts/', status=200)