From f54dfe6ead329c4d5e01620891c7e2db0e445daf Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Oct 2021 11:21:24 +0200 Subject: [PATCH] Do not raise error if user is nil I do not get when it happens --- .../france_connect/particulier_controller.rb | 2 +- .../france_connect/particulier_controller_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 40625c23f..655ab2cf2 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -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" diff --git a/spec/controllers/france_connect/particulier_controller_spec.rb b/spec/controllers/france_connect/particulier_controller_spec.rb index 3ff97c96b..92f342022 100644 --- a/spec/controllers/france_connect/particulier_controller_spec.rb +++ b/spec/controllers/france_connect/particulier_controller_spec.rb @@ -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) }