Skip to content

Commit

Permalink
Fix test_provider.rb in FIPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
junaruga committed Sep 5, 2024
1 parent ade5076 commit 7bdbc52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Rake::TestTask.new(:test_fips_internal) do |t|
'test/openssl/test_pkey_dsa.rb',
'test/openssl/test_pkey_ec.rb',
'test/openssl/test_pkey_rsa.rb',
'test/openssl/test_provider.rb',
]
t.warning = true
end
Expand Down
25 changes: 18 additions & 7 deletions test/openssl/test_provider.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require_relative 'utils'
if defined?(OpenSSL) && defined?(OpenSSL::Provider) && !OpenSSL.fips_mode
if defined?(OpenSSL) && defined?(OpenSSL::Provider)

class OpenSSL::TestProvider < OpenSSL::TestCase
def test_openssl_provider_name_inspect
Expand All @@ -12,14 +12,22 @@ def test_openssl_provider_name_inspect
end

def test_openssl_provider_names
# We expect the following providers are loaded in the cases:
# * Non-FIPS: default
# * FIPS: fips, base
# Use the null provider to test the added provider.
# See provider(7) - OPENSSL PROVIDERS to see the list of providers, and
# OSSL_PROVIDER-null(7) to check the details of the null provider.
with_openssl <<-'end;'
base_provider = OpenSSL::Provider.load("base")
assert_equal(2, OpenSSL::Provider.provider_names.size)
assert_includes(OpenSSL::Provider.provider_names, "base")
num = OpenSSL::Provider.provider_names.size
assert_equal(true, base_provider.unload)
assert_equal(1, OpenSSL::Provider.provider_names.size)
assert_not_includes(OpenSSL::Provider.provider_names, "base")
added_provider = OpenSSL::Provider.load("null")
assert_equal(num + 1, OpenSSL::Provider.provider_names.size)
assert_includes(OpenSSL::Provider.provider_names, "null")
assert_equal(true, added_provider.unload)
assert_equal(num, OpenSSL::Provider.provider_names.size)
assert_not_includes(OpenSSL::Provider.provider_names, "null")
end;
end

Expand All @@ -33,6 +41,9 @@ def test_unloaded_openssl_provider
end

def test_openssl_legacy_provider
# The legacy provider is not supported on FIPS.
omit_on_fips

with_openssl(<<-'end;')
begin
OpenSSL::Provider.load("legacy")
Expand Down

0 comments on commit 7bdbc52

Please sign in to comment.