summaryrefslogtreecommitdiff
path: root/test/openssl
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
parenta01daab656a3d32b52bd236503e3d9aebaf39483 (diff)
downloadruby-1146a94aeea7d2ea1ead3bfcbddd0f4de696abe6.tar.gz
[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')
-rw-r--r--test/openssl/fixtures/pkey/certificate.derbin0 -> 1325 bytes
-rw-r--r--test/openssl/fixtures/pkey/empty.der0
-rw-r--r--test/openssl/fixtures/pkey/empty.pem0
-rw-r--r--test/openssl/fixtures/pkey/fullchain.pem56
-rw-r--r--test/openssl/fixtures/pkey/garbage.txt1
-rw-r--r--test/openssl/test_x509cert.rb32
6 files changed, 89 insertions, 0 deletions
diff --git a/test/openssl/fixtures/pkey/certificate.der b/test/openssl/fixtures/pkey/certificate.der
new file mode 100644
index 0000000000..7d44df8413
--- /dev/null
+++ b/test/openssl/fixtures/pkey/certificate.der
Binary files differ
diff --git a/test/openssl/fixtures/pkey/empty.der b/test/openssl/fixtures/pkey/empty.der
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/openssl/fixtures/pkey/empty.der
diff --git a/test/openssl/fixtures/pkey/empty.pem b/test/openssl/fixtures/pkey/empty.pem
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/openssl/fixtures/pkey/empty.pem
diff --git a/test/openssl/fixtures/pkey/fullchain.pem b/test/openssl/fixtures/pkey/fullchain.pem
new file mode 100644
index 0000000000..624785d326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PAK3qB8oYevO4C5z70kH
+ejWEHx2taPDY/laBL21/WKZuNTYQHHPD5b1tXgHXbnL7KqC401dk5VvCadTQsvd8
+S8MXjohyc9z9/G2948kLjmE6Flh9dDYrVYA9x2O+hEPGOaEOa1eePynBgPayvUfL
+qjBstzLhWVQLGAkXXmNs+5ZnPBxzDJOLxhF2JIbeQAcH5H0tZrUlo5ZYyOqA7s9p
+O5b85o3AM/OJ+CktFBQtfvBhcJVd9wvlwPsk+uyOy2HI7mNxKKgsBTt375teA2Tw
+UdHkhVNcsAKX1H7GNNLOEADksd86wuoXvg==
+-----END CERTIFICATE-----
diff --git a/test/openssl/fixtures/pkey/garbage.txt b/test/openssl/fixtures/pkey/garbage.txt
new file mode 100644
index 0000000000..557db03de9
--- /dev/null
+++ b/test/openssl/fixtures/pkey/garbage.txt
@@ -0,0 +1 @@
+Hello World
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