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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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'
2020-07-28 23:09:34 +05:30
RSpec.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
2022-10-11 01:57:18 +05:30
expect(rendered).to have_selector('[data-testid="sign-in-tab"]')
2019-12-21 20:55:43 +05:30
expect(rendered).to have_css('#login-pane.active')
2022-10-11 01:57:18 +05:30
expect(rendered).to have_selector('[data-testid="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).not_to have_content _('No authentication methods configured.')
2023-07-09 08:55:56 +05:30
expect(rendered).to have_content _('or')
expect(rendered).to have_css('.omniauth-container')
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
2022-10-11 01:57:18 +05:30
expect(rendered).to have_selector('[data-testid="ldap-tab"]')
2020-05-24 23:13:21 +05:30
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
2022-10-11 01:57:18 +05:30
expect(rendered).not_to have_selector('[data-testid="ldap-tab"]')
2020-05-24 23:13:21 +05:30
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