Update the NDNCERT library to version NDNCERT v2
spec:[https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-new]
Change-Id: Ia480a8e70c4b38ca170dfe2fcf50d1265ab65f46
diff --git a/tests/unit-tests/challenge-email.t.cpp b/tests/unit-tests/challenge-email.t.cpp
index f723f6a..3b9850c 100644
--- a/tests/unit-tests/challenge-email.t.cpp
+++ b/tests/unit-tests/challenge-email.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2017-2018, Regents of the University of California.
+ * Copyright (c) 2017-2019, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,7 +25,7 @@
namespace ndncert {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(TestChallengeEmail, IdentityManagementV2Fixture)
+BOOST_FIXTURE_TEST_SUITE(TestChallengeEmail, IdentityManagementFixture)
BOOST_AUTO_TEST_CASE(TestChallengeType)
{
@@ -33,20 +33,6 @@
BOOST_CHECK_EQUAL(challenge.CHALLENGE_TYPE, "Email");
}
-BOOST_AUTO_TEST_CASE(ParseStoredSecret)
-{
- time::system_clock::TimePoint tp = time::fromIsoString("20170207T120000");
- JsonSection json;
- json.put(ChallengeEmail::JSON_CODE_TP, time::toIsoString(tp));
- json.put(ChallengeEmail::JSON_CODE, "1234");
- json.put(ChallengeEmail::JSON_ATTEMPT_TIMES, std::to_string(3));
-
- auto result = ChallengeEmail::parseStoredSecrets(json);
- BOOST_CHECK_EQUAL(std::get<0>(result), tp);
- BOOST_CHECK_EQUAL(std::get<1>(result), "1234");
- BOOST_CHECK_EQUAL(std::get<2>(result), 3);
-}
-
BOOST_AUTO_TEST_CASE(EmailAddressChecker)
{
BOOST_CHECK_EQUAL(ChallengeEmail::isValidEmailAddress("zhiyi@cs.ucla.edu"), true);
@@ -54,28 +40,26 @@
BOOST_CHECK_EQUAL(ChallengeEmail::isValidEmailAddress("zhiyi.ucla.edu"), false);
}
-BOOST_AUTO_TEST_CASE(OnSelectInterestComingWithEmail)
+BOOST_AUTO_TEST_CASE(OnChallengeRequestWithEmail)
{
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- CertificateRequest request(Name("/ndn/site1"), "123", cert);
+ CertificateRequest request(Name("/ndn/site1"), "123", STATUS_BEFORE_CHALLENGE, cert);
JsonSection emailJson;
emailJson.put(ChallengeEmail::JSON_EMAIL, "zhiyi@cs.ucla.edu");
- std::stringstream ss;
- boost::property_tree::write_json(ss, emailJson);
- Block jsonContent = makeStringBlock(ndn::tlv::GenericNameComponent, ss.str());
-
- Name interestName("/ndn/site1/CA");
- interestName.append("_SELECT").append("Fake-Request-ID").append("EMAIL").append(jsonContent);
- Interest interest(interestName);
ChallengeEmail challenge("./tests/unit-tests/test-send-email.sh");
- challenge.handleChallengeRequest(interest, request);
+ challenge.handleChallengeRequest(emailJson, request);
- BOOST_CHECK_EQUAL(request.getStatus(), ChallengeEmail::NEED_CODE);
- BOOST_CHECK_EQUAL(request.getChallengeType(), "Email");
+ BOOST_CHECK_EQUAL(request.m_status, STATUS_CHALLENGE);
+ BOOST_CHECK_EQUAL(request.m_challengeStatus, ChallengeEmail::NEED_CODE);
+ BOOST_CHECK(request.m_challengeSecrets.get<std::string>(ChallengeEmail::JSON_CODE) != "");
+ BOOST_CHECK(request.m_remainingTime != 0);
+ BOOST_CHECK(request.m_remainingTries != 0);
+ BOOST_CHECK(request.m_challengeTp != "");
+ BOOST_CHECK_EQUAL(request.m_challengeType, "Email");
std::string line = "";
std::string delimiter = " ";
@@ -89,68 +73,47 @@
std::string secret = line.substr(line.find(delimiter) + 1);
BOOST_CHECK_EQUAL(recipientEmail, "zhiyi@cs.ucla.edu");
- auto stored_secret = request.getChallengeSecrets().get<std::string>(ChallengeEmail::JSON_CODE);
+ auto stored_secret = request.m_challengeSecrets.get<std::string>(ChallengeEmail::JSON_CODE);
BOOST_CHECK_EQUAL(secret, stored_secret);
-
std::remove("tmp.txt");
}
-BOOST_AUTO_TEST_CASE(OnSelectInterestComingWithInvalidEmail)
+BOOST_AUTO_TEST_CASE(OnChallengeRequestWithInvalidEmail)
{
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- CertificateRequest request(Name("/ndn/site1"), "123", cert);
+ CertificateRequest request(Name("/ndn/site1"), "123", STATUS_BEFORE_CHALLENGE, cert);
JsonSection emailJson;
emailJson.put(ChallengeEmail::JSON_EMAIL, "zhiyi@cs");
- std::stringstream ss;
- boost::property_tree::write_json(ss, emailJson);
- Block jsonContent = makeStringBlock(ndn::tlv::GenericNameComponent, ss.str());
-
- Name interestName("/ndn/site1/CA");
- interestName.append("_SELECT").append("Fake-Request-ID").append("EMAIL").append(jsonContent);
- Interest interest(interestName);
ChallengeEmail challenge;
- challenge.handleChallengeRequest(interest, request);
+ challenge.handleChallengeRequest(emailJson, request);
- BOOST_CHECK_EQUAL(request.getStatus(), ChallengeEmail::FAILURE_INVALID_EMAIL);
- BOOST_CHECK_EQUAL(request.getChallengeType(), "Email");
+ BOOST_CHECK_EQUAL(request.m_challengeStatus, ChallengeEmail::FAILURE_INVALID_EMAIL);
+ BOOST_CHECK_EQUAL(request.m_status, STATUS_FAILURE);
}
-BOOST_AUTO_TEST_CASE(OnValidateInterestComingWithCode)
+BOOST_AUTO_TEST_CASE(OnChallengeRequestWithCode)
{
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- CertificateRequest request(Name("/ndn/site1"), "123", cert);
- request.setChallengeType("EMAIL");
- request.setStatus(ChallengeEmail::NEED_CODE);
-
- time::system_clock::TimePoint tp = time::system_clock::now();
JsonSection json;
- json.put(ChallengeEmail::JSON_CODE_TP, time::toIsoString(tp));
json.put(ChallengeEmail::JSON_CODE, "4567");
- json.put(ChallengeEmail::JSON_ATTEMPT_TIMES, std::to_string(3));
+ CertificateRequest request(Name("/ndn/site1"), "123", STATUS_CHALLENGE, ChallengeEmail::NEED_CODE,
+ "Email", time::toIsoString(time::system_clock::now()), 3600, 3, json, cert);
- request.setChallengeSecrets(json);
-
- JsonSection infoJson;
- infoJson.put(ChallengeEmail::JSON_CODE, "4567");
- std::stringstream ss;
- boost::property_tree::write_json(ss, infoJson);
- Block jsonContent = makeStringBlock(ndn::tlv::GenericNameComponent, ss.str());
-
- Name interestName("/ndn/site1/CA");
- interestName.append("_VALIDATE").append("Fake-Request-ID").append("EMAIL").append(jsonContent);
- Interest interest(interestName);
+ JsonSection requestJson;
+ requestJson.put(ChallengeEmail::JSON_CODE, "4567");
ChallengeEmail challenge;
- challenge.handleChallengeRequest(interest, request);
+ challenge.handleChallengeRequest(requestJson, request);
- BOOST_CHECK_EQUAL(request.getStatus(), ChallengeModule::SUCCESS);
- BOOST_CHECK_EQUAL(request.getChallengeSecrets().empty(), true);
+ BOOST_CHECK_EQUAL(request.m_challengeStatus, CHALLENGE_STATUS_SUCCESS);
+ BOOST_CHECK_EQUAL(request.m_status, STATUS_PENDING);
+ BOOST_CHECK_EQUAL(request.m_challengeSecrets.empty(), true);
}
BOOST_AUTO_TEST_CASE(OnValidateInterestComingWithWrongCode)
@@ -158,61 +121,20 @@
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- CertificateRequest request(Name("/ndn/site1"), "123", cert);
- request.setChallengeType("EMAIL");
- request.setStatus(ChallengeEmail::NEED_CODE);
-
- time::system_clock::TimePoint tp = time::system_clock::now();
JsonSection json;
- json.put(ChallengeEmail::JSON_CODE_TP, time::toIsoString(tp));
json.put(ChallengeEmail::JSON_CODE, "4567");
- json.put(ChallengeEmail::JSON_ATTEMPT_TIMES, std::to_string(3));
+ CertificateRequest request(Name("/ndn/site1"), "123", STATUS_CHALLENGE, ChallengeEmail::NEED_CODE,
+ "Email", time::toIsoString(time::system_clock::now()), 3600, 3, json, cert);
- request.setChallengeSecrets(json);
-
- JsonSection infoJson;
- infoJson.put(ChallengeEmail::JSON_CODE, "1234");
- std::stringstream ss;
- boost::property_tree::write_json(ss, infoJson);
- Block jsonContent = makeStringBlock(ndn::tlv::GenericNameComponent, ss.str());
-
- Name interestName("/ndn/site1/CA");
- interestName.append("_VALIDATE").append("Fake-Request-ID").append("EMAIL").append(jsonContent);
- Interest interest(interestName);
+ JsonSection requestJson;
+ requestJson.put(ChallengeEmail::JSON_CODE, "7890");
ChallengeEmail challenge;
- challenge.handleChallengeRequest(interest, request);
+ challenge.handleChallengeRequest(requestJson, request);
- BOOST_CHECK_EQUAL(request.getStatus(), ChallengeEmail::WRONG_CODE);
- BOOST_CHECK_EQUAL(request.getChallengeSecrets().empty(), false);
-}
-
-BOOST_AUTO_TEST_CASE(ClientSendSelect)
-{
- ChallengeEmail challenge;
- auto requirementList = challenge.getSelectRequirements();
- BOOST_CHECK_EQUAL(requirementList.size(), 1);
-
- requirementList.clear();
- requirementList.push_back("zhiyi@cs.ucla.edu");
-
- auto json = challenge.genSelectParamsJson(ChallengeModule::WAIT_SELECTION, requirementList);
- BOOST_CHECK_EQUAL(json.empty(), false);
- BOOST_CHECK_EQUAL(json.get<std::string>(ChallengeEmail::JSON_EMAIL), "zhiyi@cs.ucla.edu");
-}
-
-BOOST_AUTO_TEST_CASE(ClientSendValidate)
-{
- ChallengeEmail challenge;
- auto requirementList = challenge.getValidateRequirements(ChallengeEmail::NEED_CODE);
- BOOST_CHECK_EQUAL(requirementList.size(), 1);
-
- requirementList.clear();
- requirementList.push_back("123");
-
- auto json = challenge.genValidateParamsJson(ChallengeEmail::NEED_CODE, requirementList);
- BOOST_CHECK_EQUAL(json.empty(), false);
- BOOST_CHECK_EQUAL(json.get<std::string>(ChallengeEmail::JSON_CODE), "123");
+ BOOST_CHECK_EQUAL(request.m_challengeStatus, ChallengeEmail::WRONG_CODE);
+ BOOST_CHECK_EQUAL(request.m_status, STATUS_CHALLENGE);
+ BOOST_CHECK_EQUAL(request.m_challengeSecrets.empty(), false);
}
BOOST_AUTO_TEST_SUITE_END()