aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-09-24 12:57:39 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-09-24 13:01:34 +0900
commit8c4bf53262d9a2d21641f1bb6eaf352424f648b7 (patch)
treede403abe1e40c0a01145d98042384233a1b9acf1
parent6652ad7c639d71cec93c4d21030ff9020a4e9717 (diff)
downloadruby-openssl-8c4bf53262d9a2d21641f1bb6eaf352424f648b7.tar.gz
test/test_engine: suppress stderr
Use ignore_stderr option of assert_separately instead of $stderr.reopen which may not work if the OpenSSL library uses a different stdio. Reference: https://github.com/ruby/openssl/issues/154
-rw-r--r--test/test_engine.rb30
1 files changed, 10 insertions, 20 deletions
diff --git a/test/test_engine.rb b/test/test_engine.rb
index 63435046..ee1ebb33 100644
--- a/test/test_engine.rb
+++ b/test/test_engine.rb
@@ -52,32 +52,22 @@ class OpenSSL::TestEngine < OpenSSL::TestCase
end
def test_openssl_engine_cipher_rc4
- with_openssl <<-'end;'
- begin
- engine = get_engine
- algo = "RC4" #AES is not supported by openssl Engine (<=1.0.0e)
- data = "a" * 1000
- key = OpenSSL::Random.random_bytes(16)
- # suppress message from openssl Engine's RC4 cipher [ruby-core:41026]
- err_back = $stderr.dup
- $stderr.reopen(IO::NULL)
- encrypted = crypt_data(data, key, :encrypt) { engine.cipher(algo) }
- decrypted = crypt_data(encrypted, key, :decrypt) { OpenSSL::Cipher.new(algo) }
- assert_equal(data, decrypted)
- ensure
- if err_back
- $stderr.reopen(err_back)
- err_back.close
- end
- end
+ with_openssl(<<-'end;', ignore_stderr: true)
+ engine = get_engine
+ algo = "RC4" #AES is not supported by openssl Engine (<=1.0.0e)
+ data = "a" * 1000
+ key = OpenSSL::Random.random_bytes(16)
+ encrypted = crypt_data(data, key, :encrypt) { engine.cipher(algo) }
+ decrypted = crypt_data(encrypted, key, :decrypt) { OpenSSL::Cipher.new(algo) }
+ assert_equal(data, decrypted)
end;
end
private
# this is required because OpenSSL::Engine methods change global state
- def with_openssl(code)
- assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
+ def with_openssl(code, **opts)
+ assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts)
require #{__FILE__.dump}
include OpenSSL::TestEngine::Utils
#{code}