Skip to content

Commit b3e67d3

Browse files
committed
Raise Net::LDAP::ConnectionRefusedError when new connection is refused.
Now Net::LDAP::Connection.new raises Net::LDAP::Error even if the connection refused. It's hard for some application to reconnect it only when refused.
1 parent e7fde22 commit b3e67d3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/net/ldap/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(server)
1414
rescue SocketError
1515
raise Net::LDAP::Error, "No such address or other socket error."
1616
rescue Errno::ECONNREFUSED
17-
raise Net::LDAP::Error, "Server #{server[:host]} refused connection on port #{server[:port]}."
17+
raise Net::LDAP::ConnectionRefusedError, "Server #{server[:host]} refused connection on port #{server[:port]}."
1818
rescue Errno::EHOSTUNREACH => error
1919
raise Net::LDAP::Error, "Host #{server[:host]} was unreachable (#{error.message})"
2020
rescue Errno::ETIMEDOUT

test/test_ldap_connection.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def test_blocked_port
1414
end
1515
end
1616

17+
def test_connection_refused
18+
flexmock(TCPSocket).should_receive(:new).and_raise(Errno::ECONNREFUSED)
19+
assert_raise Net::LDAP::ConnectionRefusedError do
20+
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
21+
end
22+
end
23+
1724
def test_raises_unknown_exceptions
1825
error = Class.new(StandardError)
1926
flexmock(TCPSocket).should_receive(:new).and_raise(error)

0 commit comments

Comments
 (0)