From 0d46f927958ffab27be1b097bba033ddc3d9fbf1 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 15 Jan 2018 12:07:54 +0100 Subject: [PATCH] FC: move FC constants under particulier namespace --- app/controllers/users/sessions_controller.rb | 2 +- .../france_connect_particulier_client.rb | 16 +++++++------- app/services/france_connect_salt_service.rb | 2 +- config/initializers/france_connect.rb | 21 ++++++++++++------- .../users/sessions_controller_spec.rb | 4 ++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 496ac0ea8..302c19596 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -50,7 +50,7 @@ class Users::SessionsController < Sessions::SessionsController case connected_with_france_connect when 'particulier' - redirect_to FRANCE_CONNECT.particulier_logout_endpoint + redirect_to FRANCE_CONNECT.particulier.logout_endpoint return end end diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index 5c157aa8c..934dddb6a 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,15 +1,13 @@ class FranceConnectParticulierClient < OpenIDConnect::Client def initialize(code = nil) super( - identifier: FRANCE_CONNECT.particulier_identifier, - secret: FRANCE_CONNECT.particulier_secret, - - redirect_uri: FRANCE_CONNECT.particulier_redirect_uri, - - authorization_endpoint: FRANCE_CONNECT.particulier_authorization_endpoint, - token_endpoint: FRANCE_CONNECT.particulier_token_endpoint, - userinfo_endpoint: FRANCE_CONNECT.particulier_userinfo_endpoint, - logout_endpoint: FRANCE_CONNECT.particulier_logout_endpoint + identifier: FRANCE_CONNECT.particulier.identifier, + secret: FRANCE_CONNECT.particulier.secret, + redirect_uri: FRANCE_CONNECT.particulier.redirect_uri, + authorization_endpoint: FRANCE_CONNECT.particulier.authorization_endpoint, + token_endpoint: FRANCE_CONNECT.particulier.token_endpoint, + userinfo_endpoint: FRANCE_CONNECT.particulier.userinfo_endpoint, + logout_endpoint: FRANCE_CONNECT.particulier.logout_endpoint ) if code.present? diff --git a/app/services/france_connect_salt_service.rb b/app/services/france_connect_salt_service.rb index a28476952..2e35b5515 100644 --- a/app/services/france_connect_salt_service.rb +++ b/app/services/france_connect_salt_service.rb @@ -11,6 +11,6 @@ class FranceConnectSaltService end def salt - Digest::MD5.hexdigest(model.france_connect_particulier_id + model.given_name + model.family_name + FRANCE_CONNECT.particulier_secret + DateTime.now.to_date.to_s) + Digest::MD5.hexdigest(model.france_connect_particulier_id + model.given_name + model.family_name + FRANCE_CONNECT.particulier.secret + DateTime.now.to_date.to_s) end end diff --git a/config/initializers/france_connect.rb b/config/initializers/france_connect.rb index c9e9d11cf..f4bc1d681 100644 --- a/config/initializers/france_connect.rb +++ b/config/initializers/france_connect.rb @@ -1,14 +1,19 @@ FRANCE_CONNECT = if !Rails.env.test? file_path = "#{Rails.root}/config/france_connect.yml" - Hashie::Mash.load(file_path) + config_hash = YAML.safe_load(File.read(file_path)) + .reduce({}) { |acc, (key, value)| acc[key.gsub('particulier_', '')] = value, acc } + + Hashie::Mash.new(particulier: config_hash) else Hashie::Mash.new({ - particulier_identifier: 'plop', - particulier_secret: 'plip', - particulier_redirect_uri: 'https://bidon.com/endpoint', - particulier_authorization_endpoint: 'https://bidon.com/endpoint', - particulier_token_endpoint: 'https://bidon.com/endpoint', - particulier_userinfo_endpoint: 'https://bidon.com/endpoint', - particulier_logout_endpoint: 'https://bidon.com/endpoint', + particulier: { + identifier: 'plop', + secret: 'plip', + redirect_uri: 'https://bidon.com/endpoint', + authorization_endpoint: 'https://bidon.com/endpoint', + token_endpoint: 'https://bidon.com/endpoint', + userinfo_endpoint: 'https://bidon.com/endpoint', + logout_endpoint: 'https://bidon.com/endpoint', + } }) end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 6cbaac682..8c812369a 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -118,7 +118,7 @@ describe Users::SessionsController, type: :controller 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) + expect(response).to redirect_to(FRANCE_CONNECT.particulier.logout_endpoint) end end @@ -161,7 +161,7 @@ describe Users::SessionsController, type: :controller do user.update_attributes(loged_in_with_france_connect: 'particulier') sign_in user delete :destroy - expect(@response.headers["Location"]).to eq(FRANCE_CONNECT.particulier_logout_endpoint) + expect(@response.headers["Location"]).to eq(FRANCE_CONNECT.particulier.logout_endpoint) end context "when associated administrateur" do