|
4 | 4 | if defined?(OpenSSL) |
5 | 5 |
|
6 | 6 | class OpenSSL::TestFIPS < OpenSSL::TestCase |
| 7 | + def test_fips_mode_get_is_true_on_fips_mode_enabled |
| 8 | + unless ENV["TEST_RUBY_OPENSSL_FIPS_ENABLED"] |
| 9 | + omit "Only for FIPS mode environment" |
| 10 | + end |
| 11 | + |
| 12 | + assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") |
| 13 | + assert OpenSSL.fips_mode == true, ".fips_mode should return true on FIPS mode enabled" |
| 14 | + end; |
| 15 | + end |
| 16 | + |
| 17 | + def test_fips_mode_get_is_false_on_fips_mode_disabled |
| 18 | + if ENV["TEST_RUBY_OPENSSL_FIPS_ENABLED"] |
| 19 | + omit "Only for non-FIPS mode environment" |
| 20 | + end |
| 21 | + |
| 22 | + assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") |
| 23 | + message = ".fips_mode should return false on FIPS mode disabled. " \ |
| 24 | + "If you run the test on FIPS mode, please set " \ |
| 25 | + "TEST_RUBY_OPENSSL_FIPS_ENABLED=true" |
| 26 | + assert OpenSSL.fips_mode == false, message |
| 27 | + end; |
| 28 | + end |
| 29 | + |
7 | 30 | def test_fips_mode_is_reentrant |
8 | 31 | OpenSSL.fips_mode = false |
9 | 32 | OpenSSL.fips_mode = false |
10 | 33 | end |
11 | 34 |
|
12 | | - def test_fips_mode_get |
13 | | - return unless OpenSSL::OPENSSL_FIPS |
| 35 | + def test_fips_mode_get_with_fips_mode_set |
| 36 | + omit('OpenSSL is not FIPS-capable') unless OpenSSL::OPENSSL_FIPS |
| 37 | + |
14 | 38 | assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;") |
15 | 39 | begin |
16 | 40 | OpenSSL.fips_mode = true |
17 | | - assert OpenSSL.fips_mode == true, ".fips_mode returns true when .fips_mode=true" |
| 41 | + assert OpenSSL.fips_mode == true, ".fips_mode should return true when .fips_mode=true" |
18 | 42 |
|
19 | 43 | OpenSSL.fips_mode = false |
20 | | - assert OpenSSL.fips_mode == false, ".fips_mode returns false when .fips_mode=false" |
| 44 | + assert OpenSSL.fips_mode == false, ".fips_mode should return false when .fips_mode=false" |
21 | 45 | rescue OpenSSL::OpenSSLError |
22 | 46 | pend "Could not set FIPS mode (OpenSSL::OpenSSLError: \#$!); skipping" |
23 | 47 | end |
|
0 commit comments