2019-10-08 12:06:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-26 12:06:00 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe 'admin/sessions/new.html.haml' do
|
2019-12-11 12:08:10 +00:00
|
|
|
let(:user) { create(:admin) }
|
|
|
|
|
|
|
|
before do
|
2020-04-24 15:09:37 +00:00
|
|
|
disable_all_signin_methods
|
|
|
|
|
2019-12-11 12:08:10 +00:00
|
|
|
allow(view).to receive(:current_user).and_return(user)
|
|
|
|
end
|
2019-09-26 12:06:00 +00:00
|
|
|
|
2019-12-11 12:08:10 +00:00
|
|
|
context 'internal admin user' do
|
2020-04-24 15:09:37 +00:00
|
|
|
before do
|
|
|
|
allow(view).to receive(:allow_admin_mode_password_authentication_for_web?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2019-12-11 12:08:10 +00:00
|
|
|
it 'shows enter password form' do
|
2019-09-26 12:06:00 +00:00
|
|
|
render
|
|
|
|
|
2021-08-03 18:10:02 +00:00
|
|
|
expect(rendered).to have_selector('[data-qa-selector="sign_in_tab"]') # rubocop:disable QA/SelectorUsage
|
2019-09-26 12:06:00 +00:00
|
|
|
expect(rendered).to have_css('#login-pane.active')
|
2021-08-03 18:10:02 +00:00
|
|
|
expect(rendered).to have_selector('[data-qa-selector="password_field"]') # rubocop:disable QA/SelectorUsage
|
2019-09-26 12:06:00 +00:00
|
|
|
end
|
2019-12-11 12:08:10 +00:00
|
|
|
|
|
|
|
it 'warns authentication not possible if password not set' do
|
2020-04-24 15:09:37 +00:00
|
|
|
allow(view).to receive(:allow_admin_mode_password_authentication_for_web?).and_return(false)
|
2019-12-11 12:08:10 +00:00
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_css('#login-pane')
|
|
|
|
expect(rendered).to have_content _('No authentication methods configured.')
|
|
|
|
end
|
2019-09-26 12:06:00 +00:00
|
|
|
end
|
|
|
|
|
2019-12-11 12:08:10 +00:00
|
|
|
context 'omniauth authentication enabled' do
|
2019-09-26 12:06:00 +00:00
|
|
|
before do
|
2019-12-11 12:08:10 +00:00
|
|
|
allow(view).to receive(:omniauth_enabled?).and_return(true)
|
|
|
|
allow(view).to receive(:button_based_providers_enabled?).and_return(true)
|
2019-09-26 12:06:00 +00:00
|
|
|
end
|
|
|
|
|
2019-12-11 12:08:10 +00:00
|
|
|
it 'shows omniauth form' do
|
2019-09-26 12:06:00 +00:00
|
|
|
render
|
|
|
|
|
2019-12-11 12:08:10 +00:00
|
|
|
expect(rendered).to have_css('.omniauth-container')
|
|
|
|
expect(rendered).to have_content _('Sign in with')
|
|
|
|
expect(rendered).not_to have_content _('No authentication methods configured.')
|
2019-09-26 12:06:00 +00:00
|
|
|
end
|
|
|
|
end
|
2020-04-24 15:09:37 +00:00
|
|
|
|
|
|
|
context 'ldap authentication' do
|
|
|
|
let(:user) { create(:omniauth_user, :admin, extern_uid: 'my-uid', provider: 'ldapmain') }
|
|
|
|
let(:server) { { provider_name: 'ldapmain', label: 'LDAP' }.with_indifferent_access }
|
|
|
|
|
|
|
|
before do
|
|
|
|
enable_ldap
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is shown when enabled' do
|
|
|
|
render
|
|
|
|
|
2021-08-03 18:10:02 +00:00
|
|
|
expect(rendered).to have_selector('[data-qa-selector="ldap_tab"]') # rubocop:disable QA/SelectorUsage
|
2020-04-24 15:09:37 +00:00
|
|
|
expect(rendered).to have_css('.login-box#ldapmain')
|
|
|
|
expect(rendered).to have_field('LDAP Username')
|
|
|
|
expect(rendered).not_to have_content('No authentication methods configured')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not shown when LDAP sign in is disabled' do
|
|
|
|
disable_ldap_sign_in
|
|
|
|
|
|
|
|
render
|
|
|
|
|
2021-08-03 18:10:02 +00:00
|
|
|
expect(rendered).not_to have_selector('[data-qa-selector="ldap_tab"]') # rubocop:disable QA/SelectorUsage
|
2020-04-24 15:09:37 +00:00
|
|
|
expect(rendered).not_to have_field('LDAP Username')
|
|
|
|
expect(rendered).to have_content('No authentication methods configured')
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable_ldap
|
|
|
|
allow(view).to receive(:ldap_servers).and_return([server])
|
|
|
|
allow(view).to receive(:form_based_providers).and_return([:ldapmain])
|
|
|
|
allow(view).to receive(:omniauth_callback_path).with(:user, 'ldapmain').and_return('/ldapmain')
|
|
|
|
allow(view).to receive(:ldap_sign_in_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable_ldap_sign_in
|
|
|
|
allow(view).to receive(:ldap_sign_in_enabled?).and_return(false)
|
|
|
|
allow(view).to receive(:ldap_servers).and_return([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable_all_signin_methods
|
|
|
|
allow(view).to receive(:password_authentication_enabled_for_web?).and_return(false)
|
|
|
|
allow(view).to receive(:omniauth_enabled?).and_return(false)
|
|
|
|
allow(view).to receive(:ldap_sign_in_enabled?).and_return(false)
|
|
|
|
end
|
2019-09-26 12:06:00 +00:00
|
|
|
end
|