summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Konchin <andry.konchin@gmail.com>2023-01-03 19:24:42 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-01-27 11:30:13 +0900
commit5afc8301309ec660c94438d967eea1bf1235a67c (patch)
tree4cf1a53d5c21708b4ba9b67e6095e9c796b7f5b1
parent1b06cd3f09183c14d15ceaada57e425e12a6f3b2 (diff)
[ruby/openssl] Do not require test file in a forked process in tests
https://github.com/ruby/openssl/commit/ae784673d7
-rw-r--r--test/openssl/test_engine.rb36
-rw-r--r--test/openssl/test_fips.rb2
2 files changed, 15 insertions, 23 deletions
diff --git a/test/openssl/test_engine.rb b/test/openssl/test_engine.rb
index 1ede6ed086..15434218d9 100644
--- a/test/openssl/test_engine.rb
+++ b/test/openssl/test_engine.rb
@@ -26,7 +26,7 @@ class OpenSSL::TestEngine < OpenSSL::TestCase
with_openssl <<-'end;'
orig = OpenSSL::Engine.engines
pend "'openssl' is already loaded" if orig.any? { |e| e.id == "openssl" }
- engine = get_engine
+ engine = OpenSSL::Engine.by_id("openssl")
assert_not_nil(engine)
assert_equal(1, OpenSSL::Engine.engines.size - orig.size)
end;
@@ -34,7 +34,7 @@ class OpenSSL::TestEngine < OpenSSL::TestCase
def test_openssl_engine_id_name_inspect
with_openssl <<-'end;'
- engine = get_engine
+ engine = OpenSSL::Engine.by_id("openssl")
assert_equal("openssl", engine.id)
assert_not_nil(engine.name)
assert_not_nil(engine.inspect)
@@ -43,7 +43,7 @@ class OpenSSL::TestEngine < OpenSSL::TestCase
def test_openssl_engine_digest_sha1
with_openssl <<-'end;'
- engine = get_engine
+ engine = OpenSSL::Engine.by_id("openssl")
digest = engine.digest("SHA1")
assert_not_nil(digest)
data = "test"
@@ -59,12 +59,21 @@ class OpenSSL::TestEngine < OpenSSL::TestCase
end
with_openssl(<<-'end;', ignore_stderr: true)
- engine = get_engine
+ engine = OpenSSL::Engine.by_id("openssl")
algo = "RC4"
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) }
+
+ cipher = engine.cipher(algo)
+ cipher.encrypt
+ cipher.key = key
+ encrypted = cipher.update(data) + cipher.final
+
+ cipher = OpenSSL::Cipher.new(algo)
+ cipher.decrypt
+ cipher.key = key
+ decrypted = cipher.update(encrypted) + cipher.final
+
assert_equal(data, decrypted)
end;
end
@@ -74,24 +83,9 @@ class OpenSSL::TestEngine < OpenSSL::TestCase
# 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
#{code}
end;
end
-
- module Utils
- 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
end
end
diff --git a/test/openssl/test_fips.rb b/test/openssl/test_fips.rb
index 8cd474f9a3..03f7761a03 100644
--- a/test/openssl/test_fips.rb
+++ b/test/openssl/test_fips.rb
@@ -12,8 +12,6 @@ class OpenSSL::TestFIPS < OpenSSL::TestCase
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"