Add FranceConnect Particulier
Reactivate FranceConnect Entreprise
This commit is contained in:
parent
2099095c34
commit
9e0dfb593e
21 changed files with 548 additions and 115 deletions
|
@ -30,8 +30,8 @@ describe FranceConnect::EntrepriseController, type: :controller do
|
|||
get :callback, code: code
|
||||
end
|
||||
|
||||
it 'current user have attribut loged_in_with_france_connect at true' do
|
||||
expect(current_user.loged_in_with_france_connect).to be_truthy
|
||||
it 'current user have attribut loged_in_with_france_connect at enterprise' do
|
||||
expect(current_user.loged_in_with_france_connect).to eq 'entreprise'
|
||||
end
|
||||
let(:stored_location) { '/plip/plop' }
|
||||
it 'redirect to stored location' do
|
107
spec/controllers/france_connect/particulier_controller_spec.rb
Normal file
107
spec/controllers/france_connect/particulier_controller_spec.rb
Normal file
|
@ -0,0 +1,107 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FranceConnect::ParticulierController, type: :controller do
|
||||
let(:code) { 'plop' }
|
||||
let(:given_name) { 'titi' }
|
||||
let(:family_name) { 'toto' }
|
||||
let(:birthdate) { '20150821' }
|
||||
let(:gender) { 'M' }
|
||||
let(:birthplace) { '1234' }
|
||||
let(:france_connect_particulier_id) { 'blabla' }
|
||||
let(:email) { '' }
|
||||
|
||||
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email) }
|
||||
|
||||
describe '.login' do
|
||||
it 'redirect to france connect serveur' do
|
||||
get :login
|
||||
expect(response.status).to eq(302)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.callback' do
|
||||
context 'when param code is missing' do
|
||||
it 'redirect to login page' do
|
||||
get :callback
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when params code is present' do
|
||||
context 'when code is correct' do
|
||||
before do
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(user_info)
|
||||
get :callback, code: code
|
||||
end
|
||||
|
||||
context 'when france_connect_particulier_id exist in database' do
|
||||
before do
|
||||
create(:user, france_connect_particulier_id: france_connect_particulier_id, email: email, given_name: given_name, family_name: family_name, birthdate: birthdate, gender: gender, birthplace: birthplace)
|
||||
get :callback, code: code
|
||||
end
|
||||
|
||||
let(:email) { 'plop@plop.com' }
|
||||
let(:current_user) { User.find_by_email(email) }
|
||||
let(:stored_location) { '/plip/plop' }
|
||||
|
||||
it 'current user have attribut loged_in_with_france_connect? at true' do
|
||||
expect(current_user.loged_in_with_france_connect?).to be_truthy
|
||||
end
|
||||
|
||||
it 'redirect to stored location' do
|
||||
subject.store_location_for(:user, stored_location)
|
||||
get :callback, code: code
|
||||
expect(response).to redirect_to(stored_location)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when france_connect_particulier_id does not exist in database' do
|
||||
it 'redirects to check email FC page' do
|
||||
expect(response).to redirect_to(france_connect_particulier_new_path(user: user_info))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when code is not correct' do
|
||||
before do
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
||||
get :callback, code: code
|
||||
end
|
||||
|
||||
it 'redirect to login page' do
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'display error message' do
|
||||
expect(flash[:alert]).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:email) { 'plop@gmail.com' }
|
||||
|
||||
subject { post :create, user: user_info }
|
||||
|
||||
context 'when email is filled' do
|
||||
it { expect { subject }.to change { User.count }.by(1) }
|
||||
|
||||
it 'redirects user root page' do
|
||||
subject
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when email is incorrect' do
|
||||
let(:email) { '' }
|
||||
|
||||
it { expect { subject }.to change { User.count }.by(0) }
|
||||
|
||||
it 'redirect to check email FC page' do
|
||||
subject
|
||||
expect(response).to redirect_to(france_connect_particulier_new_path(user: user_info))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Users::SessionsController, type: :controller do
|
||||
let(:loged_in_with_france_connect) { true }
|
||||
let(:loged_in_with_france_connect) { 'entreprise' }
|
||||
let(:user) { create(:user, loged_in_with_france_connect: loged_in_with_france_connect) }
|
||||
|
||||
before do
|
||||
|
@ -17,7 +17,7 @@ describe Users::SessionsController, type: :controller do
|
|||
user.reload
|
||||
end
|
||||
|
||||
subject { user.loged_in_with_france_connect }
|
||||
subject { user.loged_in_with_france_connect? }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
@ -33,19 +33,27 @@ describe Users::SessionsController, type: :controller do
|
|||
expect(subject.current_user).to be_nil
|
||||
end
|
||||
|
||||
it 'loged_in_with_france_connect current_user attribut is false' do
|
||||
it 'loged_in_with_france_connect current_user attribut is nil' do
|
||||
user.reload
|
||||
expect(user.loged_in_with_france_connect).to be_falsey
|
||||
expect(user.loged_in_with_france_connect?).to be_falsey
|
||||
end
|
||||
|
||||
context 'when user is connect with france connect' do
|
||||
context 'when user is connect with france connect entreprise' do
|
||||
it 'redirect to france connect logout page' do
|
||||
expect(response).to redirect_to(FRANCE_CONNECT.entreprise_logout_endpoint)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is connect with france connect entreprise' do
|
||||
let(:loged_in_with_france_connect) { 'particulier' }
|
||||
|
||||
it 'redirect to france connect logout page' do
|
||||
expect(response).to redirect_to(FRANCE_CONNECT.particulier_logout_endpoint)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not connect with france connect' do
|
||||
let(:loged_in_with_france_connect) { false }
|
||||
let(:loged_in_with_france_connect) { '' }
|
||||
|
||||
it 'redirect to root page' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'France Connect Connexion' do
|
||||
context 'when user is on login page' do
|
||||
|
||||
before do
|
||||
visit new_user_session_path
|
||||
end
|
||||
|
||||
scenario 'link to France Connect is present' do
|
||||
expect(page).to have_css('a#btn_fce')
|
||||
end
|
||||
|
||||
context 'and click on france connect link' do
|
||||
let(:code) { 'plop' }
|
||||
|
||||
context 'when authentification is ok' do
|
||||
before do
|
||||
allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_entreprise_callback_path(code: code))
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
|
||||
page.find_by_id('btn_fce').click
|
||||
end
|
||||
|
||||
scenario 'he is redirected to france connect' do
|
||||
expect(page).to have_content('Mes dossiers')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when authentification is not ok' do
|
||||
before do
|
||||
allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_entreprise_callback_path(code: code))
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
||||
page.find_by_id('btn_fce').click
|
||||
end
|
||||
|
||||
scenario 'he is redirected to login page' do
|
||||
expect(page).to have_css('a#btn_fce')
|
||||
end
|
||||
|
||||
scenario 'error message is displayed' do
|
||||
expect(page).to have_content(I18n.t('errors.messages.france_connect.connexion'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature 'redirection' do
|
||||
before do
|
||||
visit initial_path
|
||||
end
|
||||
context 'when he use france connect' do
|
||||
let(:code) { 'my_code' }
|
||||
let(:email) { 'plop@plop.com' }
|
||||
let(:siret) { '00000000000000' }
|
||||
let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) }
|
||||
before do
|
||||
allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_entreprise_callback_path(code: code))
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_infos)
|
||||
page.find_by_id('btn_fce').click
|
||||
end
|
||||
context 'when starting page is dossiers list' do
|
||||
let(:initial_path) { users_dossiers_path }
|
||||
scenario 'he is redirected to dossier list' do
|
||||
expect(page).to have_css('#users_index')
|
||||
end
|
||||
end
|
||||
context 'when starting page is procedure' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:initial_path) { new_users_dossiers_path(procedure_id: procedure.id ) }
|
||||
scenario 'he is redirected to siret page' do
|
||||
expect(page).to have_css('#users_siret_index')
|
||||
end
|
||||
|
||||
scenario 'the siret is already written in form' do
|
||||
expect(page.find_by_id('dossier_siret').value).to have_content(siret)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,84 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'France Connect Particulier Connexion' do
|
||||
|
||||
let(:code) { 'plop' }
|
||||
let(:given_name) { 'titi' }
|
||||
let(:family_name) { 'toto' }
|
||||
let(:birthdate) { '20150821' }
|
||||
let(:gender) { 'M' }
|
||||
let(:birthplace) { '1234' }
|
||||
let(:email) { 'plop@plop.com' }
|
||||
let(:know_france_connect_particulier_id) { 'blabla' }
|
||||
let(:unknow_france_connect_particulier_id) { 'titi' }
|
||||
|
||||
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email) }
|
||||
|
||||
context 'when user is on login page' do
|
||||
|
||||
before do
|
||||
visit new_user_session_path
|
||||
end
|
||||
|
||||
scenario 'link to France Connect is present' do
|
||||
expect(page).to have_css('a#btn_fcp')
|
||||
end
|
||||
|
||||
context 'and click on france connect link' do
|
||||
let(:code) { 'plop' }
|
||||
|
||||
context 'when authentification is ok' do
|
||||
let!(:user) { create(:user, france_connect_particulier_id: know_france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(user_info)
|
||||
page.find_by_id('btn_fcp').click
|
||||
end
|
||||
|
||||
context 'when is the first connexion' do
|
||||
let(:france_connect_particulier_id) { unknow_france_connect_particulier_id }
|
||||
|
||||
scenario 'he is redirected to france connect particulier page' do
|
||||
expect(page).to have_content('Nouvelle connexion')
|
||||
end
|
||||
|
||||
context 'when he fill an email and valid' do
|
||||
before do
|
||||
page.find_by_id('user_email').set email
|
||||
page.find_by_id('valid_new_fcp').click
|
||||
end
|
||||
|
||||
scenario 'he is redirected to user dossiers page' do
|
||||
expect(page).to have_content('Mes dossiers')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when is not the first connexion' do
|
||||
let(:france_connect_particulier_id) { know_france_connect_particulier_id }
|
||||
|
||||
scenario 'he is redirected to user dossiers page' do
|
||||
expect(page).to have_content('Mes dossiers')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when authentification is not ok' do
|
||||
before do
|
||||
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))
|
||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
||||
page.find_by_id('btn_fcp').click
|
||||
end
|
||||
|
||||
scenario 'he is redirected to login page' do
|
||||
expect(page).to have_css('a#btn_fcp')
|
||||
end
|
||||
|
||||
scenario 'error message is displayed' do
|
||||
expect(page).to have_content(I18n.t('errors.messages.france_connect.connexion'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,81 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'France Connect Connexion' do
|
||||
# context 'when user is on login page' do
|
||||
#
|
||||
# before do
|
||||
# visit new_user_session_path
|
||||
# end
|
||||
#
|
||||
# scenario 'link to France Connect is present' do
|
||||
# expect(page).to have_css('a#btn_fc')
|
||||
# end
|
||||
#
|
||||
# context 'and click on france connect link' do
|
||||
# let(:code) { 'plop' }
|
||||
#
|
||||
# context 'when authentification is ok' do
|
||||
# before do
|
||||
# allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
|
||||
# allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
|
||||
# page.find_by_id('btn_fc').click
|
||||
# end
|
||||
#
|
||||
# scenario 'he is redirected to france connect' do
|
||||
# expect(page).to have_content('Mes dossiers')
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# context 'when authentification is not ok' do
|
||||
# before do
|
||||
# allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
|
||||
# allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
||||
# page.find_by_id('btn_fc').click
|
||||
# end
|
||||
#
|
||||
# scenario 'he is redirected to login page' do
|
||||
# expect(page).to have_css('a#btn_fc')
|
||||
# end
|
||||
#
|
||||
# scenario 'error message is displayed' do
|
||||
# expect(page).to have_content(I18n.t('errors.messages.france_connect.connexion'))
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
# feature 'redirection' do
|
||||
# before do
|
||||
# visit initial_path
|
||||
# end
|
||||
# context 'when he use france connect' do
|
||||
# let(:code) { 'my_code' }
|
||||
# let(:email) { 'plop@plop.com' }
|
||||
# let(:siret) { '00000000000000' }
|
||||
# let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) }
|
||||
# before do
|
||||
# allow_any_instance_of(FranceConnectEntrepriseClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
|
||||
# allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_infos)
|
||||
# page.find_by_id('btn_fc').click
|
||||
# end
|
||||
# context 'when starting page is dossiers list' do
|
||||
# let(:initial_path) { users_dossiers_path }
|
||||
# scenario 'he is redirected to dossier list' do
|
||||
# expect(page).to have_css('#users_index')
|
||||
# end
|
||||
# end
|
||||
# context 'when starting page is procedure' do
|
||||
# let(:procedure) { create(:procedure) }
|
||||
# let(:initial_path) { new_users_dossiers_path(procedure_id: procedure.id ) }
|
||||
# scenario 'he is redirected to siret page' do
|
||||
# expect(page).to have_css('#users_siret_index')
|
||||
# end
|
||||
#
|
||||
# scenario 'the siret is already written in form' do
|
||||
# expect(page.find_by_id('dossier_siret').value).to have_content(siret)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
17
spec/models/france_connect_particulier_client_spec.rb
Normal file
17
spec/models/france_connect_particulier_client_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FranceConnectParticulierClient do
|
||||
describe '.initialize' do
|
||||
it 'create an openid client' do
|
||||
expect(described_class).to be < OpenIDConnect::Client
|
||||
end
|
||||
context 'when given code in params' do
|
||||
let(:code) { 'plop' }
|
||||
subject { described_class.new(code: code) }
|
||||
it 'set authorisation code' do
|
||||
expect_any_instance_of(described_class).to receive(:authorization_code=).with(code)
|
||||
described_class.new(code: code)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,6 +16,13 @@ describe User, type: :model do
|
|||
it { is_expected.to have_db_column(:updated_at) }
|
||||
it { is_expected.to have_db_column(:siret) }
|
||||
it { is_expected.to have_db_column(:loged_in_with_france_connect) }
|
||||
it { is_expected.to have_db_column(:given_name) }
|
||||
it { is_expected.to have_db_column(:family_name) }
|
||||
it { is_expected.to have_db_column(:birthdate) }
|
||||
it { is_expected.to have_db_column(:gender) }
|
||||
it { is_expected.to have_db_column(:birthplace) }
|
||||
it { is_expected.to have_db_column(:france_connect_particulier_id) }
|
||||
|
||||
end
|
||||
describe 'associations' do
|
||||
it { is_expected.to have_many(:dossiers) }
|
||||
|
|
|
@ -2,12 +2,11 @@ require 'spec_helper'
|
|||
|
||||
describe FranceConnectService do
|
||||
describe '.retrieve_user_informations_entreprise' do
|
||||
|
||||
let(:code) { 'plop' }
|
||||
let(:access_token) { 'my access_token' }
|
||||
let(:email) { 'patator@cake.com' }
|
||||
let(:siret) { '41123069100049' }
|
||||
let(:user_info_hash) { {'email' => email, 'siret' => siret} }
|
||||
let(:user_info_hash) { {'email' => email, 'siret' => siret} }
|
||||
let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash, email: email) }
|
||||
|
||||
subject { described_class.retrieve_user_informations_entreprise code }
|
||||
|
@ -26,4 +25,44 @@ describe FranceConnectService do
|
|||
expect(subject.siret).to eq(siret)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.retrieve_user_informations_particulier' do
|
||||
let(:code) { 'plop' }
|
||||
let(:access_token) { 'my access_token' }
|
||||
|
||||
let(:given_name) { 'plop1' }
|
||||
let(:family_name) { 'plop2' }
|
||||
let(:birthdate) { 'plop3' }
|
||||
let(:gender) { 'plop4' }
|
||||
let(:birthplace) { 'plop5' }
|
||||
let(:email) { 'plop@emaiL.com' }
|
||||
let(:phone) { '012345678' }
|
||||
let(:france_connect_particulier_id) { 'izhikziogjuziegj' }
|
||||
|
||||
let(:user_info_hash) { {sub: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, gender: gender, birthplace: birthplace, email: email, phone: phone} }
|
||||
let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash) }
|
||||
|
||||
subject { described_class.retrieve_user_informations_particulier code }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(FranceConnectParticulierClient).to receive(:access_token!).and_return(access_token)
|
||||
allow(access_token).to receive(:userinfo!).and_return(user_info)
|
||||
end
|
||||
|
||||
it 'set code for FranceConnectEntrepriseClient' do
|
||||
expect_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_code=).with(code)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'returns user informations in a object' do
|
||||
expect(subject.given_name).to eq(given_name)
|
||||
expect(subject.family_name).to eq(family_name)
|
||||
expect(subject.birthdate).to eq(birthdate)
|
||||
expect(subject.gender).to eq(gender)
|
||||
expect(subject.email).to eq(email)
|
||||
expect(subject.phone).to eq(phone)
|
||||
expect(subject.birthplace).to eq(birthplace)
|
||||
expect(subject.france_connect_particulier_id).to eq(france_connect_particulier_id)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue