Can connect admin with user session path

This commit is contained in:
Xavier J 2016-12-07 17:03:36 +01:00
parent 5915a2b7d5
commit 715f086957
3 changed files with 54 additions and 10 deletions

View file

@ -24,6 +24,7 @@ class Users::SessionsController < Sessions::SessionsController
def create
try_to_authenticate(User)
try_to_authenticate(Gestionnaire) if Features.unified_login
try_to_authenticate(Administrateur) if Features.unified_login
if user_signed_in?
current_user.update_attributes(loged_in_with_france_connect: '')
@ -33,6 +34,8 @@ class Users::SessionsController < Sessions::SessionsController
redirect_to after_sign_in_path_for(:user)
elsif gestionnaire_signed_in?
redirect_to backoffice_path
elsif administrateur_signed_in?
redirect_to admin_path
else
new
render :new, status: 401
@ -41,9 +44,8 @@ class Users::SessionsController < Sessions::SessionsController
# DELETE /resource/sign_out
def destroy
if gestionnaire_signed_in?
sign_out :gestionnaire
end
sign_out :gestionnaire if gestionnaire_signed_in?
sign_out :administrateur if administrateur_signed_in?
if user_signed_in?
connected_with_france_connect = current_user.loged_in_with_france_connect

View file

@ -35,8 +35,13 @@ describe Users::SessionsController, type: :controller do
end
context "unified login" do
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
let(:email) { 'unique@plop.com' }
let(:password) { 'password' }
let(:user) { create(:user, email: email, password: password) }
let(:gestionnaire) { create(:gestionnaire, email: email, password: password) }
let(:administrateur) { create(:administrateur, email: email, password: password) }
before { allow(Features).to receive(:unified_login).and_return(true) }
it 'signs user in' do
@ -44,6 +49,7 @@ describe Users::SessionsController, type: :controller do
expect(@response.redirect?).to be(true)
expect(subject.current_user).to eq(user)
expect(subject.current_gestionnaire).to be(nil)
expect(subject.current_administrateur).to be(nil)
expect(user.reload.loged_in_with_france_connect).to be(nil)
end
@ -52,21 +58,40 @@ describe Users::SessionsController, type: :controller do
expect(@response.redirect?).to be(true)
expect(subject.current_user).to be(nil)
expect(subject.current_gestionnaire).to eq(gestionnaire)
expect(subject.current_administrateur).to be(nil)
end
it 'signs user + gestionnaire in' do
post :create, params: {user: {email: user.email, password: gestionnaire.password}}
it 'signs administrateur in' do
post :create, params: {user: {email: administrateur.email, password: administrateur.password}}
expect(@response.redirect?).to be(true)
expect(subject.current_user).to eq(user)
expect(subject.current_gestionnaire).to eq(gestionnaire)
expect(user.reload.loged_in_with_france_connect).to be(nil)
expect(subject.current_user).to be(nil)
expect(subject.current_gestionnaire).to be(nil)
expect(subject.current_administrateur).to eq(administrateur)
end
context {
before do
user
gestionnaire
end
it 'signs user + gestionnaire + administrateur in' do
post :create, params: {user: {email: administrateur.email, password: administrateur.password}}
expect(@response.redirect?).to be(true)
expect(subject.current_user).to eq(user)
expect(subject.current_gestionnaire).to eq(gestionnaire)
expect(subject.current_administrateur).to eq(administrateur)
expect(user.reload.loged_in_with_france_connect).to be(nil)
end
}
it 'fails to sign in with bad credentials' do
post :create, params: {user: {email: user.email, password: 'wrong_password'}}
expect(@response.unauthorized?).to be(true)
expect(subject.current_user).to be(nil)
expect(subject.current_gestionnaire).to be(nil)
expect(subject.current_administrateur).to be(nil)
end
end
end
@ -136,6 +161,22 @@ describe Users::SessionsController, type: :controller do
delete :destroy
expect(@response.headers["Location"]).to eq(FRANCE_CONNECT.particulier_logout_endpoint)
end
context "when associated administrateur" do
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'password') }
it 'signs user + gestionnaire + administrateur out' do
sign_in user
sign_in gestionnaire
sign_in administrateur
delete :destroy
expect(@response.redirect?).to be(true)
expect(subject.current_user).to be(nil)
expect(subject.current_gestionnaire).to be(nil)
expect(subject.current_administrateur).to be(nil)
end
end
end
end

View file

@ -38,6 +38,7 @@ Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: true, port: 44_678 + ENV['TEST_ENV_NUMBER'].to_i, phantomjs_options: ['--proxy-type=none'], timeout: 180)
end
# ActiveSupport::Deprecation.silenced = true
Capybara.default_max_wait_time = 1