diff options
Diffstat (limited to 'test/test_pair.rb')
-rw-r--r-- | test/test_pair.rb | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/test/test_pair.rb b/test/test_pair.rb index d611d0f..9250222 100644 --- a/test/test_pair.rb +++ b/test/test_pair.rb @@ -4,7 +4,7 @@ require_relative 'utils' if defined?(OpenSSL::TestUtils) require 'socket' -require_relative '../ruby/ut_eof' +require_relative 'ut_eof' module OpenSSL::SSLPairM def server @@ -322,6 +322,16 @@ module OpenSSL::TestPairM } end + def test_partial_tls_record_read_nonblock + ssl_pair { |s1, s2| + # the beginning of a TLS record + s1.io.write("\x17") + # should raise a IO::WaitReadable since a full TLS record is not available + # for reading + assert_raise(IO::WaitReadable) { s2.read_nonblock(1) } + } + end + def tcp_pair host = "127.0.0.1" serv = TCPServer.new(host, 0) @@ -341,7 +351,7 @@ module OpenSSL::TestPairM ctx2.tmp_dh_callback = nil sock1, sock2 = tcp_pair s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2) - accepted = s2.accept_nonblock(exception: false) + s2.accept_nonblock(exception: false) ctx1 = OpenSSL::SSL::SSLContext.new ctx1.ciphers = "DH" @@ -350,16 +360,16 @@ module OpenSSL::TestPairM s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1) t = Thread.new { s1.connect } - accept = s2.accept + EnvUtil.suppress_warning { # uses default callback + assert_nothing_raised { s2.accept } + } assert_equal s1, t.value - assert accept ensure t.join if t s1.close if s1 s2.close if s2 sock1.close if sock1 sock2.close if sock2 - accepted.close if accepted.respond_to?(:close) end def test_connect_without_setting_dh_callback @@ -368,7 +378,7 @@ module OpenSSL::TestPairM ctx2.security_level = 0 sock1, sock2 = tcp_pair s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2) - accepted = s2.accept_nonblock(exception: false) + s2.accept_nonblock(exception: false) ctx1 = OpenSSL::SSL::SSLContext.new ctx1.ciphers = "DH" @@ -376,16 +386,16 @@ module OpenSSL::TestPairM s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1) t = Thread.new { s1.connect } - accept = s2.accept + EnvUtil.suppress_warning { # default DH + assert_nothing_raised { s2.accept } + } assert_equal s1, t.value - assert accept ensure t.join if t s1.close if s1 s2.close if s2 sock1.close if sock1 sock2.close if sock2 - accepted.close if accepted.respond_to?(:close) end def test_ecdh_callback @@ -422,11 +432,11 @@ module OpenSSL::TestPairM end until rv == s1 end - accepted = s2.accept + s2.accept assert called, 'ecdh callback should be called' rescue OpenSSL::SSL::SSLError => e if e.message =~ /no cipher match/ - skip "ECDH cipher not supported." + pend "ECDH cipher not supported." else raise e end @@ -447,7 +457,7 @@ module OpenSSL::TestPairM begin ctx1.ciphers = "ECDH" rescue OpenSSL::SSL::SSLError - skip "ECDH is not enabled in this OpenSSL" if $!.message =~ /no cipher match/ + pend "ECDH is not enabled in this OpenSSL" if $!.message =~ /no cipher match/ raise end ctx1.ecdh_curves = "P-384:P-521" |