From 0fabee3229fba91a758e817746496424cd3a6c02 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Tue, 3 Jan 2023 19:24:42 +0200 Subject: [PATCH] Do not require test file in a forked process in tests --- test/openssl/engine_utils.rb | 12 ++++++++++++ test/openssl/test_engine.rb | 4 ++-- test/openssl/test_fips.rb | 2 -- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 test/openssl/engine_utils.rb diff --git a/test/openssl/engine_utils.rb b/test/openssl/engine_utils.rb new file mode 100644 index 000000000..4b5e2e631 --- /dev/null +++ b/test/openssl/engine_utils.rb @@ -0,0 +1,12 @@ +module EngineUtils + def get_engine + OpenSSL::Engine.by_id("openssl") + end + + def crypt_data(data, key, mode) + cipher = yield + cipher.send mode + cipher.key = key + cipher.update(data) + cipher.final + end +end diff --git a/test/openssl/test_engine.rb b/test/openssl/test_engine.rb index 1ede6ed08..ec56c5ab8 100644 --- a/test/openssl/test_engine.rb +++ b/test/openssl/test_engine.rb @@ -74,8 +74,8 @@ def test_openssl_engine_cipher_rc4 # this is required because OpenSSL::Engine methods change global state def with_openssl(code, **opts) assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts) - require #{__FILE__.dump} - include OpenSSL::TestEngine::Utils + require 'engine_utils' + include EngineUtils #{code} end; end diff --git a/test/openssl/test_fips.rb b/test/openssl/test_fips.rb index 8cd474f9a..03f7761a0 100644 --- a/test/openssl/test_fips.rb +++ b/test/openssl/test_fips.rb @@ -12,8 +12,6 @@ def test_fips_mode_is_reentrant def test_fips_mode_get return unless OpenSSL::OPENSSL_FIPS assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") - require #{__FILE__.dump} - begin OpenSSL.fips_mode = true assert OpenSSL.fips_mode == true, ".fips_mode returns true when .fips_mode=true"