Can connect admin with user session path
This commit is contained in:
parent
5915a2b7d5
commit
715f086957
3 changed files with 54 additions and 10 deletions
|
@ -24,6 +24,7 @@ class Users::SessionsController < Sessions::SessionsController
|
||||||
def create
|
def create
|
||||||
try_to_authenticate(User)
|
try_to_authenticate(User)
|
||||||
try_to_authenticate(Gestionnaire) if Features.unified_login
|
try_to_authenticate(Gestionnaire) if Features.unified_login
|
||||||
|
try_to_authenticate(Administrateur) if Features.unified_login
|
||||||
|
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
current_user.update_attributes(loged_in_with_france_connect: '')
|
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)
|
redirect_to after_sign_in_path_for(:user)
|
||||||
elsif gestionnaire_signed_in?
|
elsif gestionnaire_signed_in?
|
||||||
redirect_to backoffice_path
|
redirect_to backoffice_path
|
||||||
|
elsif administrateur_signed_in?
|
||||||
|
redirect_to admin_path
|
||||||
else
|
else
|
||||||
new
|
new
|
||||||
render :new, status: 401
|
render :new, status: 401
|
||||||
|
@ -41,9 +44,8 @@ class Users::SessionsController < Sessions::SessionsController
|
||||||
|
|
||||||
# DELETE /resource/sign_out
|
# DELETE /resource/sign_out
|
||||||
def destroy
|
def destroy
|
||||||
if gestionnaire_signed_in?
|
sign_out :gestionnaire if gestionnaire_signed_in?
|
||||||
sign_out :gestionnaire
|
sign_out :administrateur if administrateur_signed_in?
|
||||||
end
|
|
||||||
|
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
connected_with_france_connect = current_user.loged_in_with_france_connect
|
connected_with_france_connect = current_user.loged_in_with_france_connect
|
||||||
|
|
|
@ -35,8 +35,13 @@ describe Users::SessionsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "unified login" do
|
context "unified login" do
|
||||||
let(:user) { create(:user, email: 'unique@plop.com', password: 'password') }
|
let(:email) { 'unique@plop.com' }
|
||||||
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') }
|
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) }
|
before { allow(Features).to receive(:unified_login).and_return(true) }
|
||||||
|
|
||||||
it 'signs user in' do
|
it 'signs user in' do
|
||||||
|
@ -44,6 +49,7 @@ describe Users::SessionsController, type: :controller do
|
||||||
expect(@response.redirect?).to be(true)
|
expect(@response.redirect?).to be(true)
|
||||||
expect(subject.current_user).to eq(user)
|
expect(subject.current_user).to eq(user)
|
||||||
expect(subject.current_gestionnaire).to be(nil)
|
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)
|
expect(user.reload.loged_in_with_france_connect).to be(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,21 +58,40 @@ describe Users::SessionsController, type: :controller do
|
||||||
expect(@response.redirect?).to be(true)
|
expect(@response.redirect?).to be(true)
|
||||||
expect(subject.current_user).to be(nil)
|
expect(subject.current_user).to be(nil)
|
||||||
expect(subject.current_gestionnaire).to eq(gestionnaire)
|
expect(subject.current_gestionnaire).to eq(gestionnaire)
|
||||||
|
expect(subject.current_administrateur).to be(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'signs user + gestionnaire in' do
|
it 'signs administrateur in' do
|
||||||
post :create, params: {user: {email: user.email, password: gestionnaire.password}}
|
post :create, params: {user: {email: administrateur.email, password: administrateur.password}}
|
||||||
expect(@response.redirect?).to be(true)
|
expect(@response.redirect?).to be(true)
|
||||||
expect(subject.current_user).to eq(user)
|
expect(subject.current_user).to be(nil)
|
||||||
expect(subject.current_gestionnaire).to eq(gestionnaire)
|
expect(subject.current_gestionnaire).to be(nil)
|
||||||
expect(user.reload.loged_in_with_france_connect).to be(nil)
|
expect(subject.current_administrateur).to eq(administrateur)
|
||||||
end
|
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
|
it 'fails to sign in with bad credentials' do
|
||||||
post :create, params: {user: {email: user.email, password: 'wrong_password'}}
|
post :create, params: {user: {email: user.email, password: 'wrong_password'}}
|
||||||
expect(@response.unauthorized?).to be(true)
|
expect(@response.unauthorized?).to be(true)
|
||||||
expect(subject.current_user).to be(nil)
|
expect(subject.current_user).to be(nil)
|
||||||
expect(subject.current_gestionnaire).to be(nil)
|
expect(subject.current_gestionnaire).to be(nil)
|
||||||
|
expect(subject.current_administrateur).to be(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -136,6 +161,22 @@ describe Users::SessionsController, type: :controller do
|
||||||
delete :destroy
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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
|
end
|
||||||
|
|
||||||
|
# ActiveSupport::Deprecation.silenced = true
|
||||||
|
|
||||||
Capybara.default_max_wait_time = 1
|
Capybara.default_max_wait_time = 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue