diff --git a/Contributors.rdoc b/Contributors.rdoc index 137394f8..820ba8e1 100644 --- a/Contributors.rdoc +++ b/Contributors.rdoc @@ -23,3 +23,4 @@ Contributions since: * Cody Cutrer (ccutrer) * WoodsBagotAndreMarquesLee * Rufus Post (mynameisrufus) +* Akamai Technologies, Inc. (jwedoff) diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index f7a98ef5..3f0ea5a5 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -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], diff --git a/lib/net/ldap/connection.rb b/lib/net/ldap/connection.rb index b01984f4..467a315e 100644 --- a/lib/net/ldap/connection.rb +++ b/lib/net/ldap/connection.rb @@ -38,6 +38,12 @@ def prepare_socket(server, timeout=nil) setup_encryption(encryption, timeout) if encryption end + # Internal: simple private method that can be replaced, if necessary, to allow this warning to be modified + def ssl_verify_warning(host, port) + warn "not verifying SSL hostname of LDAPS server '#{host}:#{port}'" + end + private :ssl_verify_warning + def open_connection(server) hosts = server[:hosts] encryption = server[:encryption] @@ -55,7 +61,7 @@ def open_connection(server) if encryption[:tls_options] && encryption[:tls_options][:verify_mode] && encryption[:tls_options][:verify_mode] == OpenSSL::SSL::VERIFY_NONE - warn "not verifying SSL hostname of LDAPS server '#{host}:#{port}'" + ssl_verify_warning(host, port) else @conn.post_connection_check(host) end diff --git a/lib/net/ldap/error.rb b/lib/net/ldap/error.rb index 50442d06..eb2aa085 100644 --- a/lib/net/ldap/error.rb +++ b/lib/net/ldap/error.rb @@ -9,31 +9,11 @@ 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.kind_of? Errno::ECONNREFUSED return Net::LDAP::Error.new(error.message) end diff --git a/test/integration/test_bind.rb b/test/integration/test_bind.rb index bd1281e2..6f6e370c 100644 --- a/test/integration/test_bind.rb +++ b/test/integration/test_bind.rb @@ -70,7 +70,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( @@ -86,7 +86,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( @@ -102,7 +102,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( @@ -137,7 +137,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( diff --git a/test/integration/test_password_modify.rb b/test/integration/test_password_modify.rb index ed8d4f5b..db1a00a7 100644 --- a/test/integration/test_password_modify.rb +++ b/test/integration/test_password_modify.rb @@ -3,7 +3,7 @@ class TestPasswordModifyIntegration < LDAPIntegrationTestCase def setup super - @admin_account = {dn: 'cn=admin,dc=rubyldap,dc=com', password: 'passworD1', method: :simple} + @admin_account = { dn: 'cn=admin,dc=rubyldap,dc=com', password: 'passworD1', method: :simple } @ldap.authenticate @admin_account[:dn], @admin_account[:password] @dn = 'uid=modify-password-user1,ou=People,dc=rubyldap,dc=com' diff --git a/test/test_ldap_connection.rb b/test/test_ldap_connection.rb index 8489c377..0f130d1d 100644 --- a/test/test_ldap_connection.rb +++ b/test/test_ldap_connection.rb @@ -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 @@ -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