summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-16 12:35:11 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-16 12:35:11 +0000
commit62941003a2f5314e80daf0c16e51881f0d177ff5 (patch)
treeee36b3bd9b748af7f755eb726fbf178d54a2d543 /test
parent829779e20c858b5be4dfb31b708ebb8f3a1832c3 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@30571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/net/http/test_http.rb19
-rw-r--r--test/net/http/test_https.rb22
2 files changed, 41 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index 6f40b79d76..bc87febbd9 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -173,6 +173,25 @@ module TestNetHTTP_version_1_1_methods
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
diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb
index adb50c58fb..11bb4a1f1e 100644
--- a/test/net/http/test_https.rb
+++ b/test/net/http/test_https.rb
@@ -2,6 +2,7 @@ require "test/unit"
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 @@ class TestNetHTTPS < Test::Unit::TestCase
}
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)