diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-09-06 21:53:15 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-09-07 09:10:49 +0900 |
commit | bb315a0be77fe792863d9eae70694997ca994e13 (patch) | |
tree | 82dd106da14889c052aa531a3893e0e9a8b327f1 /test | |
parent | ee37304b67fec137b383552e9fc74dc90905883b (diff) | |
download | ruby-openssl-bb315a0be77fe792863d9eae70694997ca994e13.tar.gz |
test/test_pair: extract IO-like methods tests from test_ssl.rb
Move a test case of SSLSocket#gets to test_pair.rb, and remove test
cases from test_ssl.rb which duplicate the tests in test_pair.rb
Diffstat (limited to 'test')
-rw-r--r-- | test/test_pair.rb | 16 | ||||
-rw-r--r-- | test/test_ssl.rb | 126 |
2 files changed, 45 insertions, 97 deletions
diff --git a/test/test_pair.rb b/test/test_pair.rb index 73d3e8d4..7d962c38 100644 --- a/test/test_pair.rb +++ b/test/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 diff --git a/test/test_ssl.rb b/test/test_ssl.rb index 8e31b53f..cf704e24 100644 --- a/test/test_ssl.rb +++ b/test/test_ssl.rb @@ -52,110 +52,44 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase } end - def test_ssl_gets + def test_sysread_and_syswrite start_server { |server, port| server_connect(port) { |ssl| - ssl.write "abc\n" - IO.select [ssl] - - line = ssl.gets - - assert_equal "abc\n", line - assert_equal Encoding::BINARY, line.encoding - } - } - end - - def test_ssl_read_nonblock - start_server { |server, port| - server_connect(port) { |ssl| - assert_raise(IO::WaitReadable) { ssl.read_nonblock(100) } - ssl.write("abc\n") - IO.select [ssl] - assert_equal('a', ssl.read_nonblock(1)) - assert_equal("bc\n", ssl.read_nonblock(100)) - assert_raise(IO::WaitReadable) { ssl.read_nonblock(100) } + str = "x" * 100 + "\n" + ssl.syswrite(str) + newstr = ssl.sysread(str.bytesize) + assert_equal(str, newstr) + + buf = "" + ssl.syswrite(str) + assert_same buf, ssl.sysread(str.size, buf) + assert_equal(str, newstr) } } end - def test_ssl_sysread_blocking_error + def test_sync_close start_server { |server, port| - server_connect(port) { |ssl| - ssl.write("abc\n") - assert_raise(TypeError) { ssl.sysread(4, exception: false) } - buf = '' - assert_raise(ArgumentError) { ssl.sysread(4, buf, exception: false) } - assert_equal '', buf - assert_equal buf.object_id, ssl.sysread(4, buf).object_id - assert_equal "abc\n", buf - } - } - end - - def test_connect_and_close - start_server { |server, port| - sock = TCPSocket.new("127.0.0.1", port) - ssl = OpenSSL::SSL::SSLSocket.new(sock) - assert(ssl.connect) - ssl.close - assert(!sock.closed?) - sock.close - - sock = TCPSocket.new("127.0.0.1", port) - ssl = OpenSSL::SSL::SSLSocket.new(sock) - ssl.sync_close = true # !! - assert(ssl.connect) - ssl.close - assert(sock.closed?) - } - end - - def test_read_and_write - start_server { |server, port| - server_connect(port) { |ssl| - # syswrite and sysread - ITERATIONS.times{|i| - str = "x" * 100 + "\n" - ssl.syswrite(str) - newstr = '' - newstr << ssl.sysread(str.size - newstr.size) until newstr.size == str.size - assert_equal(str, newstr) - - str = "x" * i * 100 + "\n" - buf = "" - ssl.syswrite(str) - assert_equal(buf.object_id, ssl.sysread(str.size, buf).object_id) - newstr = buf - newstr << ssl.sysread(str.size - newstr.size) until newstr.size == str.size - assert_equal(str, newstr) - } - - # puts and gets - ITERATIONS.times{ - str = "x" * 100 + "\n" - ssl.puts(str) - assert_equal(str, ssl.gets) - - str = "x" * 100 - ssl.puts(str) - assert_equal(str, ssl.gets("\n", 100)) - assert_equal("\n", ssl.gets) - } + begin + sock = TCPSocket.new("127.0.0.1", port) + ssl = OpenSSL::SSL::SSLSocket.new(sock) + ssl.connect + ssl.close + assert_not_predicate sock, :closed? + ensure + sock&.close + end - # read and write - ITERATIONS.times{|i| - str = "x" * 100 + "\n" - ssl.write(str) - assert_equal(str, ssl.read(str.size)) - - str = "x" * i * 100 + "\n" - buf = "" - ssl.write(str) - assert_equal(buf.object_id, ssl.read(str.size, buf).object_id) - assert_equal(str, buf) - } - } + begin + sock = TCPSocket.new("127.0.0.1", port) + ssl = OpenSSL::SSL::SSLSocket.new(sock) + ssl.sync_close = true # !! + ssl.connect + ssl.close + assert_predicate sock, :closed? + ensure + sock&.close + end } end |