@@ -370,34 +370,53 @@ def test_marshal
370
370
end
371
371
372
372
def test_load_file_empty_pem
373
- empty_path = Fixtures . file_path ( "pkey" , "empty.pem" )
374
- assert_raise ( OpenSSL ::X509 ::CertificateError ) do
375
- OpenSSL ::X509 ::Certificate . load_file ( empty_path )
373
+ Tempfile . create ( "empty.pem" ) do |f |
374
+ f . close
375
+
376
+ assert_raise ( OpenSSL ::X509 ::CertificateError ) do
377
+ OpenSSL ::X509 ::Certificate . load_file ( f . path )
378
+ end
376
379
end
377
380
end
378
381
379
382
def test_load_file_fullchain_pem
380
- fullchain_path = Fixtures . file_path ( "pkey" , "fullchain.pem" )
381
- certificates = OpenSSL ::X509 ::Certificate . load_file ( fullchain_path )
382
- assert_equal 2 , certificates . size
383
- assert_equal "/CN=www.codeotaku.com" , certificates [ 0 ] . subject . to_s
384
- assert_equal "/C=US/O=Let's Encrypt/CN=R3" , certificates [ 1 ] . subject . to_s
383
+ cert1 = issue_cert ( @ee1 , @rsa2048 , 1 , [ ] , nil , nil )
384
+ cert2 = issue_cert ( @ca , @rsa2048 , 1 , [ ] , nil , nil )
385
+
386
+ Tempfile . create ( "fullchain.pem" ) do |f |
387
+ f . puts cert1 . to_pem
388
+ f . puts cert2 . to_pem
389
+ f . close
390
+
391
+ certificates = OpenSSL ::X509 ::Certificate . load_file ( f . path )
392
+ assert_equal 2 , certificates . size
393
+ assert_equal @ee1 , certificates [ 0 ] . subject
394
+ assert_equal @ca , certificates [ 1 ] . subject
395
+ end
385
396
end
386
397
387
398
def test_load_file_certificate_der
388
- fullchain_path = Fixtures . file_path ( "pkey" , "certificate.der" )
389
- certificates = OpenSSL ::X509 ::Certificate . load_file ( fullchain_path )
399
+ cert = issue_cert ( @ca , @rsa2048 , 1 , [ ] , nil , nil )
400
+ Tempfile . create ( "certificate.der" , binmode : true ) do |f |
401
+ f . write cert . to_der
402
+ f . close
390
403
391
- # DER encoding can only contain one certificate:
392
- assert_equal 1 , certificates . size
393
- assert_equal "/CN=www.codeotaku.com" , certificates [ 0 ] . subject . to_s
404
+ certificates = OpenSSL ::X509 ::Certificate . load_file ( f . path )
405
+
406
+ # DER encoding can only contain one certificate:
407
+ assert_equal 1 , certificates . size
408
+ assert_equal cert . to_der , certificates [ 0 ] . to_der
409
+ end
394
410
end
395
411
396
412
def test_load_file_fullchain_garbage
397
- fullchain_path = Fixtures . file_path ( "pkey" , "garbage.txt" )
413
+ Tempfile . create ( "garbage.txt" ) do |f |
414
+ f . puts "not a certificate"
415
+ f . close
398
416
399
- assert_raise ( OpenSSL ::X509 ::CertificateError ) do
400
- OpenSSL ::X509 ::Certificate . load_file ( fullchain_path )
417
+ assert_raise ( OpenSSL ::X509 ::CertificateError ) do
418
+ OpenSSL ::X509 ::Certificate . load_file ( f . path )
419
+ end
401
420
end
402
421
end
403
422
0 commit comments