Skip to content

Commit dbfcc44

Browse files
committed
test/openssl/test_ts.rb: make assert_raise blocks smaller
1 parent 3d9938e commit dbfcc44

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

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)