aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNuno Goncalves <[email protected]>2017-04-03 23:56:29 +0200
committerNuno Goncalves <[email protected]>2017-04-04 12:09:08 +0200
commitb0068f74fb15aa4ffcb9225a60c0aaff89209b62 (patch)
tree58ab9127b8d8b7b8b29c881a2afda0611e2b32eb /src
parente01373bd429e984d658cc8cece97119fb09b19e3 (diff)
Add tests for find_cert_by_raw_subject_dn_sha256
Signed-off-by: Nuno Goncalves <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/tests/test_certstor.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/tests/test_certstor.cpp b/src/tests/test_certstor.cpp
index cf76ee4b0..abe4a4ed0 100644
--- a/src/tests/test_certstor.cpp
+++ b/src/tests/test_certstor.cpp
@@ -210,6 +210,48 @@ Test::Result test_certstor_sqlite3_all_subjects_test(const std::vector<Certifica
#endif
+Test::Result test_certstor_find_hash_subject(const std::vector<CertificateAndKey>& certsandkeys)
+ {
+ Test::Result result("Certificate Store - Find by subject hash");
+
+ try
+ {
+ Botan::Certificate_Store_In_Memory store;
+
+ for(const auto& a : certsandkeys)
+ store.add_certificate(a.certificate);
+
+ for(const auto certandkey : certsandkeys)
+ {
+ const auto cert = certandkey.certificate;
+ const auto hash = cert.raw_subject_dn_sha256();
+
+ const auto found = store.find_cert_by_raw_subject_dn_sha256(hash);
+ if(!found)
+ {
+ result.test_failure("Can't retrieve certificate " + cert.fingerprint("SHA1"));
+ return result;
+ }
+
+ result.test_eq("Got wrong certificate", hash, found->raw_subject_dn_sha256());
+ }
+
+ const auto found = store.find_cert_by_raw_subject_dn_sha256(std::vector<uint8_t>(32,0));
+ if(found)
+ {
+ result.test_failure("Certificate found for dummy hash");
+ return result;
+ }
+
+ return result;
+ }
+ catch(std::exception& e)
+ {
+ result.test_failure(e.what());
+ return result;
+ }
+ }
+
class Certstor_Tests : public Test
{
public:
@@ -272,12 +314,12 @@ class Certstor_Tests : public Test
std::vector<Test::Result> results;
+ results.push_back(test_certstor_find_hash_subject(certsandkeys));
#if defined(BOTAN_HAS_CERTSTOR_SQLITE3)
results.push_back(test_certstor_sqlite3_insert_find_remove_test(certsandkeys));
results.push_back(test_certstor_sqlite3_crl_test(certsandkeys));
results.push_back(test_certstor_sqlite3_all_subjects_test(certsandkeys));
#endif
-
return results;
}
};