Skip to content

Commit 6f6be75

Browse files
Mack Talcottpboling
authored andcommitted
Make LDAP bind failure cause an ldap_error, rather than an invalid_credentials
Fixes #51
1 parent 8093e82 commit 6f6be75

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Please file a bug if you notice a violation of semantic versioning.
3131
- https://datatracker.ietf.org/doc/html/draft-behera-ldap-password-policy-11
3232
- Support for JSON bodies
3333
- Support custom LDAP attributes mapping
34+
- Raise a distinct error when LDAP server is unreachable
35+
- Previously raised an invalid credentials authentication failure error, which is technically incorrect
3436

3537
### Changed
3638

lib/omniauth-ldap/adaptor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def bind_as(args = {})
134134
@last_password_policy_response = nil
135135
@connection.open do |me|
136136
rs = me.search(args)
137+
raise ConnectionError.new("bind failed") unless rs
138+
137139
if rs && rs.first
138140
dn = rs.first.dn
139141
if dn

spec/omniauth-ldap/adaptor_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,14 @@ def mock_conn(opts = {})
310310
expect(@last_bind_args[:controls].first).to include(oid: ppolicy_oid)
311311
expect(adaptor.last_password_policy_response.oid).to eq(ppolicy_oid)
312312
end
313+
314+
it "should raise a ConnectionError if the bind fails" do
315+
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'})
316+
expect(adaptor.connection).to receive(:open).and_yield(adaptor.connection)
317+
# Net::LDAP#search returns nil if the operation was not successful
318+
expect(adaptor.connection).to receive(:search).with(args).and_return(nil)
319+
expect(adaptor.connection).not_to receive(:bind)
320+
expect { adaptor.bind_as(args) }.to raise_error OmniAuth::LDAP::Adaptor::ConnectionError
321+
end
313322
end
314323
end

0 commit comments

Comments
 (0)