BigW Consortium Gitlab

adapter_spec.rb 984 Bytes
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::LDAP::Adapter, lib: true do
4
  let(:adapter) { Gitlab::LDAP::Adapter.new 'ldapmain' }
5

6
  describe '#dn_matches_filter?' do
7 8
    let(:ldap) { double(:ldap) }
    subject { adapter.dn_matches_filter?(:dn, :filter) }
9
    before { allow(adapter).to receive(:ldap).and_return(ldap) }
10 11 12

    context "when the search is successful" do
      context "and the result is non-empty" do
13
        before { allow(ldap).to receive(:search).and_return([:foo]) }
14

15
        it { is_expected.to be_truthy }
16 17 18
      end

      context "and the result is empty" do
19
        before { allow(ldap).to receive(:search).and_return([]) }
20

21
        it { is_expected.to be_falsey }
22 23 24 25
      end
    end

    context "when the search encounters an error" do
26 27 28 29 30 31
      before do
        allow(ldap).to receive_messages(
          search: nil,
          get_operation_result: double(code: 1, message: 'some error')
        )
      end
32

33
      it { is_expected.to be_falsey }
34 35 36
    end
  end
end