Skip to content
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
2 changes: 1 addition & 1 deletion lib/net/ldap/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def open_connection(server)
end
return
rescue Net::LDAP::Error, SocketError, SystemCallError,
OpenSSL::SSL::SSLError => e
OpenSSL::SSL::SSLError, IO::TimeoutError => e
# Ensure the connection is closed in the event a setup failure.
close
errors << [e, host, port]
Expand Down
38 changes: 38 additions & 0 deletions test/test_ldap_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,28 @@ def setup
@connection = Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
end

def capture_stderr
stderr, $stderr = $stderr, StringIO.new
yield
$stderr.string
ensure
$stderr = stderr
end

# Fake socket for testing
#
# FakeTCPSocket.new("success", 636)
# FakeTCPSocket.new("fail.SocketError", 636) # raises SocketError
class FakeTCPSocket
def initialize(host, port, socket_opts = {})
parts = host.split(".")
status = parts.shift
error = parts.join(".")

raise Object.const_get(error) if status == "fail"
end
end

def test_error_failed_operation
ber = Net::BER::BerIdentifiedArray.new([Net::LDAP::ResultCodeUnwillingToPerform, "", "The provided password value was rejected by a password validator: The provided password did not contain enough characters from the character set 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. The minimum number of characters from that set that must be present in user passwords is 1"])
ber.ber_identifier = Net::LDAP::PDU::ModifyResponse
Expand All @@ -382,6 +404,22 @@ def test_no_error_on_success
assert result.success?, "should be success"
assert_equal "", result.error_message
end

def test_connection_timeout_io_timeout_error
return if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("4.0.0")

connection = Net::LDAP::Connection.new(
:host => "fail.IO::TimeoutError",
:port => 636,
:socket_class => FakeTCPSocket,
)

capture_stderr do
assert_raise Net::LDAP::Error do
connection.socket
end
end
end
end

class TestLDAPConnectionInstrumentation < Test::Unit::TestCase
Expand Down