Updating ca storage interface to support listing function
Change-Id: Iab9d50d075a139a671d94824b97c78b741203354
Refs:#4048
diff --git a/tests/unit-tests/ca-sqlite.t.cpp b/tests/unit-tests/ca-sqlite.t.cpp
index 496d7ae..be4b54d 100644
--- a/tests/unit-tests/ca-sqlite.t.cpp
+++ b/tests/unit-tests/ca-sqlite.t.cpp
@@ -18,43 +18,73 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
-#include "identity-management-fixture.hpp"
+#include "database-fixture.hpp"
#include "ca-detail/ca-sqlite.hpp"
namespace ndn {
namespace ndncert {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(TestCaSqlite, IdentityManagementV2TimeFixture)
+BOOST_FIXTURE_TEST_SUITE(TestCaSqlite, DatabaseFixture)
BOOST_AUTO_TEST_CASE(Initialization)
{
- BOOST_CHECK_NO_THROW(CaSqlite storage);
+ BOOST_CHECK_NO_THROW(CaSqlite storage(dbDir.string()));
}
BOOST_AUTO_TEST_CASE(CertificateOperations)
{
- CaSqlite storage;
+ CaSqlite storage(dbDir.string());
- auto identity = addIdentity(Name("/ndn/site1"));
- auto key = identity.getDefaultKey();
- auto cert = key.getDefaultCertificate();
+ auto identity1 = addIdentity(Name("/ndn/site1"));
+ auto key1 = identity1.getDefaultKey();
+ auto cert1 = key1.getDefaultCertificate();
- BOOST_CHECK_NO_THROW(storage.addCertificate("123", cert));
- auto result = storage.getCertificate("123");
- BOOST_CHECK_EQUAL(cert, result);
+ // add operation
+ BOOST_CHECK_NO_THROW(storage.addCertificate("123", cert1));
+
+ // get operation
+ BOOST_CHECK_EQUAL(storage.getCertificate("123"), cert1);
+
+ // list operation
+ auto allCerts = storage.listAllIssuedCertificates();
+ BOOST_CHECK_EQUAL(allCerts.size(), 1);
+
+ auto identity2 = addIdentity(Name("/ndn/site2"));
+ auto key2 = identity2.getDefaultKey();
+ auto cert2 = key2.getDefaultCertificate();
+ storage.addCertificate("456", cert2);
+
+ allCerts = storage.listAllIssuedCertificates();
+ BOOST_CHECK_EQUAL(allCerts.size(), 2);
+
+ BOOST_CHECK_NO_THROW(storage.deleteCertificate("123"));
+
+ allCerts = storage.listAllIssuedCertificates();
+ BOOST_CHECK_EQUAL(allCerts.size(), 1);
+
+ auto identity3 = addIdentity(Name("/ndn/site3"));
+ auto key3 = identity3.getDefaultKey();
+ auto cert3 = key3.getDefaultCertificate();
+
+ // update operation
+ BOOST_CHECK_NO_THROW(storage.updateCertificate("456", cert3));
+ BOOST_CHECK_EQUAL(storage.getCertificate("456"), cert3);
}
BOOST_AUTO_TEST_CASE(RequestOperations)
{
- CaSqlite storage;
+ CaSqlite storage(dbDir.string());
- auto identity = addIdentity(Name("/ndn/site2"));
- auto key = identity.getDefaultKey();
- auto cert = key.getDefaultCertificate();
+ auto identity1 = addIdentity(Name("/ndn/site1"));
+ auto key1 = identity1.getDefaultKey();
+ auto cert1 = key1.getDefaultCertificate();
- CertificateRequest request1(Name("/ndn/site2"), "123", cert);
+ // add operation
+ CertificateRequest request1(Name("/ndn/site1"), "123", cert1);
BOOST_CHECK_NO_THROW(storage.addRequest(request1));
+
+ // get operation
auto result = storage.getRequest("123");
BOOST_CHECK_EQUAL(request1.getCert(), result.getCert());
BOOST_CHECK_EQUAL(request1.getStatus(), result.getStatus());
@@ -62,16 +92,33 @@
JsonSection json;
json.put("code", "1234");
- std::stringstream ss;
- boost::property_tree::write_json(ss, json);
- std::string jsonValue = ss.str();
- CertificateRequest request2(Name("/ndn/site2"), "123", "need-verify", "EMAIL", jsonValue, cert);
+ // update operation
+ CertificateRequest request2(Name("/ndn/site1"), "123", "need-verify", "EMAIL",
+ CaSqlite::convertJson2String(json), cert1);
storage.updateRequest(request2);
result = storage.getRequest("123");
BOOST_CHECK_EQUAL(request2.getCert(), result.getCert());
BOOST_CHECK_EQUAL(request2.getStatus(), result.getStatus());
BOOST_CHECK_EQUAL(request2.getCaName(), result.getCaName());
+
+ auto identity2 = addIdentity(Name("/ndn/site2"));
+ auto key2 = identity2.getDefaultKey();
+ auto cert2 = key2.getDefaultCertificate();
+ CertificateRequest request3(Name("/ndn/site2"), "456", cert2);
+ storage.addRequest(request3);
+
+ // list operation
+ auto allRequests = storage.listAllRequests();
+ BOOST_CHECK_EQUAL(allRequests.size(), 2);
+
+ storage.deleteRequest("456");
+ allRequests = storage.listAllRequests();
+ BOOST_CHECK_EQUAL(allRequests.size(), 1);
+
+ storage.deleteRequest("123");
+ allRequests = storage.listAllRequests();
+ BOOST_CHECK_EQUAL(allRequests.size(), 0);
}
BOOST_AUTO_TEST_SUITE_END() // TestCaModule