Skip to content

Commit 54d26ed

Browse files
authored
Merge pull request #910 from rhenium/ky/update-tests-ci-20250711
Various test and CI improvements
2 parents f887d9f + dbfcc44 commit 54d26ed

File tree

7 files changed

+62
-64
lines changed

7 files changed

+62
-64
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ jobs:
6060
if: ${{ !matrix.skip-warnings }}
6161

6262
- name: rake compile
63-
run: bundle exec rake compile
63+
run: bundle exec rake debug_compiler compile
64+
65+
- name: rake debug
66+
run: bundle exec rake debug
6467

6568
- name: rake test
66-
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately"
69+
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately" OSSL_TEST_ALL=1
6770
timeout-minutes: 5
6871

6972
test-openssls:
@@ -158,10 +161,13 @@ jobs:
158161
if: ${{ !matrix.skip-warnings }}
159162

160163
- name: rake compile
161-
run: bundle exec rake compile -- --with-openssl-dir=$HOME/openssl
164+
run: bundle exec rake debug_compiler compile -- --with-openssl-dir=$HOME/openssl
165+
166+
- name: rake debug
167+
run: bundle exec rake debug
162168

163169
- name: rake test
164-
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately"
170+
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately" OSSL_TEST_ALL=1
165171
timeout-minutes: 5
166172

167173
# Run only the passing tests on the FIPS module as a temporary workaround.
@@ -170,6 +176,7 @@ jobs:
170176
run: |
171177
sed -e "s|OPENSSL_DIR|$HOME/openssl|" tool/openssl_fips.cnf.tmpl > tmp/openssl_fips.cnf
172178
export OPENSSL_CONF=$(pwd)/tmp/openssl_fips.cnf
173-
bundle exec rake test_fips TESTOPTS="-v --no-show-detail-immediately"
179+
bundle exec rake debug
180+
bundle exec rake test_fips TESTOPTS="-v --no-show-detail-immediately" OSSL_TEST_ALL=1
174181
timeout-minutes: 5
175182
if: ${{ startsWith(matrix.openssl, 'openssl-3') || matrix.openssl == 'openssl-master' }}

Rakefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ require 'bundler/gem_tasks'
55
begin
66
require 'rake/extensiontask'
77
Rake::ExtensionTask.new('openssl')
8-
# Run the debug_compiler task before the compile task.
9-
Rake::Task['compile'].prerequisites.unshift :debug_compiler
108
rescue LoadError
119
warn "rake-compiler not installed. Run 'bundle install' to " \
1210
"install testing dependency gems."
1311
end
1412

1513
Rake::TestTask.new do |t|
16-
t.libs << 'test/openssl'
1714
t.test_files = FileList["test/**/test_*.rb"]
1815
t.warning = true
1916
end
@@ -25,7 +22,6 @@ task :test_fips do
2522
end
2623

2724
Rake::TestTask.new(:test_fips_internal) do |t|
28-
t.libs << 'test/openssl'
2925
# Exclude failing test files in FIPS for this task to pass.
3026
# TODO: Fix failing test files.
3127
t.test_files = FileList['test/**/test_*.rb'] - FileList[
@@ -53,12 +49,8 @@ RDoc::Task.new do |rdoc|
5349
rdoc.rdoc_files.include("*.md", "lib/**/*.rb", "ext/**/*.c")
5450
end
5551

56-
task :test => [:compile, :debug]
57-
task :test_fips => [:compile, :debug]
58-
5952
# Print Ruby and compiler info for debugging purpose.
6053
task :debug_compiler do
61-
ruby '-v'
6254
compiler = RbConfig::CONFIG['CC']
6355
case compiler
6456
when 'gcc', 'clang'
@@ -84,7 +76,7 @@ task :debug do
8476
Providers: #{providers_str}
8577
MESSAGE
8678
EOF
87-
ruby %Q(-I./lib -ropenssl.so -ve'#{ruby_code}')
79+
ruby %Q(-I./lib -ropenssl.so -e'#{ruby_code}'), verbose: false
8880
end
8981

9082
task :default => :test

test/openssl/test_ossl.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33

44
if defined?(OpenSSL)
55

6-
class OpenSSL::OSSL < OpenSSL::SSLTestCase
6+
class OpenSSL::TestOSSL < OpenSSL::TestCase
77
def test_fixed_length_secure_compare
88
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "a") }
99
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "aa") }
1010

11-
assert OpenSSL.fixed_length_secure_compare("aaa", "aaa")
12-
assert OpenSSL.fixed_length_secure_compare(
11+
assert_true(OpenSSL.fixed_length_secure_compare("aaa", "aaa"))
12+
assert_true(OpenSSL.fixed_length_secure_compare(
1313
OpenSSL::Digest.digest('SHA256', "aaa"), OpenSSL::Digest::SHA256.digest("aaa")
14-
)
14+
))
1515

1616
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "aaaa") }
17-
refute OpenSSL.fixed_length_secure_compare("aaa", "baa")
18-
refute OpenSSL.fixed_length_secure_compare("aaa", "aba")
19-
refute OpenSSL.fixed_length_secure_compare("aaa", "aab")
17+
assert_false(OpenSSL.fixed_length_secure_compare("aaa", "baa"))
18+
assert_false(OpenSSL.fixed_length_secure_compare("aaa", "aba"))
19+
assert_false(OpenSSL.fixed_length_secure_compare("aaa", "aab"))
2020
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "aaab") }
2121
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "b") }
2222
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "bb") }
23-
refute OpenSSL.fixed_length_secure_compare("aaa", "bbb")
23+
assert_false(OpenSSL.fixed_length_secure_compare("aaa", "bbb"))
2424
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "bbbb") }
2525
end
2626

2727
def test_secure_compare
28-
refute OpenSSL.secure_compare("aaa", "a")
29-
refute OpenSSL.secure_compare("aaa", "aa")
28+
assert_false(OpenSSL.secure_compare("aaa", "a"))
29+
assert_false(OpenSSL.secure_compare("aaa", "aa"))
3030

31-
assert OpenSSL.secure_compare("aaa", "aaa")
31+
assert_true(OpenSSL.secure_compare("aaa", "aaa"))
3232

33-
refute OpenSSL.secure_compare("aaa", "aaaa")
34-
refute OpenSSL.secure_compare("aaa", "baa")
35-
refute OpenSSL.secure_compare("aaa", "aba")
36-
refute OpenSSL.secure_compare("aaa", "aab")
37-
refute OpenSSL.secure_compare("aaa", "aaab")
38-
refute OpenSSL.secure_compare("aaa", "b")
39-
refute OpenSSL.secure_compare("aaa", "bb")
40-
refute OpenSSL.secure_compare("aaa", "bbb")
41-
refute OpenSSL.secure_compare("aaa", "bbbb")
33+
assert_false(OpenSSL.secure_compare("aaa", "aaaa"))
34+
assert_false(OpenSSL.secure_compare("aaa", "baa"))
35+
assert_false(OpenSSL.secure_compare("aaa", "aba"))
36+
assert_false(OpenSSL.secure_compare("aaa", "aab"))
37+
assert_false(OpenSSL.secure_compare("aaa", "aaab"))
38+
assert_false(OpenSSL.secure_compare("aaa", "b"))
39+
assert_false(OpenSSL.secure_compare("aaa", "bb"))
40+
assert_false(OpenSSL.secure_compare("aaa", "bbb"))
41+
assert_false(OpenSSL.secure_compare("aaa", "bbbb"))
4242
end
4343

4444
def test_memcmp_timing
@@ -63,7 +63,7 @@ def test_memcmp_timing
6363
end
6464
assert_operator(a_b_time, :<, a_c_time * 10, "fixed_length_secure_compare timing test failed")
6565
assert_operator(a_c_time, :<, a_b_time * 10, "fixed_length_secure_compare timing test failed")
66-
end
66+
end if ENV["OSSL_TEST_ALL"] == "1"
6767

6868
def test_error_data
6969
# X509V3_EXT_nconf_nid() called from OpenSSL::X509::ExtensionFactory#create_ext is a function

test/openssl/test_pkey_dh.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_new_generate
1616
# This test is slow
1717
dh = OpenSSL::PKey::DH.new(NEW_KEYLEN)
1818
assert_key(dh)
19-
end if ENV["OSSL_TEST_ALL"]
19+
end if ENV["OSSL_TEST_ALL"] == "1"
2020

2121
def test_new_break
2222
unless openssl? && OpenSSL.fips_mode

test/openssl/test_pkey_dsa.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def test_generate
4747
assert_equal 1024, key1024.p.num_bits
4848
assert_equal 160, key1024.q.num_bits
4949

50-
key2048 = OpenSSL::PKey::DSA.generate(2048)
51-
assert_equal 2048, key2048.p.num_bits
52-
assert_equal 256, key2048.q.num_bits
53-
5450
if ENV["OSSL_TEST_ALL"] == "1" # slow
51+
key2048 = OpenSSL::PKey::DSA.generate(2048)
52+
assert_equal 2048, key2048.p.num_bits
53+
assert_equal 256, key2048.q.num_bits
54+
5555
key3072 = OpenSSL::PKey::DSA.generate(3072)
5656
assert_equal 3072, key3072.p.num_bits
5757
assert_equal 256, key3072.q.num_bits

test/openssl/test_ssl_session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_server_session_cache
222222

223223
# Skipping tests that use session_remove_cb by default because it may cause
224224
# deadlock.
225-
TEST_SESSION_REMOVE_CB = ENV["OSSL_TEST_ALL"] == "1"
225+
TEST_SESSION_REMOVE_CB = ENV["OSSL_TEST_UNSAFE"] == "1"
226226

227227
def test_ctx_client_session_cb_tls12
228228
start_server do |port|

test/openssl/test_ts.rb

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ def ts_cert_ee
7070
def test_request_mandatory_fields
7171
req = OpenSSL::Timestamp::Request.new
7272
assert_raise(OpenSSL::Timestamp::TimestampError) do
73-
tmp = req.to_der
74-
pp OpenSSL::ASN1.decode(tmp)
73+
req.to_der
7574
end
7675
req.algorithm = "sha1"
7776
assert_raise(OpenSSL::Timestamp::TimestampError) do
7877
req.to_der
7978
end
8079
req.message_imprint = OpenSSL::Digest.digest('SHA1', "data")
81-
req.to_der
80+
assert_nothing_raised { req.to_der }
8281
end
8382

8483
def test_request_assignment
@@ -371,60 +370,60 @@ def test_no_cert_requested
371370
end
372371

373372
def test_response_no_policy_defined
374-
assert_raise(OpenSSL::Timestamp::TimestampError) do
375-
req = OpenSSL::Timestamp::Request.new
376-
req.algorithm = "SHA1"
377-
digest = OpenSSL::Digest.digest('SHA1', "test")
378-
req.message_imprint = digest
373+
req = OpenSSL::Timestamp::Request.new
374+
req.algorithm = "SHA1"
375+
digest = OpenSSL::Digest.digest('SHA1', "test")
376+
req.message_imprint = digest
379377

380-
fac = OpenSSL::Timestamp::Factory.new
381-
fac.gen_time = Time.now
382-
fac.serial_number = 1
383-
fac.allowed_digests = ["sha1"]
378+
fac = OpenSSL::Timestamp::Factory.new
379+
fac.gen_time = Time.now
380+
fac.serial_number = 1
381+
fac.allowed_digests = ["sha1"]
384382

383+
assert_raise(OpenSSL::Timestamp::TimestampError) do
385384
fac.create_timestamp(ee_key, ts_cert_ee, req)
386385
end
387386
end
388387

389388
def test_verify_ee_no_req
389+
ts, _ = timestamp_ee
390390
assert_raise(TypeError) do
391-
ts, _ = timestamp_ee
392391
ts.verify(nil, ca_cert)
393392
end
394393
end
395394

396395
def test_verify_ee_no_store
396+
ts, req = timestamp_ee
397397
assert_raise(TypeError) do
398-
ts, req = timestamp_ee
399398
ts.verify(req, nil)
400399
end
401400
end
402401

403402
def test_verify_ee_wrong_root_no_intermediate
403+
ts, req = timestamp_ee
404404
assert_raise(OpenSSL::Timestamp::TimestampError) do
405-
ts, req = timestamp_ee
406405
ts.verify(req, intermediate_store)
407406
end
408407
end
409408

410409
def test_verify_ee_wrong_root_wrong_intermediate
410+
ts, req = timestamp_ee
411411
assert_raise(OpenSSL::Timestamp::TimestampError) do
412-
ts, req = timestamp_ee
413412
ts.verify(req, intermediate_store, [ca_cert])
414413
end
415414
end
416415

417416
def test_verify_ee_nonce_mismatch
417+
ts, req = timestamp_ee
418+
req.nonce = 1
418419
assert_raise(OpenSSL::Timestamp::TimestampError) do
419-
ts, req = timestamp_ee
420-
req.nonce = 1
421420
ts.verify(req, ca_store, [intermediate_cert])
422421
end
423422
end
424423

425424
def test_verify_ee_intermediate_missing
425+
ts, req = timestamp_ee
426426
assert_raise(OpenSSL::Timestamp::TimestampError) do
427-
ts, req = timestamp_ee
428427
ts.verify(req, ca_store)
429428
end
430429
end
@@ -472,27 +471,27 @@ def test_verify_direct_unrelated_untrusted
472471
end
473472

474473
def test_verify_direct_wrong_root
474+
ts, req = timestamp_direct
475475
assert_raise(OpenSSL::Timestamp::TimestampError) do
476-
ts, req = timestamp_direct
477476
ts.verify(req, intermediate_store)
478477
end
479478
end
480479

481480
def test_verify_direct_no_cert_no_intermediate
481+
ts, req = timestamp_direct_no_cert
482482
assert_raise(OpenSSL::Timestamp::TimestampError) do
483-
ts, req = timestamp_direct_no_cert
484483
ts.verify(req, ca_store)
485484
end
486485
end
487486

488487
def test_verify_ee_no_cert
489488
ts, req = timestamp_ee_no_cert
490-
ts.verify(req, ca_store, [ts_cert_ee, intermediate_cert])
489+
assert_same(ts, ts.verify(req, ca_store, [ts_cert_ee, intermediate_cert]))
491490
end
492491

493492
def test_verify_ee_no_cert_no_intermediate
493+
ts, req = timestamp_ee_no_cert
494494
assert_raise(OpenSSL::Timestamp::TimestampError) do
495-
ts, req = timestamp_ee_no_cert
496495
ts.verify(req, ca_store, [ts_cert_ee])
497496
end
498497
end

0 commit comments

Comments
 (0)