Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Make LDAP bind failure cause an ldap_error, rather than an invalid_cr…
Browse files Browse the repository at this point in the history
…edentials

Fixes omniauth#51
  • Loading branch information
Mack Talcott committed Nov 6, 2014
1 parent 9d36cdb commit 4095703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/omniauth-ldap/adaptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def bind_as(args = {})
result = false
@connection.open do |me|
rs = me.search args
if rs and rs.first and dn = rs.first.dn
raise ConnectionError.new("bind failed") unless rs

if rs.first and dn = rs.first.dn
password = args[:password]
method = args[:method] || @method
password = password.call if password.respond_to?(:call)
Expand Down
9 changes: 9 additions & 0 deletions spec/omniauth-ldap/adaptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,14 @@
adaptor.connection.should_receive(:bind).and_return(true)
adaptor.bind_as(args).should == rs
end

it "should raise a ConnectionError if the bind fails" do
adaptor = OmniAuth::LDAP::Adaptor.new({host: "192.168.1.126", method: 'plain', base: 'dc=score, dc=local', port: 389, uid: 'sAMAccountName', bind_dn: 'bind_dn', password: 'password'})
adaptor.connection.should_receive(:open).and_yield(adaptor.connection)
# Net::LDAP#search returns nil if the operation was not successful
adaptor.connection.should_receive(:search).with(args).and_return(nil)
adaptor.connection.should_receive(:bind).never
lambda { adaptor.bind_as(args) }.should raise_error OmniAuth::LDAP::Adaptor::ConnectionError
end
end
end

0 comments on commit 4095703

Please sign in to comment.