debian-mirror-gitlab/spec/views/admin/sessions/new.html.haml_spec.rb

98 lines
3.1 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe 'admin/sessions/new.html.haml' do
2020-01-01 13:55:28 +05:30
let(:user) { create(:admin) }
before do
2020-05-24 23:13:21 +05:30
disable_all_signin_methods
2020-01-01 13:55:28 +05:30
allow(view).to receive(:current_user).and_return(user)
end
2019-12-21 20:55:43 +05:30
2020-01-01 13:55:28 +05:30
context 'internal admin user' do
2020-05-24 23:13:21 +05:30
before do
allow(view).to receive(:allow_admin_mode_password_authentication_for_web?).and_return(true)
end
2020-01-01 13:55:28 +05:30
it 'shows enter password form' do
2019-12-21 20:55:43 +05:30
render
2020-05-24 23:13:21 +05:30
expect(rendered).to have_selector('[data-qa-selector="sign_in_tab"]')
2019-12-21 20:55:43 +05:30
expect(rendered).to have_css('#login-pane.active')
2020-05-24 23:13:21 +05:30
expect(rendered).to have_selector('[data-qa-selector="password_field"]')
2019-12-21 20:55:43 +05:30
end
2020-01-01 13:55:28 +05:30
it 'warns authentication not possible if password not set' do
2020-05-24 23:13:21 +05:30
allow(view).to receive(:allow_admin_mode_password_authentication_for_web?).and_return(false)
2020-01-01 13:55:28 +05:30
render
expect(rendered).not_to have_css('#login-pane')
expect(rendered).to have_content _('No authentication methods configured.')
end
2019-12-21 20:55:43 +05:30
end
2020-01-01 13:55:28 +05:30
context 'omniauth authentication enabled' do
2019-12-21 20:55:43 +05:30
before do
2020-01-01 13:55:28 +05:30
allow(view).to receive(:omniauth_enabled?).and_return(true)
allow(view).to receive(:button_based_providers_enabled?).and_return(true)
2019-12-21 20:55:43 +05:30
end
2020-01-01 13:55:28 +05:30
it 'shows omniauth form' do
2019-12-21 20:55:43 +05:30
render
2020-01-01 13:55:28 +05:30
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-12-21 20:55:43 +05:30
end
end
2020-05-24 23:13:21 +05:30
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
expect(rendered).to have_selector('[data-qa-selector="ldap_tab"]')
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
expect(rendered).not_to have_selector('[data-qa-selector="ldap_tab"]')
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-12-21 20:55:43 +05:30
end