diff options
author | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-08 01:09:19 +0000 |
---|---|---|
committer | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-08 01:09:19 +0000 |
commit | a128c0d33f1d7a66c2c8c5d57fde40acd97becae (patch) | |
tree | 6b5d9600c76e8432c1d22e9ef9223910e8162d0f /test/openssl/test_pair.rb | |
parent | ba6ae341bab83dfc7a624c5bf20d8d162dacaff9 (diff) |
openssl: import v2.0.0.beta.2
* {ext,test}/openssl: Import Ruby/OpenSSL 2.0.0.beta.2. The full commit
history since v2.0.0.beta.1 can be found at:
https://github.com/ruby/openssl/compare/v2.0.0.beta.1...v2.0.0.beta.2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/openssl/test_pair.rb')
-rw-r--r-- | test/openssl/test_pair.rb | 157 |
1 files changed, 15 insertions, 142 deletions
diff --git a/test/openssl/test_pair.rb b/test/openssl/test_pair.rb index 9250222979..7d962c385a 100644 --- a/test/openssl/test_pair.rb +++ b/test/openssl/test_pair.rb @@ -113,11 +113,25 @@ module OpenSSL::TestPairM } end + def test_gets + ssl_pair {|s1, s2| + s1 << "abc\n\n$def123ghi" + s1.close + ret = s2.gets + assert_equal Encoding::BINARY, ret.encoding + assert_equal "abc\n", ret + assert_equal "\n$", s2.gets("$") + assert_equal "def123", s2.gets(/\d+/) + assert_equal "ghi", s2.gets + assert_equal nil, s2.gets + } + end + def test_gets_eof_limit ssl_pair {|s1, s2| s1.write("hello") s1.close # trigger EOF - assert_match "hello", s2.gets("\n", 6), "[ruby-core:70149] [Bug #11140]" + assert_match "hello", s2.gets("\n", 6), "[ruby-core:70149] [Bug #11400]" } end @@ -344,147 +358,6 @@ module OpenSSL::TestPairM serv.close if serv && !serv.closed? end - def test_connect_works_when_setting_dh_callback_to_nil - ctx2 = OpenSSL::SSL::SSLContext.new - ctx2.ciphers = "DH" - ctx2.security_level = 0 - ctx2.tmp_dh_callback = nil - sock1, sock2 = tcp_pair - s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2) - s2.accept_nonblock(exception: false) - - ctx1 = OpenSSL::SSL::SSLContext.new - ctx1.ciphers = "DH" - ctx1.security_level = 0 - ctx1.tmp_dh_callback = nil - s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1) - t = Thread.new { s1.connect } - - EnvUtil.suppress_warning { # uses default callback - assert_nothing_raised { s2.accept } - } - assert_equal s1, t.value - ensure - t.join if t - s1.close if s1 - s2.close if s2 - sock1.close if sock1 - sock2.close if sock2 - end - - def test_connect_without_setting_dh_callback - ctx2 = OpenSSL::SSL::SSLContext.new - ctx2.ciphers = "DH" - ctx2.security_level = 0 - sock1, sock2 = tcp_pair - s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2) - s2.accept_nonblock(exception: false) - - ctx1 = OpenSSL::SSL::SSLContext.new - ctx1.ciphers = "DH" - ctx1.security_level = 0 - s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1) - t = Thread.new { s1.connect } - - EnvUtil.suppress_warning { # default DH - assert_nothing_raised { s2.accept } - } - assert_equal s1, t.value - ensure - t.join if t - s1.close if s1 - s2.close if s2 - sock1.close if sock1 - sock2.close if sock2 - end - - def test_ecdh_callback - return unless OpenSSL::SSL::SSLContext.instance_methods.include?(:tmp_ecdh_callback) - EnvUtil.suppress_warning do # tmp_ecdh_callback is deprecated (2016-05) - begin - called = false - ctx2 = OpenSSL::SSL::SSLContext.new - ctx2.ciphers = "ECDH" - # OpenSSL 1.1.0 doesn't have tmp_ecdh_callback so this shouldn't be required - ctx2.security_level = 0 - ctx2.tmp_ecdh_callback = ->(*args) { - called = true - OpenSSL::PKey::EC.new "prime256v1" - } - - sock1, sock2 = tcp_pair - - s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2) - ctx1 = OpenSSL::SSL::SSLContext.new - ctx1.ciphers = "ECDH" - ctx1.security_level = 0 - - s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1) - th = Thread.new do - begin - rv = s1.connect_nonblock(exception: false) - case rv - when :wait_writable - IO.select(nil, [s1], nil, 5) - when :wait_readable - IO.select([s1], nil, nil, 5) - end - end until rv == s1 - end - - s2.accept - assert called, 'ecdh callback should be called' - rescue OpenSSL::SSL::SSLError => e - if e.message =~ /no cipher match/ - pend "ECDH cipher not supported." - else - raise e - end - ensure - th.join if th - s1.close if s1 - s2.close if s2 - sock1.close if sock1 - sock2.close if sock2 - end - end - end - - def test_ecdh_curves - sock1, sock2 = tcp_pair - - ctx1 = OpenSSL::SSL::SSLContext.new - begin - ctx1.ciphers = "ECDH" - rescue OpenSSL::SSL::SSLError - pend "ECDH is not enabled in this OpenSSL" if $!.message =~ /no cipher match/ - raise - end - ctx1.ecdh_curves = "P-384:P-521" - ctx1.security_level = 0 - s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1) - - ctx2 = OpenSSL::SSL::SSLContext.new - ctx2.ciphers = "ECDH" - ctx2.ecdh_curves = "P-256:P-384" - ctx2.security_level = 0 - s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2) - - th = Thread.new { s1.accept } - s2.connect - - assert s2.cipher[0].start_with?("AECDH"), "AECDH should be used" - if s2.respond_to?(:tmp_key) - assert_equal "secp384r1", s2.tmp_key.group.curve_name - end - ensure - th.join if th - s1.close if s1 - s2.close if s2 - sock1.close if sock1 - sock2.close if sock2 - end - def test_connect_accept_nonblock_no_exception ctx2 = OpenSSL::SSL::SSLContext.new ctx2.ciphers = "ADH" |