Update the CertificateRequest and JSON helper functions to the newest packet format
Change-Id: I28dd2753dfc5d8dda658be455e3804445a9efc26
diff --git a/tests/unit-tests/certificate-request.t.cpp b/tests/unit-tests/certificate-request.t.cpp
index 113748d..3282ee9 100644
--- a/tests/unit-tests/certificate-request.t.cpp
+++ b/tests/unit-tests/certificate-request.t.cpp
@@ -38,49 +38,43 @@
CertificateRequest request1(Name("/ndn/site1"), "123", cert);
BOOST_CHECK_EQUAL(request1.getCaName().toUri(), "/ndn/site1");
BOOST_CHECK_EQUAL(request1.getRequestId(), "123");
- BOOST_CHECK_EQUAL(request1.getStatus(), CertificateRequest::Pending);
- BOOST_CHECK_EQUAL(request1.getChallengeType(), "");
- BOOST_CHECK_EQUAL(request1.getChallengeStatus(), "");
- BOOST_CHECK_EQUAL(request1.getChallengeDefinedField(), "");
- BOOST_CHECK_EQUAL(request1.getChallengeInstruction(), "");
+ BOOST_CHECK_EQUAL(request1.getStatus(), "");
+ BOOST_CHECK_EQUAL(request1.getChallengeSecrets().empty(), true);
+ BOOST_CHECK_EQUAL(request1.getCert(), cert);
BOOST_CHECK_EQUAL(request1.getCert(), cert);
- CertificateRequest request2(Name("/ndn/site1"), "123", CertificateRequest::Verifying,
- "Email", "NEED_CODE", "123456", cert);
+ 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/site1"), "123", "need-verify", "EMAIL", jsonValue, cert);
BOOST_CHECK_EQUAL(request2.getCaName().toUri(), "/ndn/site1");
BOOST_CHECK_EQUAL(request2.getRequestId(), "123");
- BOOST_CHECK_EQUAL(request2.getStatus(), CertificateRequest::Verifying);
- BOOST_CHECK_EQUAL(request2.getChallengeType(), "Email");
- BOOST_CHECK_EQUAL(request2.getChallengeStatus(), "NEED_CODE");
- BOOST_CHECK_EQUAL(request2.getChallengeDefinedField(), "123456");
- BOOST_CHECK_EQUAL(request2.getChallengeInstruction(), "");
+ BOOST_CHECK_EQUAL(request2.getStatus(), "need-verify");
+ BOOST_CHECK_EQUAL(request2.getChallengeType(), "EMAIL");
+ BOOST_CHECK(request2.getChallengeSecrets() == json);
BOOST_CHECK_EQUAL(request2.getCert(), cert);
}
-BOOST_AUTO_TEST_CASE(GetStatusOutput)
-{
- CertificateRequest::ApplicationStatus status = CertificateRequest::Success;
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), "success");
-}
-
BOOST_AUTO_TEST_CASE(GetterSetter)
{
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- CertificateRequest request(Name("/ndn/site1"), "123", cert);
- request.setStatus(CertificateRequest::Verifying);
- request.setChallengeType("Email");
- request.setChallengeDefinedField("456");
- request.setChallengeStatus("NEED_EMAIL");
- request.setChallengeInstruction("Please provide your email address");
+ JsonSection json;
+ json.put("code", "1234");
- BOOST_CHECK_EQUAL(request.getStatus(), CertificateRequest::Verifying);
- BOOST_CHECK_EQUAL(request.getChallengeType(), "Email");
- BOOST_CHECK_EQUAL(request.getChallengeDefinedField(), "456");
- BOOST_CHECK_EQUAL(request.getChallengeStatus(), "NEED_EMAIL");
- BOOST_CHECK_EQUAL(request.getChallengeInstruction(), "Please provide your email address");
+ CertificateRequest request(Name("/ndn/site1"), "123", cert);
+ request.setStatus("need-verify");
+ request.setChallengeType("EMAIL");
+ request.setChallengeSecrets(json);
+
+ BOOST_CHECK_EQUAL(request.getStatus(), "need-verify");
+ BOOST_CHECK_EQUAL(request.getChallengeType(), "EMAIL");
+ BOOST_CHECK(request.getChallengeSecrets() == json);
}
BOOST_AUTO_TEST_CASE(GetCertificateRequestOutput)
@@ -101,8 +95,6 @@
/ndn/site1
Request ID:
123
-Request Status:
- pending
Certificate:
Certificate name:
/ndn/site1/KEY/ksk-1416425377094/0123/%FD%00%00%01I%C9%8B
diff --git a/tests/unit-tests/json-helper.t.cpp b/tests/unit-tests/json-helper.t.cpp
index d258e54..61a74e5 100644
--- a/tests/unit-tests/json-helper.t.cpp
+++ b/tests/unit-tests/json-helper.t.cpp
@@ -18,14 +18,14 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
-#include "identity-management-fixture.hpp"
+#include "boost-test.hpp"
#include "json-helper.hpp"
namespace ndn {
namespace ndncert {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(TestJsonHelper, IdentityManagementV2Fixture)
+BOOST_AUTO_TEST_SUITE(TestJsonHelper)
BOOST_AUTO_TEST_CASE(GenerateProbeJson)
{
@@ -37,45 +37,33 @@
BOOST_AUTO_TEST_CASE(GenerateNewResponseJson)
{
- auto identity = addIdentity(Name("/ndn/site1"));
- auto key = identity.getDefaultKey();
- auto cert = key.getDefaultCertificate();
+ std::list<std::string> challenges;
+ challenges.push_back("PIN");
+ challenges.push_back("EMAIL");
+ auto result = genResponseNewJson("598234759", challenges);
- CertificateRequest request(Name("/ndn/site1"), "598234759", cert);
- std::list<std::tuple<std::string, std::string>> challenges;
- challenges.push_back(std::make_tuple("PIN", "Please ask ca officer"));
- challenges.push_back(std::make_tuple("EMAIL", "Please provide your email"));
- auto result = genResponseNewJson(request, challenges);
-
- BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "pending");
BOOST_CHECK_EQUAL(result.get<std::string>(JSON_REQUEST_ID), "598234759");
auto child = result.get_child(JSON_CHALLENGES);
auto it = child.begin();
BOOST_CHECK_EQUAL(it->second.get<std::string>(JSON_CHALLENGE_TYPE), "PIN");
- BOOST_CHECK_EQUAL(it->second.get<std::string>(JSON_CHALLENGE_INSTRUCTION),
- "Please ask ca officer");
it++;
BOOST_CHECK_EQUAL(it->second.get<std::string>(JSON_CHALLENGE_TYPE), "EMAIL");
- BOOST_CHECK_EQUAL(it->second.get<std::string>(JSON_CHALLENGE_INSTRUCTION),
- "Please provide your email");
}
-BOOST_AUTO_TEST_CASE(GeneratePollResponseJson)
+BOOST_AUTO_TEST_CASE(GenerateChallengeResponseJson)
{
- auto identity = addIdentity(Name("/ndn/site1"));
- auto key = identity.getDefaultKey();
- auto cert = key.getDefaultCertificate();
+ auto result = genResponseChallengeJson("598234759", "EMAIL", "need-code");
- CertificateRequest request(Name("/ndn/site1"), "598234759", CertificateRequest::Verifying,
- "Email", "NEED_CODE", "111", cert);
- request.setChallengeInstruction("Please provide verification code");
- auto result = genResponsePollJson(request);
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_REQUEST_ID), "598234759");
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_TYPE), "EMAIL");
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "need-code");
- BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "verifying");
- BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_TYPE), "Email");
- BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_STATUS), "NEED_CODE");
- BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_INSTRUCTION),
- "Please provide verification code");
+ result = genResponseChallengeJson("598234759", "EMAIL", "need-code", Name("/ndn/test"));
+
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_REQUEST_ID), "598234759");
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_TYPE), "EMAIL");
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "need-code");
+ BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CERTIFICATE), "/ndn/test");
}
BOOST_AUTO_TEST_CASE(GenerateErrorJson)