[前][次][番号順一覧][スレッド一覧]

ruby-changes:44900

From: shugo <ko1@a...>
Date: Sun, 4 Dec 2016 00:41:19 +0900 (JST)
Subject: [ruby-changes:44900] shugo:r56973 (trunk): Use IPv6 if it's preferred.

shugo	2016-12-04 00:41:14 +0900 (Sun, 04 Dec 2016)

  New Revision: 56973

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56973

  Log:
    Use IPv6 if it's preferred.
    
    I hope this fix makes tests faster on Windows.

  Modified files:
    trunk/test/net/ftp/test_ftp.rb
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 56972)
+++ test/net/ftp/test_ftp.rb	(revision 56973)
@@ -7,7 +7,8 @@ require "stringio" https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L7
 require "tempfile"
 
 class FTPTest < Test::Unit::TestCase
-  SERVER_ADDR = "127.0.0.1"
+  SERVER_NAME = "localhost"
+  SERVER_ADDR = Addrinfo.getaddrinfo(SERVER_NAME, 0)[0].ip_address
   CA_FILE = File.expand_path("../fixtures/cacert.pem", __dir__)
   SERVER_KEY = File.expand_path("../fixtures/server.key", __dir__)
   SERVER_CERT = File.expand_path("../fixtures/server.crt", __dir__)
@@ -405,10 +406,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L406
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Here comes the directory listing.\r\n")
       begin
@@ -441,7 +439,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L439
           ftp.list
         end
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("LIST\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -471,10 +469,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L469
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Here comes the directory listing.\r\n")
       conn = TCPSocket.new(host, port)
@@ -498,7 +493,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L493
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(list_lines, ftp.list)
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("LIST\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
@@ -524,7 +519,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L519
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("553 Requested action not taken.\r\n")
       commands.push(sock.gets)
@@ -541,7 +536,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L536
         assert_equal("TYPE I\r\n", commands.shift)
         assert_raise(Net::FTPPermError){ ftp.list }
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("LIST\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
@@ -582,7 +577,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L577
         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_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -606,10 +601,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L601
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -637,7 +629,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L629
         end
         assert_equal(1024, buf.bytesize)
         assert_equal(binary_data[0, 1024], buf)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -661,10 +653,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L653
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -692,7 +681,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L681
         end
         assert_equal(binary_data.bytesize, buf.bytesize)
         assert_equal(binary_data, buf)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -715,7 +704,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L704
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("550 Requested action not taken.\r\n")
     }
@@ -729,7 +718,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L718
         assert_match(/\APASS /, commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_raise(Net::FTPPermError){ ftp.retrbinary("RETR foo", 1024) }
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -753,10 +742,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L742
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -780,7 +766,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L766
         buf = ftp.getbinaryfile("foo", nil)
         assert_equal(binary_data, buf)
         assert_equal(Encoding::ASCII_8BIT, buf.encoding)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -804,10 +790,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L790
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -828,7 +811,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L811
         buf = ftp.getbinaryfile("foo", nil)
         assert_equal(binary_data, buf)
         assert_equal(Encoding::ASCII_8BIT, buf.encoding)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -852,10 +835,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L835
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -887,7 +867,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L867
           assert_equal(Encoding::ASCII_8BIT, buf.encoding)
           assert_equal(binary_data, f.read)
         end
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -912,10 +892,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L892
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo\r\n")
       conn = TCPSocket.new(host, port)
@@ -934,7 +911,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L911
         assert_equal("TYPE I\r\n", commands.shift)
         ftp.storbinary("STOR foo", StringIO.new(binary_data), 1024)
         assert_equal(binary_data, stored_data)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("STOR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -958,7 +935,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L935
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("452 Requested file action aborted.\r\n")
     }
@@ -972,7 +949,7 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L949
         assert_match(/\APASS /, commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_raise(Net::FTPTempError){ ftp.storbinary("STOR foo", StringIO.new(binary_data), 1024) }
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("STOR foo\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -1002,10 +979,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L979
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening TEXT mode data connection for foo (#{text_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -1034,7 +1008,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1008
         assert_equal(text_data.bytesize, buf.bytesize)
         assert_equal(text_data, buf)
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
@@ -1065,10 +1039,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1039
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening TEXT mode data connection for foo (#{text_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -1094,7 +1065,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1065
         assert_equal(text_data.gsub(/\r\n/, "\n"), buf)
         assert_equal(Encoding::ASCII_8BIT, buf.encoding)
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
@@ -1125,10 +1096,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1096
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening TEXT mode data connection for foo (#{text_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -1161,7 +1129,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1129
           assert_equal(buf, f.read)
         end
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR foo\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
@@ -1193,10 +1161,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1161
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Here comes the directory listing.\r\n")
       conn = TCPSocket.new(host, port)
@@ -1209,10 +1174,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1174
       sock.print("200 Switching to Binary mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Opening BINARY mode data connection for foo (#{binary_data.size} bytes)\r\n")
       conn = TCPSocket.new(host, port)
@@ -1236,10 +1198,10 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1198
           end
         end
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("LIST\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_equal("RETR baz.bin\r\n", commands.shift)
         assert_equal(nil, commands.shift)
       ensure
@@ -1658,10 +1620,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1620
       sock.print("200 Switching to ASCII mode.\r\n")
       line = sock.gets
       commands.push(line)
-      port_args = line.slice(/\APORT (.*)/, 1).split(/,/)
-      host = port_args[0, 4].join(".")
-      port = port_args[4, 2].map(&:to_i).inject {|x, y| (x << 8) + y}
-      sock.print("200 PORT command successful.\r\n")
+      host, port = process_port_or_eprt(sock, line)
       commands.push(sock.gets)
       sock.print("150 Here comes the directory listing.\r\n")
       begin
@@ -1705,7 +1664,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1664
         assert_equal(123456, modify.usec)
         assert_equal(true, modify.utc?)
         assert_equal("TYPE A\r\n", commands.shift)
-        assert_match(/\APORT /, commands.shift)
+        assert_match(/\A(PORT|EPRT) /, commands.shift)
         assert_match("MLSD /\r\n", commands.shift)
         assert_equal("TYPE I\r\n", commands.shift)
         assert_equal(nil, commands.shift)
@@ -1751,7 +1710,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1710
       assert_raise(OpenSSL::SSL::SSLError) do
         tls_test do |port|
           begin
-            Net::FTP.new("localhost",
+            Net::FTP.new(SERVER_NAME,
                          :port => port,
                          :ssl => true)
           rescue SystemCallError
@@ - (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]