Skip to content

Commit 8c4bf53

Browse files
committed
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: #154
1 parent 6652ad7 commit 8c4bf53

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

test/test_engine.rb

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,22 @@ def test_openssl_engine_digest_sha1
5252
end
5353

5454
def test_openssl_engine_cipher_rc4
55-
with_openssl <<-'end;'
56-
begin
57-
engine = get_engine
58-
algo = "RC4" #AES is not supported by openssl Engine (<=1.0.0e)
59-
data = "a" * 1000
60-
key = OpenSSL::Random.random_bytes(16)
61-
# suppress message from openssl Engine's RC4 cipher [ruby-core:41026]
62-
err_back = $stderr.dup
63-
$stderr.reopen(IO::NULL)
64-
encrypted = crypt_data(data, key, :encrypt) { engine.cipher(algo) }
65-
decrypted = crypt_data(encrypted, key, :decrypt) { OpenSSL::Cipher.new(algo) }
66-
assert_equal(data, decrypted)
67-
ensure
68-
if err_back
69-
$stderr.reopen(err_back)
70-
err_back.close
71-
end
72-
end
55+
with_openssl(<<-'end;', ignore_stderr: true)
56+
engine = get_engine
57+
algo = "RC4" #AES is not supported by openssl Engine (<=1.0.0e)
58+
data = "a" * 1000
59+
key = OpenSSL::Random.random_bytes(16)
60+
encrypted = crypt_data(data, key, :encrypt) { engine.cipher(algo) }
61+
decrypted = crypt_data(encrypted, key, :decrypt) { OpenSSL::Cipher.new(algo) }
62+
assert_equal(data, decrypted)
7363
end;
7464
end
7565

7666
private
7767

7868
# this is required because OpenSSL::Engine methods change global state
79-
def with_openssl(code)
80-
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
69+
def with_openssl(code, **opts)
70+
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts)
8171
require #{__FILE__.dump}
8272
include OpenSSL::TestEngine::Utils
8373
#{code}

0 commit comments

Comments
 (0)