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

ruby-changes:18549

From: yugui <ko1@a...>
Date: Sun, 16 Jan 2011 21:41:07 +0900 (JST)
Subject: [ruby-changes:18549] Ruby:r30571 (ruby_1_9_2): merges r30520 from trunk into ruby_1_9_2.

yugui	2011-01-16 21:35:11 +0900 (Sun, 16 Jan 2011)

  New Revision: 30571

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30571

  Log:
    merges r30520 from trunk into ruby_1_9_2.
    --
    * lib/net/http.rb (Net::HTTP#connect): makes it timeout during
      SSL handshake too. [ruby-core:34203]
      Patch by Marc Slemko.
    
    * test/net/http/test_http.rb (TestNetHTTP_v1_2#test_timeout_during_HTTP_session):
      test for [ruby-core:34203]
    
    * test/net/http/test_https.rb (TestNetHTTPS#test_timeout_during_SSL_handshake):
      ditto.

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/lib/net/http.rb
    branches/ruby_1_9_2/test/net/http/test_http.rb
    branches/ruby_1_9_2/test/net/http/test_https.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 30570)
+++ ruby_1_9_2/ChangeLog	(revision 30571)
@@ -1,3 +1,15 @@
+Wed Jan 12 16:25:12 2011  Yuki Sonoda (Yugui)  <yugui@y...>
+
+	* lib/net/http.rb (Net::HTTP#connect): makes it timeout during 
+	  SSL handshake too. [ruby-core:34203]
+	  Patch by Marc Slemko.
+
+	* test/net/http/test_http.rb (TestNetHTTP_v1_2#test_timeout_during_HTTP_session):
+	  test for [ruby-core:34203]
+
+	* test/net/http/test_https.rb (TestNetHTTPS#test_timeout_during_SSL_handshake):
+	  ditto.
+
 Sun Jan  9 16:31:53 2011  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* io.c (Kernel.#syscall): implemented on LP64/LLP64 environments too.
Index: ruby_1_9_2/lib/net/http.rb
===================================================================
--- ruby_1_9_2/lib/net/http.rb	(revision 30570)
+++ ruby_1_9_2/lib/net/http.rb	(revision 30571)
@@ -662,22 +662,28 @@
       @socket.read_timeout = @read_timeout
       @socket.debug_output = @debug_output
       if use_ssl?
-        if proxy?
-          @socket.writeline sprintf('CONNECT %s:%s HTTP/%s',
-                                    @address, @port, HTTPVersion)
-          @socket.writeline "Host: #{@address}:#{@port}"
-          if proxy_user
-            credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
-            credential.delete!("\r\n")
-            @socket.writeline "Proxy-Authorization: Basic #{credential}"
+        begin
+          if proxy?
+            @socket.writeline sprintf('CONNECT %s:%s HTTP/%s',
+                                      @address, @port, HTTPVersion)
+            @socket.writeline "Host: #{@address}:#{@port}"
+            if proxy_user
+              credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
+              credential.delete!("\r\n")
+              @socket.writeline "Proxy-Authorization: Basic #{credential}"
+            end
+            @socket.writeline ''
+            HTTPResponse.read_new(@socket).value
           end
-          @socket.writeline ''
-          HTTPResponse.read_new(@socket).value
+          timeout(@open_timeout) { s.connect }
+          if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
+            s.post_connection_check(@address)
+          end
+        rescue => exception
+          D "Conn close because of connect error #{exception}"
+          @socket.close if @socket and not @socket.closed?
+          raise exception
         end
-        s.connect
-        if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
-          s.post_connection_check(@address)
-        end
       end
       on_connect
     end
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 30570)
+++ ruby_1_9_2/version.h	(revision 30571)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 151
+#define RUBY_PATCHLEVEL 152
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/net/http/test_http.rb
===================================================================
--- ruby_1_9_2/test/net/http/test_http.rb	(revision 30570)
+++ ruby_1_9_2/test/net/http/test_http.rb	(revision 30571)
@@ -173,6 +173,25 @@
     assert_equal ["a=x1", "a=x2", "b=y"], res.body.split(/[;&]/).sort
   end
 
+  def test_timeout_during_HTTP_session
+    bug4246 = "expected the HTTP session to have timed out but have not. c.f. [ruby-core:34203]"
+
+    # listen for connections... but deliberately do not complete SSL handshake
+    TCPServer.open(0) {|server|
+      port = server.addr[1]
+
+      conn = Net::HTTP.new('localhost', port)
+      conn.read_timeout = 1
+      conn.open_timeout = 1
+
+      th = Thread.new do
+        assert_raise(Timeout::Error) {
+          conn.get('/')
+        }
+      end
+      assert th.join(10), bug4246
+    }
+  end
 end
 
 
Index: ruby_1_9_2/test/net/http/test_https.rb
===================================================================
--- ruby_1_9_2/test/net/http/test_https.rb	(revision 30570)
+++ ruby_1_9_2/test/net/http/test_https.rb	(revision 30571)
@@ -2,6 +2,7 @@
 begin
   require 'net/https'
   require 'stringio'
+  require 'timeout'
   require File.expand_path("../../openssl/utils", File.dirname(__FILE__))
   require File.expand_path("utils", File.dirname(__FILE__))
 rescue LoadError
@@ -94,4 +95,25 @@
     }
     assert_match(/hostname was not match/, ex.message)
   end
+
+  def test_timeout_during_SSL_handshake
+    bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]"
+
+    # listen for connections... but deliberately do not complete SSL handshake
+    TCPServer.open(0) {|server|
+      port = server.addr[1]
+
+      conn = Net::HTTP.new('localhost', port)
+      conn.use_ssl = true
+      conn.read_timeout = 1
+      conn.open_timeout = 1
+
+      th = Thread.new do
+        assert_raise(Timeout::Error) {
+          conn.get('/')
+        }
+      end
+      assert th.join(10), bug4246
+    }
+  end
 end if defined?(OpenSSL)

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

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