diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-09-06 07:21:14 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-09-07 08:56:28 +0900 |
commit | 6c864ac01fee46180c594ad68f199546c5eef5ee (patch) | |
tree | a25deef05ecd7fbdefb5f6db9f4b1ba5f4f562d2 /test | |
parent | c6b0bc0e3a2ca82c6e8fb1d3a7f29764b654ca23 (diff) | |
download | ruby-openssl-6c864ac01fee46180c594ad68f199546c5eef5ee.tar.gz |
test/test_ssl: remove 'STARTTLS' code from test/utils.rb
Move it to TestSSL#test_starttls using the server_proc option of
start_server, as it is the only user of the 'STARTTLS' code.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_ssl.rb | 51 | ||||
-rw-r--r-- | test/utils.rb | 11 |
2 files changed, 35 insertions, 27 deletions
diff --git a/test/test_ssl.rb b/test/test_ssl.rb index 5c1f58bb..d1ad490b 100644 --- a/test/test_ssl.rb +++ b/test/test_ssl.rb @@ -288,25 +288,44 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase end def test_starttls - OpenSSL::TestUtils.silent do - start_server(start_immediately: false) { |server, port| - sock = TCPSocket.new("127.0.0.1", port) - ssl = OpenSSL::SSL::SSLSocket.new(sock) - ssl.sync_close = true - str = "x" * 1000 + "\n" + server_proc = -> (ctx, ssl) { + begin + while line = ssl.gets + if line =~ /^STARTTLS$/ + ssl.write("x") + ssl.flush + ssl.accept + next + end + ssl.write(line) + end + rescue OpenSSL::SSL::SSLError + rescue IOError + ensure + ssl.close rescue nil + end + } - ITERATIONS.times{ - ssl.puts(str) - assert_equal(str, ssl.gets) - } - starttls(ssl) + EnvUtil.suppress_warning do # read/write on not started session + start_server(start_immediately: false, + server_proc: server_proc) { |server, port| + begin + sock = TCPSocket.new("127.0.0.1", port) + ssl = OpenSSL::SSL::SSLSocket.new(sock) - ITERATIONS.times{ - ssl.puts(str) - assert_equal(str, ssl.gets) - } + ssl.puts "plaintext" + assert_equal "plaintext\n", ssl.gets - ssl.close + ssl.puts("STARTTLS") + ssl.read(1) + ssl.connect + + ssl.puts "over-tls" + assert_equal "over-tls\n", ssl.gets + ensure + ssl&.close + sock&.close + end } end end diff --git a/test/utils.rb b/test/utils.rb index 4d055032..45ea8766 100644 --- a/test/utils.rb +++ b/test/utils.rb @@ -241,10 +241,6 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC def readwrite_loop(ctx, ssl) while line = ssl.gets - if line =~ /^STARTTLS$/ - ssl.accept - next - end ssl.write(line) end rescue OpenSSL::SSL::SSLError @@ -336,13 +332,6 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC end } end - - def starttls(ssl) - ssl.puts("STARTTLS") - sleep 1 # When this line is eliminated, process on Cygwin blocks - # forever at ssl.connect. But I don't know why it does. - ssl.connect - end end class OpenSSL::PKeyTestCase < OpenSSL::TestCase |