fix siret retrieval from OpenIDConnect::ResponseObject::UserInfo
This commit is contained in:
parent
6db8efb078
commit
6dc891a320
6 changed files with 36 additions and 19 deletions
|
@ -3,6 +3,7 @@ class FranceConnectService
|
||||||
client = FranceConnectClient.new code: code
|
client = FranceConnectClient.new code: code
|
||||||
|
|
||||||
access_token = client.access_token!(client_auth_method: :secret)
|
access_token = client.access_token!(client_auth_method: :secret)
|
||||||
access_token.userinfo!
|
user_info = access_token.userinfo!
|
||||||
|
Hashie::Mash.new user_info.raw_attributes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,10 +18,13 @@ describe FranceConnectController, type: :controller do
|
||||||
end
|
end
|
||||||
context 'when params code is present' do
|
context 'when params code is present' do
|
||||||
let(:code) { 'plop' }
|
let(:code) { 'plop' }
|
||||||
|
let(:email) { 'patator@cake.com' }
|
||||||
|
let(:siret) { '41123069100049' }
|
||||||
|
let(:user_info) { Hashie::Mash.new(email: email, siret: siret) }
|
||||||
context 'when code is correct' do
|
context 'when code is correct' do
|
||||||
before do
|
before do
|
||||||
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
|
|
||||||
|
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_info)
|
||||||
end
|
end
|
||||||
it 'redirect to dossiers list' do
|
it 'redirect to dossiers list' do
|
||||||
get :callback, code: code
|
get :callback, code: code
|
||||||
|
|
|
@ -16,9 +16,11 @@ feature 'user path for dossier creation' do
|
||||||
|
|
||||||
context 'user sign_in' do
|
context 'user sign_in' do
|
||||||
before do
|
before do
|
||||||
page.find_by_id('user_email').set user.email
|
within('#new_user') do
|
||||||
page.find_by_id('user_password').set user.password
|
page.find_by_id('user_email').set user.email
|
||||||
page.click_on 'Se connecter'
|
page.find_by_id('user_password').set user.password
|
||||||
|
page.click_on 'Se connecter'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
scenario 'redirects to siret page' do
|
scenario 'redirects to siret page' do
|
||||||
expect(page).to have_css('#siret')
|
expect(page).to have_css('#siret')
|
||||||
|
|
|
@ -9,9 +9,11 @@ feature 'user access to the list of his dossier' do
|
||||||
before do
|
before do
|
||||||
last_updated_dossier.update_attributes(nom_projet: 'salut la compagnie')
|
last_updated_dossier.update_attributes(nom_projet: 'salut la compagnie')
|
||||||
visit root_path
|
visit root_path
|
||||||
page.find_by_id('user_email').set user.email
|
within('#new_user') do
|
||||||
page.find_by_id('user_password').set user.password
|
page.find_by_id('user_email').set user.email
|
||||||
page.click_on 'Se connecter'
|
page.find_by_id('user_password').set user.password
|
||||||
|
page.click_on 'Se connecter'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
scenario 'the list of dossier is displayed' do
|
scenario 'the list of dossier is displayed' do
|
||||||
expect(page).to have_content(dossier1.nom_projet)
|
expect(page).to have_content(dossier1.nom_projet)
|
||||||
|
|
|
@ -14,9 +14,11 @@ feature 'user arrive on siret page' do
|
||||||
end
|
end
|
||||||
context 'when he enter login information' do
|
context 'when he enter login information' do
|
||||||
before do
|
before do
|
||||||
page.find_by_id('user_email').set user.email
|
within('#new_user') do
|
||||||
page.find_by_id('user_password').set user.password
|
page.find_by_id('user_email').set user.email
|
||||||
page.click_on 'Se connecter'
|
page.find_by_id('user_password').set user.password
|
||||||
|
page.click_on 'Se connecter'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
scenario 'he is redirected to siret page to enter a siret' do
|
scenario 'he is redirected to siret page to enter a siret' do
|
||||||
expect(page).to have_css('#pro_section')
|
expect(page).to have_css('#pro_section')
|
||||||
|
|
|
@ -3,21 +3,28 @@ require 'spec_helper'
|
||||||
describe FranceConnectService do
|
describe FranceConnectService do
|
||||||
|
|
||||||
describe '.retrieve_user_informations' do
|
describe '.retrieve_user_informations' do
|
||||||
|
|
||||||
let(:code) { 'plop' }
|
let(:code) { 'plop' }
|
||||||
let(:mocky) { 'my mocky' }
|
let(:access_token) { 'my access_token' }
|
||||||
let(:user_info) { 'user_informations' }
|
let(:email) { 'patator@cake.com' }
|
||||||
|
let(:siret) { '41123069100049' }
|
||||||
|
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 code }
|
subject { described_class.retrieve_user_informations code }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(FranceConnectClient).to receive(:access_token!).and_return(mocky)
|
allow_any_instance_of(FranceConnectClient).to receive(:access_token!).and_return(access_token)
|
||||||
allow(mocky).to receive(:userinfo!).and_return(user_info)
|
allow(access_token).to receive(:userinfo!).and_return(user_info)
|
||||||
end
|
end
|
||||||
it 'set code for FranceConnectClient' do
|
it 'set code for FranceConnectClient' do
|
||||||
expect_any_instance_of(FranceConnectClient).to receive(:initialize).with(code: code)
|
expect_any_instance_of(FranceConnectClient).to receive(:authorization_code=).with(code)
|
||||||
described_class.retrieve_user_informations code
|
described_class.retrieve_user_informations code
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns user informations' do
|
it 'returns user informations in a object' do
|
||||||
expect(subject).to eq(user_info)
|
expect(subject.email).to eq(email)
|
||||||
|
expect(subject.siret).to eq(siret)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue