diff options
Diffstat (limited to 'test/openssl/test_x509cert.rb')
-rw-r--r-- | test/openssl/test_x509cert.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/openssl/test_x509cert.rb b/test/openssl/test_x509cert.rb index 70fe9d4419..818b784b6c 100644 --- a/test/openssl/test_x509cert.rb +++ b/test/openssl/test_x509cert.rb @@ -288,6 +288,38 @@ class OpenSSL::TestX509Certificate < OpenSSL::TestCase assert_equal cert.to_der, deserialized.to_der end + def test_load_file_empty_pem + empty_path = Fixtures.file_path("pkey", "empty.pem") + assert_raise(OpenSSL::X509::CertificateError) do + OpenSSL::X509::Certificate.load_file(empty_path) + end + end + + def test_load_file_fullchain_pem + fullchain_path = Fixtures.file_path("pkey", "fullchain.pem") + certificates = OpenSSL::X509::Certificate.load_file(fullchain_path) + assert_equal 2, certificates.size + assert_equal "/CN=www.codeotaku.com", certificates[0].subject.to_s + assert_equal "/C=US/O=Let's Encrypt/CN=R3", certificates[1].subject.to_s + end + + def test_load_file_certificate_der + fullchain_path = Fixtures.file_path("pkey", "certificate.der") + certificates = OpenSSL::X509::Certificate.load_file(fullchain_path) + + # DER encoding can only contain one certificate: + assert_equal 1, certificates.size + assert_equal "/CN=www.codeotaku.com", certificates[0].subject.to_s + end + + def test_load_file_fullchain_garbage + fullchain_path = Fixtures.file_path("pkey", "garbage.txt") + + assert_raise(OpenSSL::X509::CertificateError) do + certificates = OpenSSL::X509::Certificate.load_file(fullchain_path) + end + end + private def certificate_error_returns_false |