auth_fc: save unusable password of new users (#52855)

This commit is contained in:
Benjamin Dauvergne 2021-04-08 11:16:18 +02:00
parent 20e610da0e
commit 12fc2bca25
2 changed files with 13 additions and 1 deletions

View File

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

View File

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