Commit 430ceaa9 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch 'bug/ldap_dn_matches_filter' into 'master'

Handle LDAP errors in Adapter#dn_matches_filter?
parents ec73107d 4e9d2808
v 6.7.1
- Handle LDAP errors in Adapter#dn_matches_filter?
v 6.7.0 v 6.7.0
- Improve LDAP sign-in speed by reusing connections - Improve LDAP sign-in speed by reusing connections
- Add support for Active Directory nested LDAP groups - Add support for Active Directory nested LDAP groups
......
...@@ -107,7 +107,12 @@ module Gitlab ...@@ -107,7 +107,12 @@ module Gitlab
end end
def dn_matches_filter?(dn, filter) def dn_matches_filter?(dn, filter)
ldap.search(base: dn, filter: filter, attributes: %w{dn}).any? results = ldap.search(base: dn, filter: filter, attributes: %w{dn})
if results.nil?
false # Net::LDAP encountered an LDAP error
else
results.any?
end
end end
private private
......
require 'spec_helper'
describe Gitlab::LDAP::Adapter do
let(:adapter) { Gitlab::LDAP::Adapter.new }
describe :dn_matches_filter? do
let(:ldap) { double(:ldap) }
subject { adapter.dn_matches_filter?(:dn, :filter) }
before { adapter.stub(ldap: ldap) }
context "when the search is successful" do
context "and the result is non-empty" do
before { ldap.stub(search: [:foo]) }
it { should be_true }
end
context "and the result is empty" do
before { ldap.stub(search: []) }
it { should be_false }
end
end
context "when the search encounters an error" do
before { ldap.stub(search: nil) }
it { should be_false }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment