1f35109
require 'openssl'
1f35109
1f35109
# Run openssl tests in OpenSSL FIPS. See the link below for how to test.
1f35109
# https://github.com/ruby/openssl/blob/master/.github/workflows/test.yml
1f35109
# - step name: test on fips module
1f35109
1f35109
# Listing the testing files by an array explicitly rather than the `Dir.glob`
1f35109
# to prevent the test files from not loading unintentionally.
1f35109
TEST_FILES = %w[
1f35109
  test/openssl/test_fips.rb
1f35109
  test/openssl/test_pkey.rb
1f35109
].freeze
1f35109
1f35109
if ARGV.empty?
1f35109
  puts 'ERROR: Argument base_dir required.'
1f35109
  puts "Usage: #{__FILE__} base_dir [options]"
1f35109
  exit false
1f35109
end
1f35109
BASE_DIR = ARGV[0]
1f35109
abs_test_files = TEST_FILES.map { |file| File.join(BASE_DIR, file) }
1f35109
1f35109
# Set Fedora/RHEL downstream OpenSSL downstream environment variable to enable
1f35109
# FIPS module in non-FIPS OS environment. It is available in Fedora 38 or later
1f35109
# versions.
1f35109
# https://src.fedoraproject.org/rpms/openssl/blob/rawhide/f/0009-Add-Kernel-FIPS-mode-flag-support.patch
1f35109
ENV['OPENSSL_FORCE_FIPS_MODE'] = '1'
1f35109
# A flag to tell the tests the current environment is FIPS enabled.
1f35109
# https://github.com/ruby/openssl/blob/master/test/openssl/test_fips.rb
1f35109
ENV['TEST_RUBY_OPENSSL_FIPS_ENABLED'] = 'true'
1f35109
1f35109
abs_test_files.each do |file|
1f35109
  puts "INFO: Loading #{file}."
1f35109
  require file
1f35109
end