Merge pull request #6555 from betagouv/fix_fc

FC ne lève pas d'exception lorsque le merge concerne un compte qui n'existe pas
This commit is contained in:
LeSim 2021-10-19 12:05:32 +02:00 committed by GitHub
commit 98107eb7da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -45,7 +45,7 @@ class FranceConnect::ParticulierController < ApplicationController
def merge_with_existing_account
user = User.find_by(email: sanitized_email_params)
if user.valid_for_authentication? { user.valid_password?(password_params) }
if user.present? && user.valid_for_authentication? { user.valid_password?(password_params) }
if !user.can_france_connect?
flash.alert = "#{user.email} ne peut utiliser FranceConnect"

View file

@ -189,6 +189,17 @@ describe FranceConnect::ParticulierController, type: :controller do
it_behaves_like "a method that needs a valid merge token"
context 'when the user is not found' do
it 'does not log' do
subject
fci.reload
expect(fci.user).to be_nil
expect(fci.merge_token).not_to be_nil
expect(controller.current_user).to be_nil
end
end
context 'when the credentials are ok' do
let!(:user) { create(:user, email: email, password: password) }