Merge branch 'france_connect' of ssh://37.187.249.111:2200/opt/git/tps into france_connect
Conflicts: spec/controllers/france_connect_controller_spec.rb
This commit is contained in:
commit
deb13673d7
5 changed files with 81 additions and 17 deletions
|
@ -6,15 +6,30 @@ class Users::SessionsController < Devise::SessionsController
|
||||||
# super
|
# super
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# POST /resource/sign_in
|
#POST /resource/sign_in
|
||||||
# def create
|
def create
|
||||||
# super
|
super
|
||||||
# end
|
|
||||||
|
current_user.update_attributes(login_with_france_connect: false)
|
||||||
|
end
|
||||||
|
|
||||||
# DELETE /resource/sign_out
|
# DELETE /resource/sign_out
|
||||||
# def destroy
|
def destroy
|
||||||
# super
|
connected_with_france_connect = current_user.login_with_france_connect
|
||||||
# end
|
current_user.update_attributes(login_with_france_connect: false)
|
||||||
|
|
||||||
|
|
||||||
|
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
||||||
|
set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
|
||||||
|
yield if block_given?
|
||||||
|
|
||||||
|
|
||||||
|
if connected_with_france_connect
|
||||||
|
redirect_to FRANCE_CONNECT.logout_endpoint
|
||||||
|
else
|
||||||
|
respond_to_on_destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# protected
|
# protected
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,13 @@ class FranceConnectClient < OpenIDConnect::Client
|
||||||
super(
|
super(
|
||||||
identifier: FRANCE_CONNECT.identifier,
|
identifier: FRANCE_CONNECT.identifier,
|
||||||
secret: FRANCE_CONNECT.secret,
|
secret: FRANCE_CONNECT.secret,
|
||||||
|
|
||||||
redirect_uri: FRANCE_CONNECT.redirect_uri,
|
redirect_uri: FRANCE_CONNECT.redirect_uri,
|
||||||
|
|
||||||
authorization_endpoint: FRANCE_CONNECT.authorization_endpoint,
|
authorization_endpoint: FRANCE_CONNECT.authorization_endpoint,
|
||||||
token_endpoint: FRANCE_CONNECT.token_endpoint,
|
token_endpoint: FRANCE_CONNECT.token_endpoint,
|
||||||
userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint
|
userinfo_endpoint: FRANCE_CONNECT.userinfo_endpoint,
|
||||||
|
logout_endpoint: FRANCE_CONNECT.logout_endpoint
|
||||||
)
|
)
|
||||||
self.authorization_code = params[:code] if params.has_key? :code
|
self.authorization_code = params[:code] if params.has_key? :code
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
devise_for :users, controllers: {
|
devise_for :users, controllers: {
|
||||||
sessions: 'users/sessions'
|
sessions: 'users/sessions'
|
||||||
}
|
}
|
||||||
|
|
||||||
devise_for :gestionnaires, controllers: {
|
devise_for :gestionnaires, controllers: {
|
||||||
sessions: 'gestionnaires/sessions'
|
sessions: 'gestionnaires/sessions'
|
||||||
}, skip: [:password, :registrations]
|
}, skip: [:password, :registrations]
|
||||||
|
|
||||||
|
|
||||||
root 'users/dossiers#index'
|
root 'users/dossiers#index'
|
||||||
# root 'users/france_connect_callbacks#login'
|
|
||||||
|
|
||||||
|
|
||||||
get 'france_connect' => 'france_connect#login'
|
|
||||||
get 'france_connect/callback' => 'france_connect#callback'
|
|
||||||
|
|
||||||
|
get 'france_connect' => 'france_connect#login'
|
||||||
|
get 'france_connect/callback' => 'france_connect#callback'
|
||||||
|
|
||||||
namespace :users do
|
namespace :users do
|
||||||
get 'siret' => 'siret#index'
|
get 'siret' => 'siret#index'
|
||||||
|
|
51
spec/controllers/users/sessions_controller_spec.rb
Normal file
51
spec/controllers/users/sessions_controller_spec.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Users::SessionsController, type: :controller do
|
||||||
|
let(:login_with_france_connect) { true }
|
||||||
|
let(:user) { create(:user, login_with_france_connect: login_with_france_connect) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.create' do
|
||||||
|
before do
|
||||||
|
post :create, user: {email: user.email, password: user.password}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'login_with_france_connect current_user attribut is false' do
|
||||||
|
user.reload
|
||||||
|
expect(user.login_with_france_connect).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.destroy' do
|
||||||
|
before do
|
||||||
|
sign_in user
|
||||||
|
delete :destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'user is sign out' do
|
||||||
|
expect(subject.current_user).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'login_with_france_connect current_user attribut is false' do
|
||||||
|
user.reload
|
||||||
|
expect(user.login_with_france_connect).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user is connect with france connect' do
|
||||||
|
it 'redirect to france connect logout page' do
|
||||||
|
expect(response).to redirect_to(FRANCE_CONNECT.logout_endpoint)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user is not connect with france connect' do
|
||||||
|
let(:login_with_france_connect) { false }
|
||||||
|
|
||||||
|
it 'redirect to root page' do
|
||||||
|
expect(response).to redirect_to(root_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +1,6 @@
|
||||||
require 'spec_helper'
|
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' }
|
||||||
|
|
Loading…
Reference in a new issue