gitlab-org--gitlab-foss/spec/lib/gitlab/ldap/adapter_spec.rb

37 lines
984 B
Ruby
Raw Normal View History

require 'spec_helper'
2015-12-09 05:55:36 -05:00
describe Gitlab::LDAP::Adapter, lib: true do
let(:adapter) { Gitlab::LDAP::Adapter.new 'ldapmain' }
2015-05-21 17:49:06 -04:00
describe '#dn_matches_filter?' do
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) }
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]) }
it { is_expected.to be_truthy }
end
context "and the result is empty" do
2015-05-21 17:49:06 -04:00
before { allow(ldap).to receive(:search).and_return([]) }
it { is_expected.to be_falsey }
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
it { is_expected.to be_falsey }
end
end
end