Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require a test file in a separately run test case #591

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions test/openssl/test_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def test_openssl_engine_by_id_string
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;
end

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)
Expand All @@ -43,7 +43,7 @@ def test_openssl_engine_id_name_inspect

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"
Expand All @@ -59,12 +59,21 @@ def test_openssl_engine_cipher_rc4
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
Expand All @@ -74,24 +83,9 @@ 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
#{code}
end;
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module Utils below should be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should simply inline these helper methods in Utils. They are both too specialized and don't look very useful anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've inlined the helpers.


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
2 changes: 0 additions & 2 deletions test/openssl/test_fips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down