Skip to content

Commit 67d6c58

Browse files
committed
Remove deprecated ConnectionRefusedError
ConnectionError.new was returning a deprecated ConnectionRefusedError, this pattern was introduced for backward compatibility at some point, but there seems to be no other usage of `ConnectionRefusedError` needed in the codebase. If we need to keep the class around for external backward compatibility, I would recommend that we introduce a private-ish way to initialize `ConnectionRefusedError` without raising the deprecation warning. I'm happy to PR such a change, but it seems that we could bump the version and get rid of this deprecation in the library.
1 parent 87ae9b8 commit 67d6c58

File tree

4 files changed

+9
-30
lines changed

4 files changed

+9
-30
lines changed

lib/net/ldap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ def new_connection
13201320
# Force connect to see if there's a connection error
13211321
connection.socket
13221322
connection
1323-
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Net::LDAP::ConnectionRefusedError => e
1323+
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
13241324
@result = {
13251325
:resultCode => 52,
13261326
:errorMessage => ResultStrings[ResultCodeUnavailable],

lib/net/ldap/error.rb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,11 @@ class Error < StandardError; end
99

1010
class AlreadyOpenedError < Error; end
1111
class SocketError < Error; end
12-
class ConnectionRefusedError < Error;
13-
def initialize(*args)
14-
warn_deprecation_message
15-
super
16-
end
17-
18-
def message
19-
warn_deprecation_message
20-
super
21-
end
22-
23-
private
24-
25-
def warn_deprecation_message
26-
warn "Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead."
27-
end
28-
end
2912
class ConnectionError < Error
3013
def self.new(errors)
3114
error = errors.first.first
3215
if errors.size == 1
33-
if error.kind_of? Errno::ECONNREFUSED
34-
return Net::LDAP::ConnectionRefusedError.new(error.message)
35-
end
16+
return error if error.is_a? Errno::ECONNREFUSED
3617

3718
return Net::LDAP::Error.new(error.message)
3819
end

test/integration/test_bind.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require_relative '../test_helper'
22

33
class TestBindIntegration < LDAPIntegrationTestCase
4-
54
INTEGRATION_HOSTNAME = 'ldap.example.org'.freeze
65

76
def test_bind_success
@@ -28,7 +27,7 @@ def test_bind_anonymous_fail
2827
assert_equal Net::LDAP::ResultCodeUnwillingToPerform, result.code
2928
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeUnwillingToPerform], result.message
3029
assert_equal "unauthenticated bind (DN with no password) disallowed",
31-
result.error_message
30+
result.error_message
3231
assert_equal "", result.matched_dn
3332
end
3433

@@ -75,7 +74,7 @@ def test_bind_tls_with_bad_hostname_verify_peer_ca_fails
7574
ca_file: CA_FILE },
7675
)
7776
error = assert_raise Net::LDAP::Error,
78-
Net::LDAP::ConnectionRefusedError do
77+
Errno::ECONNREFUSED do
7978
@ldap.bind BIND_CREDS
8079
end
8180
assert_equal(
@@ -91,7 +90,7 @@ def test_bind_tls_with_bad_hostname_ca_default_opt_merge_fails
9190
tls_options: TLS_OPTS.merge(ca_file: CA_FILE),
9291
)
9392
error = assert_raise Net::LDAP::Error,
94-
Net::LDAP::ConnectionRefusedError do
93+
Errno::ECONNREFUSED do
9594
@ldap.bind BIND_CREDS
9695
end
9796
assert_equal(
@@ -107,7 +106,7 @@ def test_bind_tls_with_bad_hostname_ca_no_opt_merge_fails
107106
tls_options: { ca_file: CA_FILE },
108107
)
109108
error = assert_raise Net::LDAP::Error,
110-
Net::LDAP::ConnectionRefusedError do
109+
Errno::ECONNREFUSED do
111110
@ldap.bind BIND_CREDS
112111
end
113112
assert_equal(
@@ -142,7 +141,7 @@ def test_bind_tls_with_bogus_hostname_system_ca_fails
142141
@ldap.host = '127.0.0.1'
143142
@ldap.encryption(method: :start_tls, tls_options: {})
144143
error = assert_raise Net::LDAP::Error,
145-
Net::LDAP::ConnectionRefusedError do
144+
Errno::ECONNREFUSED do
146145
@ldap.bind BIND_CREDS
147146
end
148147
assert_equal(

test/test_ldap_connection.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_result_for_connection_failed_is_set
6161

6262
ldap_client = Net::LDAP.new(host: '127.0.0.1', port: 12345)
6363

64-
assert_raise Net::LDAP::ConnectionRefusedError do
64+
assert_raise Errno::ECONNREFUSED do
6565
ldap_client.bind(method: :simple, username: 'asdf', password: 'asdf')
6666
end
6767

@@ -86,11 +86,10 @@ def test_blocked_port
8686
def test_connection_refused
8787
connection = Net::LDAP::Connection.new(:host => "fail.Errno::ECONNREFUSED", :port => 636, :socket_class => FakeTCPSocket)
8888
stderr = capture_stderr do
89-
assert_raise Net::LDAP::ConnectionRefusedError do
89+
assert_raise Errno::ECONNREFUSED do
9090
connection.socket
9191
end
9292
end
93-
assert_equal("Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead.\n", stderr)
9493
end
9594

9695
def test_connection_timeout

0 commit comments

Comments
 (0)