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

Output cleanup #322

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Contributors.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Contributions since:
* Cody Cutrer (ccutrer)
* WoodsBagotAndreMarquesLee
* Rufus Post (mynameisrufus)
* Akamai Technologies, Inc. (jwedoff)
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
8 changes: 7 additions & 1 deletion lib/net/ldap/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
22 changes: 1 addition & 21 deletions lib/net/ldap/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions test/integration/test_bind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_password_modify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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