debian-mirror-gitlab/spec/tasks/gitlab/check_rake_spec.rb

119 lines
2.9 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'rake_helper'
2019-02-15 15:39:39 +05:30
describe 'check.rake' do
2017-08-17 22:00:37 +05:30
before do
Rake.application.rake_require 'tasks/gitlab/check'
stub_warn_user_is_not_gitlab
end
2019-02-15 15:39:39 +05:30
shared_examples_for 'system check rake task' do
it 'runs the check' do
expect do
subject
end.to output(/Checking #{name} ... Finished/).to_stdout
2019-01-03 12:48:30 +05:30
end
2018-12-23 12:14:25 +05:30
end
2019-02-15 15:39:39 +05:30
describe 'gitlab:check rake task' do
subject { run_rake_task('gitlab:check') }
2019-12-21 20:55:43 +05:30
2019-02-15 15:39:39 +05:30
let(:name) { 'GitLab subtasks' }
2018-12-23 12:14:25 +05:30
2019-02-15 15:39:39 +05:30
it_behaves_like 'system check rake task'
end
describe 'gitlab:gitlab_shell:check rake task' do
subject { run_rake_task('gitlab:gitlab_shell:check') }
2019-12-21 20:55:43 +05:30
2019-02-15 15:39:39 +05:30
let(:name) { 'GitLab Shell' }
it_behaves_like 'system check rake task'
end
describe 'gitlab:gitaly:check rake task' do
subject { run_rake_task('gitlab:gitaly:check') }
2019-12-21 20:55:43 +05:30
2019-02-15 15:39:39 +05:30
let(:name) { 'Gitaly' }
it_behaves_like 'system check rake task'
end
describe 'gitlab:sidekiq:check rake task' do
subject { run_rake_task('gitlab:sidekiq:check') }
2019-12-21 20:55:43 +05:30
2019-02-15 15:39:39 +05:30
let(:name) { 'Sidekiq' }
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
it_behaves_like 'system check rake task'
end
2018-12-23 12:14:25 +05:30
2019-02-15 15:39:39 +05:30
describe 'gitlab:incoming_email:check rake task' do
subject { run_rake_task('gitlab:incoming_email:check') }
2019-12-21 20:55:43 +05:30
2019-02-15 15:39:39 +05:30
let(:name) { 'Incoming Email' }
2018-12-23 12:14:25 +05:30
2019-02-15 15:39:39 +05:30
it_behaves_like 'system check rake task'
end
describe 'gitlab:ldap:check rake task' do
include LdapHelpers
subject { run_rake_task('gitlab:ldap:check') }
2019-12-21 20:55:43 +05:30
2019-02-15 15:39:39 +05:30
let(:name) { 'LDAP' }
it_behaves_like 'system check rake task'
context 'when LDAP is not enabled' do
it 'does not attempt to bind or search for users' do
2020-04-08 14:13:33 +05:30
expect(Gitlab::Auth::Ldap::Config).not_to receive(:providers)
expect(Gitlab::Auth::Ldap::Adapter).not_to receive(:open)
2019-02-15 15:39:39 +05:30
subject
end
2019-01-03 12:48:30 +05:30
end
2018-12-23 12:14:25 +05:30
2019-02-15 15:39:39 +05:30
context 'when LDAP is enabled' do
let(:ldap) { double(:ldap) }
let(:adapter) { ldap_adapter('ldapmain', ldap) }
before do
2020-04-08 14:13:33 +05:30
allow(Gitlab::Auth::Ldap::Config)
2019-02-15 15:39:39 +05:30
.to receive_messages(
enabled?: true,
providers: ['ldapmain']
)
2020-04-08 14:13:33 +05:30
allow(Gitlab::Auth::Ldap::Adapter).to receive(:open).and_yield(adapter)
2019-02-15 15:39:39 +05:30
allow(adapter).to receive(:users).and_return([])
end
it 'attempts to bind using credentials' do
stub_ldap_config(has_auth?: true)
expect(ldap).to receive(:bind)
subject
end
it 'searches for 100 LDAP users' do
stub_ldap_config(uid: 'uid')
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
expect(adapter).to receive(:users).with('uid', '*', 100)
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
subject
end
2019-09-30 21:07:59 +05:30
it 'sanitizes output' do
user = double(dn: 'uid=fake_user1', uid: 'fake_user1')
allow(adapter).to receive(:users).and_return([user])
stub_env('SANITIZE', 'true')
expect { subject }.to output(/User output sanitized/).to_stdout
expect { subject }.not_to output('fake_user1').to_stdout
end
2017-08-17 22:00:37 +05:30
end
end
end