Commit 48fa4ec0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch 'handle-ldap-errors' into 'master'

Handle ldap errors

Fixes #85
parents de68bada eff30fff
......@@ -62,7 +62,7 @@ module Gitlab
options.merge!(size: size) if size
ldap.search(options).map do |entry|
ldap_search(options).map do |entry|
Gitlab::LDAP::Group.new(entry, self)
end
end
......@@ -93,7 +93,7 @@ module Gitlab
end
end
entries = ldap.search(options).select do |entry|
entries = ldap_search(options).select do |entry|
entry.respond_to? config.uid
end
......@@ -107,11 +107,22 @@ module Gitlab
end
def dn_matches_filter?(dn, filter)
results = ldap.search(base: dn, filter: filter, attributes: %w{dn})
ldap_search(base: dn, filter: filter, attributes: %w{dn}).any?
end
def ldap_search(*args)
results = ldap.search(*args)
if results.nil?
false # Net::LDAP encountered an LDAP error
response = ldap.get_operation_result
unless response.code.zero?
Rails.logger.warn("LDAP search error: #{response.message}")
end
[]
else
results.any?
results
end
end
......
......@@ -9,7 +9,7 @@ module Gitlab
class Person
def self.find_by_uid(uid, adapter=nil)
adapter ||= Gitlab::LDAP::Adapter.new
adapter.user(config.uid, uid)
adapter.user(Gitlab.config.ldap.uid, uid)
end
def self.find_by_dn(dn, adapter=nil)
......
......@@ -23,7 +23,7 @@ describe Gitlab::LDAP::Adapter do
end
context "when the search encounters an error" do
before { ldap.stub(search: nil) }
before { ldap.stub(search: nil, get_operation_result: double(code: 1, message: 'some error')) }
it { should be_false }
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