summaryrefslogtreecommitdiff
path: root/test/net
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-27 10:10:54 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-27 10:10:54 +0000
commit6cdc55f4a3441e5b9b0839f3c3e0ae885a4bee90 (patch)
tree55b12c261911cecb2e64a31ff130660585105c80 /test/net
parentb8d544832b8cbb041b87fc45c2c5614143af0fb5 (diff)
* lib/net/ftp.rb (makeport): close the TCPServer
when sending the port fails. * test/net/ftp/test_ftp.rb: test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net')
-rw-r--r--test/net/ftp/test_ftp.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb
index 6fae078bc7..618a9da287 100644
--- a/test/net/ftp/test_ftp.rb
+++ b/test/net/ftp/test_ftp.rb
@@ -469,6 +469,46 @@ class FTPTest < Test::Unit::TestCase
end
end
+ def test_open_data_port_fail_no_leak
+ commands = []
+ server = create_ftp_server { |sock|
+ sock.print("220 (test_ftp).\r\n")
+ commands.push(sock.gets)
+ sock.print("331 Please specify the password.\r\n")
+ commands.push(sock.gets)
+ sock.print("230 Login successful.\r\n")
+ commands.push(sock.gets)
+ sock.print("200 Switching to Binary mode.\r\n")
+ commands.push(sock.gets)
+ sock.print("200 Switching to ASCII mode.\r\n")
+ line = sock.gets
+ commands.push(line)
+ sock.print("421 Service not available, closing control connection.\r\n")
+ commands.push(sock.gets)
+ sock.print("200 Switching to Binary mode.\r\n")
+ }
+ begin
+ begin
+ ftp = Net::FTP.new
+ ftp.read_timeout = 0.2
+ ftp.connect(SERVER_ADDR, server.port)
+ ftp.login
+ assert_match(/\AUSER /, commands.shift)
+ assert_match(/\APASS /, commands.shift)
+ assert_equal("TYPE I\r\n", commands.shift)
+ assert_raise(Net::FTPTempError){ ftp.list }
+ assert_equal("TYPE A\r\n", commands.shift)
+ assert_match(/\APORT /, commands.shift)
+ assert_equal("TYPE I\r\n", commands.shift)
+ assert_equal(nil, commands.shift)
+ ensure
+ ftp.close if ftp
+ end
+ ensure
+ server.close
+ end
+ end
+
def test_retrbinary_read_timeout_exceeded
commands = []
binary_data = (0..0xff).map {|i| i.chr}.join * 4 * 3