france_connect: make existing user lookup case-insensitive

Fix #4053
This commit is contained in:
Pierre de La Morinerie 2019-07-08 17:28:35 +02:00
parent d05bab3df3
commit 6b27ac8514
2 changed files with 12 additions and 1 deletions

View file

@ -13,7 +13,7 @@ class FranceConnect::ParticulierController < ApplicationController
fetched_fci.tap(&:save)
if fci.user.nil?
user = User.find_or_create_by(email: fci.email_france_connect) do |new_user|
user = User.find_or_create_by(email: fci.email_france_connect.downcase) do |new_user|
new_user.password = Devise.friendly_token[0, 20]
new_user.confirmed_at = Time.zone.now
end

View file

@ -85,6 +85,17 @@ describe FranceConnect::ParticulierController, type: :controller do
expect(subject).to redirect_to(root_path)
end
end
context 'when a differently cased email address is already used' do
let(:email) { 'TEST@test.com' }
let!(:user) { create(:user, email: email.downcase, france_connect_information: nil) }
it 'associates the france_connect infos with the existing user' do
expect { subject }.not_to change(User, :count)
expect(user.reload.loged_in_with_france_connect).to eq(User.loged_in_with_france_connects.fetch(:particulier))
expect(subject).to redirect_to(root_path)
end
end
end
end