summaryrefslogtreecommitdiff
path: root/test/openssl/test_x509cert.rb
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-05-22 08:47:20 +1200
committerKazuki Yamaguchi <k@rhe.jp>2021-07-18 17:44:55 +0900
commit1146a94aeea7d2ea1ead3bfcbddd0f4de696abe6 (patch)
treeea3cf733e6c7e7c141b6ffd1c2b89a7392498a93 /test/openssl/test_x509cert.rb
parenta01daab656a3d32b52bd236503e3d9aebaf39483 (diff)
[ruby/openssl] Implement `Certificate.load` to load certificate chain. (https://github.com/ruby/openssl/pull/441)
* Add feature for loading the chained certificate into Certificate array. https://github.com/ruby/openssl/commit/05e1c015d6 Co-authored-by: Sao I Kuan <saoikuan@gmail.com>
Diffstat (limited to 'test/openssl/test_x509cert.rb')
-rw-r--r--test/openssl/test_x509cert.rb32
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