Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/auth/ldap/adapter_spec.rb')
-rw-r--r--spec/lib/gitlab/auth/ldap/adapter_spec.rb75
1 files changed, 54 insertions, 21 deletions
diff --git a/spec/lib/gitlab/auth/ldap/adapter_spec.rb b/spec/lib/gitlab/auth/ldap/adapter_spec.rb
index 8546d63cf77..b7b12e49a8e 100644
--- a/spec/lib/gitlab/auth/ldap/adapter_spec.rb
+++ b/spec/lib/gitlab/auth/ldap/adapter_spec.rb
@@ -95,6 +95,40 @@ RSpec.describe Gitlab::Auth::Ldap::Adapter do
describe '#ldap_search' do
subject { adapter.ldap_search(base: :dn, filter: :filter) }
+ shared_examples 'connection retry' do
+ before do
+ allow(adapter).to receive(:renew_connection_adapter).and_return(ldap)
+ allow(Gitlab::AppLogger).to receive(:warn)
+ end
+
+ context 'retries the operation' do
+ before do
+ stub_const("#{described_class}::MAX_SEARCH_RETRIES", 3)
+ end
+
+ it 'as many times as MAX_SEARCH_RETRIES' do
+ expect(ldap).to receive(:search).exactly(3).times
+ expect { subject }.to raise_error(Gitlab::Auth::Ldap::LdapConnectionError)
+ end
+
+ context 'when no more retries' do
+ before do
+ stub_const("#{described_class}::MAX_SEARCH_RETRIES", 1)
+ end
+
+ it 'raises the exception' do
+ expect { subject }.to raise_error(Gitlab::Auth::Ldap::LdapConnectionError)
+ end
+
+ it 'logs the error' do
+ expect { subject }.to raise_error(Gitlab::Auth::Ldap::LdapConnectionError)
+ expect(Gitlab::AppLogger).to have_received(:warn).with(
+ "LDAP search raised exception Net::LDAP::Error: #{err_message}")
+ end
+ end
+ end
+ end
+
context "when the search is successful" do
context "and the result is non-empty" do
before do
@@ -110,6 +144,22 @@ RSpec.describe Gitlab::Auth::Ldap::Adapter do
end
it { is_expected.to eq [] }
+
+ context 'when returned with expected code' do
+ let(:response_code) { 80 }
+ let(:response_message) { 'Other' }
+ let(:err_message) { "Got empty results with response code: #{response_code}, message: #{response_message}" }
+
+ before do
+ stub_ldap_config(retry_empty_result_with_codes: [response_code])
+ allow(ldap).to receive_messages(
+ search: nil,
+ get_operation_result: double(code: response_code, message: response_message)
+ )
+ end
+
+ it_behaves_like 'connection retry'
+ end
end
end
@@ -132,30 +182,13 @@ RSpec.describe Gitlab::Auth::Ldap::Adapter do
end
context 'retries the operation' do
- before do
- stub_const("#{described_class}::MAX_SEARCH_RETRIES", 3)
- end
+ let(:err_message) { 'some error' }
- it 'as many times as MAX_SEARCH_RETRIES' do
- expect(ldap).to receive(:search).exactly(3).times
- expect { subject }.to raise_error(Gitlab::Auth::Ldap::LdapConnectionError)
+ before do
+ allow(ldap).to receive(:search) { raise Net::LDAP::Error, err_message }
end
- context 'when no more retries' do
- before do
- stub_const("#{described_class}::MAX_SEARCH_RETRIES", 1)
- end
-
- it 'raises the exception' do
- expect { subject }.to raise_error(Gitlab::Auth::Ldap::LdapConnectionError)
- end
-
- it 'logs the error' do
- expect { subject }.to raise_error(Gitlab::Auth::Ldap::LdapConnectionError)
- expect(Gitlab::AppLogger).to have_received(:warn).with(
- "LDAP search raised exception Net::LDAP::Error: some error")
- end
- end
+ it_behaves_like 'connection retry'
end
end
end