2014-05-14 12:11:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::LDAP::Adapter, lib: true do
|
2014-10-13 11:33:44 -04:00
|
|
|
let(:adapter) { Gitlab::LDAP::Adapter.new 'ldapmain' }
|
2014-05-14 12:11:14 -04:00
|
|
|
|
2015-05-21 17:49:06 -04:00
|
|
|
describe '#dn_matches_filter?' do
|
2014-05-14 12:11:14 -04:00
|
|
|
let(:ldap) { double(:ldap) }
|
|
|
|
subject { adapter.dn_matches_filter?(:dn, :filter) }
|
2015-05-21 17:49:06 -04:00
|
|
|
before { allow(adapter).to receive(:ldap).and_return(ldap) }
|
2014-05-14 12:11:14 -04:00
|
|
|
|
|
|
|
context "when the search is successful" do
|
|
|
|
context "and the result is non-empty" do
|
2015-05-21 17:49:06 -04:00
|
|
|
before { allow(ldap).to receive(:search).and_return([:foo]) }
|
2014-05-14 12:11:14 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_truthy }
|
2014-05-14 12:11:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "and the result is empty" do
|
2015-05-21 17:49:06 -04:00
|
|
|
before { allow(ldap).to receive(:search).and_return([]) }
|
2014-05-14 12:11:14 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_falsey }
|
2014-05-14 12:11:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the search encounters an error" do
|
2015-05-21 17:49:06 -04:00
|
|
|
before do
|
|
|
|
allow(ldap).to receive_messages(
|
|
|
|
search: nil,
|
|
|
|
get_operation_result: double(code: 1, message: 'some error')
|
|
|
|
)
|
|
|
|
end
|
2014-05-14 12:11:14 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to be_falsey }
|
2014-05-14 12:11:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|