Skip to content

Commit 97d99fc

Browse files
authored
Merge pull request #109 from omniauth/feat/ldap-error-on-misconfiguration
2 parents 8093e82 + 8309643 commit 97d99fc

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.rubocop_gradual.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lib/omniauth-ldap/adaptor.rb:3925200886": [
2+
"lib/omniauth-ldap/adaptor.rb:928056405": [
33
[68, 7, 413, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 105664470]
44
],
55
"spec/integration/middleware_spec.rb:2185613788": [
@@ -12,7 +12,7 @@
1212
[4, 3, 12, "RSpec/BeforeAfterAll: Beware of using `before(:all)` as it may cause state to leak between tests. If you are using `rspec-rails`, and `use_transactional_fixtures` is enabled, then records created in `before(:all)` are not automatically rolled back.", 86334566],
1313
[70, 16, 5, "RSpec/ExpectActual: Provide the actual value you are testing to `expect(...)`.", 237881235]
1414
],
15-
"spec/omniauth-ldap/adaptor_spec.rb:1245381318": [
15+
"spec/omniauth-ldap/adaptor_spec.rb:1839434473": [
1616
[3, 1, 38, "RSpec/SpecFilePathFormat: Spec path should end with `omni_auth/ldap/adaptor*_spec.rb`.", 1973618936],
1717
[239, 9, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310],
1818
[240, 9, 26, "RSpec/StubbedMock: Prefer `allow` over `expect` when configuring a response.", 1924417310]

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("LDAP search operation 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 "raises a ConnectionError if the bind fails" do
315+
adaptor = described_class.new({host: "192.168.1.126", method: "plain", base: "dc=score, dc=local", port: 389, uid: "sAMAccountName", bind_dn: "bind_dn", password: "password"})
316+
allow(adaptor.connection).to receive(:open).and_yield(adaptor.connection)
317+
# Net::LDAP#search returns nil if the operation was not successful
318+
allow(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 described_class::ConnectionError
321+
end
313322
end
314323
end

0 commit comments

Comments
 (0)