Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated ConnectionRefusedError #366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ def new_connection
# Force connect to see if there's a connection error
connection.socket
connection
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Net::LDAP::ConnectionRefusedError => e
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
@result = {
:resultCode => 52,
:errorMessage => ResultStrings[ResultCodeUnavailable],
Expand Down
27 changes: 1 addition & 26 deletions lib/net/ldap/error.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
class Net::LDAP
class LdapError < StandardError
def message
"Deprecation warning: Net::LDAP::LdapError is no longer used. Use Net::LDAP::Error or rescue one of it's subclasses. \n" + super
end
end

class Error < StandardError; end

class AlreadyOpenedError < Error; end
class SocketError < Error; end
class ConnectionRefusedError < Error;
def initialize(*args)
warn_deprecation_message
super
end

def message
warn_deprecation_message
super
end

private

def warn_deprecation_message
warn "Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead."
end
end
class ConnectionError < Error
def self.new(errors)
error = errors.first.first
if errors.size == 1
if error.kind_of? Errno::ECONNREFUSED
return Net::LDAP::ConnectionRefusedError.new(error.message)
end
return error if error.is_a? Errno::ECONNREFUSED

return Net::LDAP::Error.new(error.message)
end
Expand Down
11 changes: 5 additions & 6 deletions test/integration/test_bind.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative '../test_helper'

class TestBindIntegration < LDAPIntegrationTestCase

INTEGRATION_HOSTNAME = 'ldap.example.org'.freeze

def test_bind_success
Expand All @@ -28,7 +27,7 @@ def test_bind_anonymous_fail
assert_equal Net::LDAP::ResultCodeUnwillingToPerform, result.code
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeUnwillingToPerform], result.message
assert_equal "unauthenticated bind (DN with no password) disallowed",
result.error_message
result.error_message
assert_equal "", result.matched_dn
end

Expand Down Expand Up @@ -75,7 +74,7 @@ def test_bind_tls_with_bad_hostname_verify_peer_ca_fails
ca_file: CA_FILE },
)
error = assert_raise Net::LDAP::Error,
Net::LDAP::ConnectionRefusedError do
Errno::ECONNREFUSED do
@ldap.bind BIND_CREDS
end
assert_equal(
Expand All @@ -91,7 +90,7 @@ def test_bind_tls_with_bad_hostname_ca_default_opt_merge_fails
tls_options: TLS_OPTS.merge(ca_file: CA_FILE),
)
error = assert_raise Net::LDAP::Error,
Net::LDAP::ConnectionRefusedError do
Errno::ECONNREFUSED do
@ldap.bind BIND_CREDS
end
assert_equal(
Expand All @@ -107,7 +106,7 @@ def test_bind_tls_with_bad_hostname_ca_no_opt_merge_fails
tls_options: { ca_file: CA_FILE },
)
error = assert_raise Net::LDAP::Error,
Net::LDAP::ConnectionRefusedError do
Errno::ECONNREFUSED do
@ldap.bind BIND_CREDS
end
assert_equal(
Expand Down Expand Up @@ -142,7 +141,7 @@ def test_bind_tls_with_bogus_hostname_system_ca_fails
@ldap.host = '127.0.0.1'
@ldap.encryption(method: :start_tls, tls_options: {})
error = assert_raise Net::LDAP::Error,
Net::LDAP::ConnectionRefusedError do
Errno::ECONNREFUSED do
@ldap.bind BIND_CREDS
end
assert_equal(
Expand Down
5 changes: 2 additions & 3 deletions test/test_ldap_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_result_for_connection_failed_is_set

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

assert_raise Net::LDAP::ConnectionRefusedError do
assert_raise Errno::ECONNREFUSED do
ldap_client.bind(method: :simple, username: 'asdf', password: 'asdf')
end

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

def test_connection_timeout
Expand Down