Add list function
Change-Id: I3923d4f12e2134250b5a61419d53582e5450bdde
diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp
index 27cb9a7..5d23a9f 100644
--- a/tests/unit-tests/ca-module.t.cpp
+++ b/tests/unit-tests/ca-module.t.cpp
@@ -23,6 +23,7 @@
#include "database-fixture.hpp"
#include "client-module.hpp"
#include "challenge-module.hpp"
+
#include <ndn-cxx/util/dummy-client-face.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/transform/public-key.hpp>
@@ -48,8 +49,8 @@
BOOST_CHECK_EQUAL(ca.getCaStorage()->getCertificate("111").getIdentity(), Name("/ndn/site2"));
advanceClocks(time::milliseconds(20), 60);
- BOOST_CHECK_EQUAL(ca.m_registeredPrefixIds.size(), 3);
- BOOST_CHECK_EQUAL(ca.m_interestFilterIds.size(), 17);
+ BOOST_CHECK_EQUAL(ca.m_registeredPrefixIds.size(), 4);
+ BOOST_CHECK_EQUAL(ca.m_interestFilterIds.size(), 18);
}
BOOST_AUTO_TEST_CASE(HandleProbe)
@@ -160,6 +161,95 @@
BOOST_CHECK_EQUAL(nClientInterest, 1);
}
+BOOST_AUTO_TEST_CASE(HandleLocalhostList)
+{
+ auto identity0 = addIdentity(Name("/ndn"));
+ auto identity1 = addIdentity(Name("/ndn/edu/ucla/cs/zhiyi"));
+ auto identity2 = addIdentity(Name("/ndn/site1"));
+ m_keyChain.setDefaultIdentity(identity0);
+
+ util::DummyClientFace face(m_io, {true, true});
+ CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test");
+
+ advanceClocks(time::milliseconds(20), 60);
+ Interest interest(Name("/localhost/CA/_LIST"));
+
+ int count = 0;
+ face.onSendData.connect([&] (const Data& response) {
+ count++;
+ JsonSection contentJson = ClientModule::getJsonFromData(response);
+ ClientConfig clientConf;
+ clientConf.load(contentJson);
+ BOOST_CHECK_EQUAL(clientConf.m_caItems.size(), 3);
+ });
+ face.receive(interest);
+
+ advanceClocks(time::milliseconds(20), 60);
+ BOOST_CHECK_EQUAL(count, 1);
+}
+
+BOOST_AUTO_TEST_CASE(HandleList)
+{
+ auto identity0 = addIdentity(Name("/ndn"));
+ util::DummyClientFace face(m_io, {true, true});
+ CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test");
+
+ advanceClocks(time::milliseconds(20), 60);
+ Interest interest(Name("/ndn/CA/_LIST"));
+
+ int count = 0;
+ face.onSendData.connect([&] (const Data& response) {
+ count++;
+ JsonSection contentJson = ClientModule::getJsonFromData(response);
+ BOOST_CHECK_EQUAL(contentJson.get_child("ca-list").size(), 2);
+ std::string schemaDataName = contentJson.get<std::string>("trust-schema");
+ BOOST_CHECK_EQUAL(schemaDataName, "TODO: add trust schema");
+ });
+ face.receive(interest);
+
+ advanceClocks(time::milliseconds(20), 60);
+ BOOST_CHECK_EQUAL(count, 1);
+}
+
+BOOST_AUTO_TEST_CASE(HandleTargetList)
+{
+ auto identity0 = addIdentity(Name("/ndn"));
+ util::DummyClientFace face(m_io, {true, true});
+ CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test");
+ ca.setRecommendCaHandler(Name("/ndn"),
+ [] (const std::string& input, const std::list<Name>& list) -> std::tuple<Name, std::string> {
+ Name recommendedCa;
+ std::string identity;
+ for (auto caName : list) {
+ std::string univName = readString(caName.get(-1));
+ if (input.find(univName) != std::string::npos) {
+ recommendedCa = caName;
+ identity = input.substr(0, input.find("@"));
+ }
+ }
+ return std::make_tuple(recommendedCa, identity);
+ });
+
+ advanceClocks(time::milliseconds(20), 60);
+ Interest interest(Name("/ndn/CA/_LIST/example@memphis.edu"));
+
+ int count = 0;
+ face.onSendData.connect([&] (const Data& response) {
+ count++;
+ JsonSection contentJson = ClientModule::getJsonFromData(response);
+ std::string recommendedCA = contentJson.get<std::string>("recommended-ca");
+ std::string recommendedIdentity = contentJson.get<std::string>("recommended-identity");
+ std::string schemaDataName = contentJson.get<std::string>("trust-schema");
+ BOOST_CHECK_EQUAL(recommendedCA, "/ndn/edu/memphis");
+ BOOST_CHECK_EQUAL(recommendedIdentity, "example");
+ BOOST_CHECK_EQUAL(schemaDataName, "TODO: add trust schema");
+ });
+ face.receive(interest);
+
+ advanceClocks(time::milliseconds(20), 60);
+ BOOST_CHECK_EQUAL(count, 1);
+}
+
BOOST_AUTO_TEST_SUITE_END() // TestCaModule
} // namespace tests
diff --git a/tests/unit-tests/client-config.t.cpp b/tests/unit-tests/client-config.t.cpp
index 9e03da0..6035510 100644
--- a/tests/unit-tests/client-config.t.cpp
+++ b/tests/unit-tests/client-config.t.cpp
@@ -41,6 +41,8 @@
BOOST_CHECK_EQUAL(item.m_targetedList, "Use your email address (edu preferred) as input");
BOOST_CHECK_EQUAL(item.m_anchor.getName().toUri(),
"/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
+
+ BOOST_CHECK_EQUAL(config.m_localNdncertAnchor, "/usr/local/etc/ndncert/anchor.key");
}
BOOST_AUTO_TEST_CASE(AddAndRemoveCaItem)
@@ -53,7 +55,7 @@
item.m_caInfo = "test";
item.m_probe = "test";
- config.addNewCaItem(item);
+ config.m_caItems.push_back(item);
BOOST_CHECK_EQUAL(config.m_caItems.size(), 3);
auto lastItem = config.m_caItems.back();
BOOST_CHECK_EQUAL(lastItem.m_caName.toUri(), "/test");
diff --git a/tests/unit-tests/client.conf.test b/tests/unit-tests/client.conf.test
index 222d6c5..9c39af1 100644
--- a/tests/unit-tests/client.conf.test
+++ b/tests/unit-tests/client.conf.test
@@ -13,5 +13,6 @@
"ca-info": "Zhiyi's own ceritificate authority",
"certificate": "Bv0CJAcsCANuZG4IBXNpdGUxCANLRVkICBG8IvRjFf8XCARzZWxmCAn9AAABWcgU2aUUCRgBAhkEADbugBX9AU8wggFLMIIBAwYHKoZIzj0CATCB9wIBATAsBgcqhkjOPQEBAiEA/////wAAAAEAAAAAAAAAAAAAAAD///////////////8wWwQg/////wAAAAEAAAAAAAAAAAAAAAD///////////////wEIFrGNdiqOpPns+u9VXaYhrxlHQawzFOw9jvOPD4n0mBLAxUAxJ02CIbnBJNqZnjhE50mt4GffpAEQQRrF9Hy4SxCR/i85uVjpEDydwN9gS3rM6D0oTlF2JjClk/jQuL+Gn+bjufrSnwPnhYrzjNXazFezsu2QGg3v1H1AiEA/////wAAAAD//////////7zm+q2nF56E87nKwvxjJVECAQEDQgAES9Cb9iANUNYmwt5bjwNW1mZgjzIkDJb6FTCdiYWnkMMIVxh2YDllphoWDEAPS6kqJczzCuhnGYpZCp9tTaYKGxZMGwEDHB0HGwgDbmRuCAVzaXRlMQgDS0VZCAgRvCL0YxX/F/0A/Sb9AP4PMTk3MDAxMDFUMDAwMDAw/QD/DzIwMzcwMTE3VDIxMjg0NhdIMEYCIQDXkR1hF3GiP7yLXq+0JBJfi9QC+hhAu/1Bykx+MWz6RAIhANwelBTxxZr2C5bD15mjfhWudK4I1tOb4b/9xWCHyM7F"
}
- ]
+ ],
+ "local-ndncert-anchor": "/usr/local/etc/ndncert/anchor.key"
}
\ No newline at end of file