From 20cae835e6f9594c100030fe67adf7f04c63bd59 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 6 Oct 2015 11:47:42 +0200 Subject: [PATCH] begin spec client france connect service --- app/controllers/france_connect_controller.rb | 2 +- app/models/france_connect_client.rb | 13 ++++--------- app/services/france_connect_service.rb | 10 +++------- spec/models/france_connect_client_spec.rb | 2 +- spec/services/france_connect_service_spec.rb | 13 +++++++++++++ 5 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 spec/services/france_connect_service_spec.rb diff --git a/app/controllers/france_connect_controller.rb b/app/controllers/france_connect_controller.rb index 02103054a..2be233c97 100644 --- a/app/controllers/france_connect_controller.rb +++ b/app/controllers/france_connect_controller.rb @@ -14,7 +14,7 @@ class FranceConnectController < ApplicationController end def callback - user_infos = FranceConnectService.retrive_user(params[:code]) + user_infos = FranceConnectService.retrieve_user_informations(params[:code]) unless user_infos.nil? @user = User.find_for_france_connect(user_infos.email) diff --git a/app/models/france_connect_client.rb b/app/models/france_connect_client.rb index 565a9a402..9a760feaa 100644 --- a/app/models/france_connect_client.rb +++ b/app/models/france_connect_client.rb @@ -1,18 +1,13 @@ class FranceConnectClient < OpenIDConnect::Client def initialize params={} - redirect_uri = 'http://localhost:3000/france_connect/callback' - authorization_endpoint = 'https://fce.integ01.dev-franceconnect.fr/api/v1/authorize' - token_endpoint = 'https://fce.integ01.dev-franceconnect.fr/api/v1/token' - userinfo_endpoint = 'https://fce.integ01.dev-franceconnect.fr/api/v1/userinfo' - super( identifier: FRANCE_CONNECT.identifier, secret: FRANCE_CONNECT.secret, - redirect_uri: redirect_uri, - authorization_endpoint: authorization_endpoint, - token_endpoint: token_endpoint, - userinfo_endpoint: userinfo_endpoint + redirect_uri: FRANCE_CONNECT.redirect_uri, + authorization_endpoint: FRANCE_CONNECT.authorization_endpoint, + token_endpoint: FRANCE_CONNECT.token_endpoint, + userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint ) self.authorization_code = params[:code] if params.has_key? :code end diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index 1c3bb200b..af6d26a96 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -1,12 +1,8 @@ class FranceConnectService - def self.retrive_user code + def self.retrieve_user_informations code client = FranceConnectClient.new code: code - begin - access_token = client.access_token!(client_auth_method: :secret) - access_token.userinfo! - rescue Exception => e - Rails.logger.error(e.message) - end + access_token = client.access_token!(client_auth_method: :secret) + access_token.userinfo! end end diff --git a/spec/models/france_connect_client_spec.rb b/spec/models/france_connect_client_spec.rb index 007bc3264..174151ff5 100644 --- a/spec/models/france_connect_client_spec.rb +++ b/spec/models/france_connect_client_spec.rb @@ -9,7 +9,7 @@ describe FranceConnectClient 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=) + expect_any_instance_of(described_class).to receive(:authorization_code=).with(code) described_class.new(code: code) end end diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb new file mode 100644 index 000000000..6a8b4c9b8 --- /dev/null +++ b/spec/services/france_connect_service_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe FranceConnectService do + + describe '.retrieve_user_informations' do + let(:code) { 'plop' } + + it 'set code for FranceConnectClient' do + expect_any_instance_of(FranceConnectClient).to receive(:initialize).with(code: code) + described_class.retrieve_user_informations code + end + end +end \ No newline at end of file