Skip to content

Commit 9bf1f30

Browse files
committed
Raise exception when specifying undefined auth method
1 parent fbb1951 commit 9bf1f30

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/net/ldap/auth_adapter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ def self.register(names, adapter)
1010
end
1111

1212
def self.[](name)
13-
@adapters[name]
13+
a = @adapters[name]
14+
if a.nil?
15+
raise Net::LDAP::AuthMethodUnsupportedError, "Unsupported auth method (#{name})"
16+
end
17+
return a
1418
end
1519

1620
def initialize(conn)

test/test_auth_adapter.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'test_helper'
2+
3+
class TestAuthAdapter < Test::Unit::TestCase
4+
def test_undefined_auth_adapter
5+
flexmock(TCPSocket).should_receive(:new).ordered.with('ldap.example.com', 379).once.and_return(nil)
6+
conn = Net::LDAP::Connection.new(host: 'ldap.example.com', port: 379)
7+
assert_raise Net::LDAP::AuthMethodUnsupportedError, "Unsupported auth method (foo)" do
8+
conn.bind(method: :foo)
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)