diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-07 12:48:27 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-07 12:48:27 +0000 |
commit | 2dbae9b1f14d43f774153a7474dba9c6134dc5b4 (patch) | |
tree | 7d1d93be2f540da29a5596d87c32d3b68924c53d /test/openssl | |
parent | 1386a2303f85d6905cf1b45cfe3c4155535a05e2 (diff) | |
download | ruby-2dbae9b1f14d43f774153a7474dba9c6134dc5b4.tar.gz |
* ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLServer#accept):
Consider Socket#accept as well as TCPServer#accept.
Reported by Sam Stelfox. [ruby-core:62064] [Bug #9750]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/openssl')
-rw-r--r-- | test/openssl/test_pair.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/openssl/test_pair.rb b/test/openssl/test_pair.rb index 38b6989bac..70ea47da75 100644 --- a/test/openssl/test_pair.rb +++ b/test/openssl/test_pair.rb @@ -56,6 +56,64 @@ module SSLPair end end +module SSLPairLowlevelSocket + def server + host = "127.0.0.1" + port = 0 + ctx = OpenSSL::SSL::SSLContext.new() + ctx.ciphers = "ADH" + ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 } + tcps = Addrinfo.tcp(host, port).listen + ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx) + return ssls + end + + def client(port) + host = "127.0.0.1" + ctx = OpenSSL::SSL::SSLContext.new() + ctx.ciphers = "ADH" + s = Addrinfo.tcp(host, port).connect + ssl = OpenSSL::SSL::SSLSocket.new(s, ctx) + ssl.connect + ssl.sync_close = true + ssl + end + + def ssl_pair + ssls = server + ths = Thread.new { + ns = ssls.accept + ssls.close + ns + } + port = ssls.to_io.connect_address.ip_port + thc = Thread.new { + client(port) + } + s = ths.value + c = thc.value + if block_given? + begin + yield c, s + ensure + c.close unless c.closed? + s.close unless s.closed? + end + else + return c, s + end + ensure + if ths && ths.alive? + ths.kill + ths.join + end + if thc && thc.alive? + thc.kill + thc.join + end + end +end + class OpenSSL::TestEOF1 < Test::Unit::TestCase include TestEOF include SSLPair @@ -309,4 +367,15 @@ class OpenSSL::TestPair < Test::Unit::TestCase end +class OpenSSL::TestPairLowlevelSocket < Test::Unit::TestCase + include SSLPairLowlevelSocket + + def test_getc + ssl_pair {|s1, s2| + s1 << "a" + assert_equal(?a, s2.getc) + } + end +end + end |