debian-mirror-gitlab/spec/lib/gitlab/ldap/adapter_spec.rb

37 lines
973 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe Gitlab::LDAP::Adapter do
2015-04-26 12:48:37 +05:30
let(:adapter) { Gitlab::LDAP::Adapter.new 'ldapmain' }
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
describe '#dn_matches_filter?' do
2014-09-02 18:07:02 +05:30
let(:ldap) { double(:ldap) }
subject { adapter.dn_matches_filter?(:dn, :filter) }
2015-09-11 14:41:01 +05:30
before { allow(adapter).to receive(:ldap).and_return(ldap) }
2014-09-02 18:07:02 +05:30
context "when the search is successful" do
context "and the result is non-empty" do
2015-09-11 14:41:01 +05:30
before { allow(ldap).to receive(:search).and_return([:foo]) }
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
it { is_expected.to be_truthy }
2014-09-02 18:07:02 +05:30
end
context "and the result is empty" do
2015-09-11 14:41:01 +05:30
before { allow(ldap).to receive(:search).and_return([]) }
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
it { is_expected.to be_falsey }
2014-09-02 18:07:02 +05:30
end
end
context "when the search encounters an error" do
2015-09-11 14:41:01 +05:30
before do
allow(ldap).to receive_messages(
search: nil,
get_operation_result: double(code: 1, message: 'some error')
)
end
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
it { is_expected.to be_falsey }
2014-09-02 18:07:02 +05:30
end
end
end