1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

net/ftp: support timeout for TLS handshake.

Net::FTP inherits ssl_socket_connect from Net::Protocol to implement timeout.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2016-11-26 09:29:11 +00:00
parent 631dde2572
commit 473d0d3211
2 changed files with 26 additions and 2 deletions

View file

@ -77,7 +77,7 @@ module Net
# - #rename
# - #delete
#
class FTP
class FTP < Protocol
include MonitorMixin
if defined?(OpenSSL::SSL)
include OpenSSL
@ -338,7 +338,7 @@ module Net
# ProFTPD returns 425 for data connections if session is not reused.
ssl_sock.session = @ssl_session
end
ssl_sock.connect
ssl_socket_connect(ssl_sock, @open_timeout)
if @ssl_context.verify_mode != VERIFY_NONE
ssl_sock.post_connection_check(@host)
end

View file

@ -2100,6 +2100,30 @@ EOF
ftp.close
end
end
def test_tls_connect_timeout
server = TCPServer.new(SERVER_ADDR, 0)
port = server.addr[1]
commands = []
sock = nil
@thread = Thread.start do
sock = server.accept
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("234 AUTH success.\r\n")
end
begin
assert_raise(Net::OpenTimeout) do
Net::FTP.new("localhost",
port: port,
ssl: { ca_file: CA_FILE },
open_timeout: 0.1)
end
ensure
sock.close if sock
server.close
end
end
end
def test_abort_tls