aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-12-04 14:00:47 -0500
committerJack Lloyd <[email protected]>2017-12-04 14:00:47 -0500
commit697fdc8fcb7f4ada4699ccad80def4673270d133 (patch)
tree5b2ec8652a20d7e0c0b74f328958818fafaa14b4 /src/tests
parentd3c1f3ba1a9d03ff8e84f0044ee3854804fac86b (diff)
Support uninitialized certificate objects
Issued raised by @securitykernel on Slack, there was no non-hacky way to decode a list of certificate objects because creating an uninitialized one wasn't allowed. However after #884 that got much closer to being viable, this is the last pieces.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/data/x509/misc/cert_seq.derbin0 -> 1271 bytes
-rw-r--r--src/tests/unit_x509.cpp37
2 files changed, 37 insertions, 0 deletions
diff --git a/src/tests/data/x509/misc/cert_seq.der b/src/tests/data/x509/misc/cert_seq.der
new file mode 100644
index 000000000..4d93ccaff
--- /dev/null
+++ b/src/tests/data/x509/misc/cert_seq.der
Binary files differ
diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp
index 72c497ca7..5fbea2f4f 100644
--- a/src/tests/unit_x509.cpp
+++ b/src/tests/unit_x509.cpp
@@ -755,6 +755,41 @@ Test::Result test_self_issued(const std::string& sig_algo, const std::string& ha
return result;
}
+Test::Result test_x509_uninit()
+ {
+ Test::Result result("X509 object uninitialized access");
+
+ Botan::X509_Certificate cert;
+ result.test_throws("uninitialized cert access causes exception",
+ "X509_Certificate uninitialized",
+ [&cert]() { cert.x509_version(); });
+
+ Botan::X509_CRL crl;
+ result.test_throws("uninitialized crl access causes exception",
+ "X509_CRL uninitialized",
+ [&crl]() { crl.crl_number(); });
+
+ return result;
+ }
+
+Test::Result test_x509_decode_list()
+ {
+ Test::Result result("X509_Certificate list decode");
+
+ Botan::DataSource_Stream input(Test::data_file("x509/misc/cert_seq.der"));
+
+ Botan::BER_Decoder dec(input);
+ std::vector<Botan::X509_Certificate> certs;
+ dec.decode_list(certs);
+
+ result.test_eq("Expected number of certs in list", certs.size(), 2);
+
+ result.test_eq("Expected cert 1 CN", certs[0].subject_dn().get_first_attribute("CN"), "CA1-PP.01.02");
+ result.test_eq("Expected cert 2 CN", certs[1].subject_dn().get_first_attribute("CN"), "User1-PP.01.02");
+
+ return result;
+ }
+
using Botan::Key_Constraints;
@@ -1250,6 +1285,8 @@ class X509_Cert_Unit_Tests final : public Test
results.push_back(test_x509_utf8());
results.push_back(test_x509_bmpstring());
results.push_back(test_crl_dn_name());
+ results.push_back(test_x509_uninit());
+ results.push_back(test_x509_decode_list());
return results;
}