tests: Restore MangementTool tests
Change-Id: I47cce57bdfb0fe18b36bc5b12278e38b575a50fd
diff --git a/tests/unit/mgmt/management-tool.cpp b/tests/unit/mgmt/management-tool.cpp
index 1121356..8f042f2 100644
--- a/tests/unit/mgmt/management-tool.cpp
+++ b/tests/unit/mgmt/management-tool.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -18,6 +18,7 @@
*/
#include "mgmt/management-tool.hpp"
+#include "daemon/rrset-factory.hpp"
#include "ndns-enum.hpp"
#include "ndns-label.hpp"
@@ -36,8 +37,6 @@
namespace ndns {
namespace tests {
-BOOST_AUTO_TEST_SUITE(ManagementTool)
-
static const boost::filesystem::path TEST_DATABASE = TEST_CONFIG_PATH "/management_tool.db";
static const boost::filesystem::path TEST_CERTDIR = TEST_CONFIG_PATH "/management_tool_certs";
static const Name FAKE_ROOT("/fake-root/123456789");
@@ -206,6 +205,8 @@
Name otherDsk;
};
+BOOST_FIXTURE_TEST_SUITE(ManagementTool, ManagementToolFixture)
+
// BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture)
// {
// using time::seconds;
@@ -241,7 +242,7 @@
// std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl;
// }
-BOOST_FIXTURE_TEST_CASE(CreateDeleteRootZone, ManagementToolFixture)
+BOOST_AUTO_TEST_CASE(CreateDeleteRootFixture)
{
m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(4600), time::seconds(4600),
rootKsk, rootDsk);
@@ -255,7 +256,7 @@
BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false);
}
-BOOST_FIXTURE_TEST_CASE(CreateDeleteChildZone, ManagementToolFixture)
+BOOST_AUTO_TEST_CASE(CreateDeleteChildFixture)
{
Name parentZoneName("/ndns-test");
Name zoneName = Name(parentZoneName).append("child-zone");
@@ -284,7 +285,7 @@
BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error);
}
-BOOST_FIXTURE_TEST_CASE(CreateZoneWithTtl, ManagementToolFixture)
+BOOST_AUTO_TEST_CASE(CreateZoneWithFixture)
{
Name parentZoneName("/ndns-test");
Name zoneName = Name(parentZoneName).append("child-zone");
@@ -318,7 +319,7 @@
m_tool.deleteZone(zoneName);
}
-BOOST_FIXTURE_TEST_CASE(ZoneCreatePreconditions, ManagementToolFixture)
+BOOST_AUTO_TEST_CASE(ZoneCreatePreconditions)
{
BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net"));
BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error);
@@ -404,7 +405,7 @@
std::streambuf* savedBuf;
};
-BOOST_FIXTURE_TEST_CASE(ExportCertificate, ManagementToolFixture)
+BOOST_AUTO_TEST_CASE(ExportCertificate)
{
std::string outputFile = TEST_CERTDIR.string() + "/ss.cert";
@@ -476,416 +477,424 @@
BOOST_CHECK_EQUAL(acutalOutput, dskValue);
}
-// BOOST_FIXTURE_TEST_CASE(AddRrSet1, ManagementToolFixture)
-// {
-// // check pre-condition
-// BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_RESP),
-// ndns::ManagementTool::Error);
+BOOST_AUTO_TEST_CASE(AddRrset)
+{
+ Name zoneName("/ndns-test");
+ Zone zone(zoneName);
-// Name zoneName("/ndns-test");
-// Zone zone(zoneName);
-// m_dbMgr.insert(zone);
+ time::seconds ttl1(4200);
+ time::seconds ttl2(4500);
+ m_tool.createZone(zoneName, ROOT_ZONE, ttl1);
-// BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_UNKNOWN),
-// ndns::ManagementTool::Error);
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, "/test", label::CERT_RR_TYPE, NDNS_RAW),
-// ndns::ManagementTool::Error);
-// BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_RAW),
-// ndns::ManagementTool::Error);
-// BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::TXT_RR_TYPE, NDNS_RAW),
-// ndns::ManagementTool::Error);
+ RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
+ rf.checkZoneKey();
+ Rrset rrset1 = rf.generateNsRrset("/l1", label::NS_RR_TYPE, 7654, ttl2, Link::DelegationSet());
-// m_dbMgr.remove(zone);
-// }
+ BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1));
+ Rrset rrset2 = findRrSet(zone, "/l1", label::NS_RR_TYPE);
+ BOOST_CHECK_EQUAL(rrset1, rrset2);
-// BOOST_FIXTURE_TEST_CASE(AddRrSet2, ManagementToolFixture)
-// {
-// Name zoneName("/ndns-test");
-// Zone zone(zoneName);
+ Rrset rrset3 = rf.generateNsRrset("/l1/l2/l3", label::NS_RR_TYPE, 7654, ttl2, Link::DelegationSet());
+ BOOST_CHECK_THROW(m_tool.addRrset(rrset3), ndns::ManagementTool::Error);
+}
-// uint64_t version = 1234;
-// time::seconds ttl1(4200);
-// time::seconds ttl2(4500);
-// m_tool.createZone(zoneName, ROOT_ZONE, ttl1);
+BOOST_AUTO_TEST_CASE(AddMultiLevelLabelRrset)
+{
-// //add NS NDNS_AUTH and check user-defined ttl
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l1", label::NS_RR_TYPE, NDNS_AUTH, 7654,
-// {}, DEFAULT_CERT, ttl2));
-// Response response;
-// BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l1", label::NS_RR_TYPE));
-// BOOST_CHECK_EQUAL(response.getNdnsType(), NDNS_AUTH);
-// BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(7654));
-// BOOST_CHECK_EQUAL(response.getFreshnessPeriod(), ttl2);
+ Name zoneName("/ndns-test");
+ Zone zone(zoneName);
-// // add NS NDNS_RESP and check default ttl
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l2", label::NS_RR_TYPE, NDNS_RESP, 15));
-// BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", label::NS_RR_TYPE));
-// BOOST_CHECK_EQUAL(response.getNdnsType(), NDNS_RESP);
-// BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(15));
-// BOOST_CHECK_EQUAL(response.getFreshnessPeriod(), ttl1);
+ time::seconds ttl(4200);
+ m_tool.createZone(zoneName, ROOT_ZONE, ttl);
-// //add TXT NDNS_RESP and check rr
-// std::string test = "oops";
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l2", label::TXT_RR_TYPE, NDNS_RESP, version,
-// {"oops", "again"}));
-// BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", label::TXT_RR_TYPE));
+ RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
+ rf.checkZoneKey();
-// BOOST_REQUIRE_EQUAL(response.getRrs().size(), 2);
-// {
-// const Block& block = response.getRrs()[0];
-// std::string someString(reinterpret_cast<const char*>(block.value()), block.value_size());
-// BOOST_CHECK_EQUAL("oops", someString);
-// }
+ auto checkRrset = [&zone, &zoneName, this](Name label,
+ name::Component type,
+ NdnsContentType contentType) -> void {
+ Rrset rr1 = findRrSet(zone, label, type);
+ BOOST_CHECK_EQUAL(Data(rr1.getData()).getContentType(), contentType);
+ Response response1;
+ response1.fromData(zoneName, Data(rr1.getData()));
+ BOOST_CHECK_EQUAL(response1.getRrLabel(), label);
+ };
-// {
-// const Block& block = response.getRrs()[1];
-// std::string someString(reinterpret_cast<const char*>(block.value()), block.value_size());
-// BOOST_CHECK_EQUAL("again", someString);
-// }
+ Name labelName("/l1/l2/l3");
-// //add user defined type
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, "/l2", name::Component("USER-DEFINED"), NDNS_RAW,
-// 1112223, {"10.10.0.1", "SECOND_INVALID_DATA"}),
-// ndns::ManagementTool::Error);
+ Rrset rrset1 = rf.generateNsRrset(labelName, label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet());
-// m_tool.addRrSet(zoneName, "/l2", name::Component("USER-DEFINED"), NDNS_RAW, 1112223,
-// {"10.10.0.1"});
-// BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", name::Component("USER-DEFINED")));
-// BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(1112223));
+ //add NS NDNS_AUTH and check user-defined ttl
+ BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(rrset1, rf, ttl));
+ Rrset rrset2 = findRrSet(zone, labelName, label::NS_RR_TYPE);
+ BOOST_CHECK_EQUAL(rrset1, rrset2);
-// std::string actualValue(reinterpret_cast<const char*>(response.getAppContent().value()),
-// response.getAppContent().value_size());
-// BOOST_CHECK_EQUAL(actualValue, "10.10.0.1");
-// }
+ checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH);
+ checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH);
-// BOOST_FIXTURE_TEST_CASE(AddRrSet3, ManagementToolFixture)
-// {
-// // check pre-condition
-// Name zoneName("/ndns-test");
+ // insert a same-name rrset with TXT type
+ Rrset txtRr = rf.generateTxtRrset("/l1/l2/l3", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>());
+ BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(txtRr, rf, ttl));
-// std::string certPath = TEST_CERTDIR.string();
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
+ checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH);
+ checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH);
+ checkRrset("/l1/l2/l3", label::TXT_RR_TYPE, ndns::NDNS_RESP);
+ // check that there is no confliction
+ checkRrset("/l1/l2/l3", label::NS_RR_TYPE, ndns::NDNS_LINK);
-// m_tool.createZone(zoneName, ROOT_ZONE);
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
-// }
+ // insert a shorter NS, when there are longer NS or TXT
+ Rrset shorterNs = rf.generateNsRrset("/l1/l2", label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet());
+ BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(shorterNs, rf, ttl),
+ ndns::ManagementTool::Error);
-// BOOST_FIXTURE_TEST_CASE(AddRrSet4, ManagementToolFixture)
-// {
-// Name parentZoneName("/ndns-test");
-// Name zoneName = Name(parentZoneName).append("/child-zone");
+ // insert a longer NS, when there is already a shorter NS
+ Rrset longerNs = rf.generateNsRrset("/l1/l2/l3/l4", label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet());
+ BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(longerNs, rf, ttl),
+ ndns::ManagementTool::Error);
-// Zone parentZone(parentZoneName);
+ // insert a smaller TXT, when there are longer NS and TXT
+ Rrset shorterTxt = rf.generateTxtRrset("/l1/l2", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>());
+ BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(shorterTxt, rf, ttl));
-// m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
-// m_tool.createZone(zoneName, parentZoneName);
+ // insert a smaller NS, when there is long TXT
+ Rrset longTxt = rf.generateTxtRrset("/k1/k2/k3", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>());
+ Rrset smallerNs = rf.generateNsRrset("/k1/k2", label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet());
+ BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longTxt, rf, ttl));
+ BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(smallerNs, rf, ttl),
+ ndns::ManagementTool::Error);
-// std::vector<Name>&& certs = getCerts(zoneName);
-// BOOST_REQUIRE_EQUAL(certs.size(), 2);
-// std::sort(certs.begin(), certs.end());
+ // inserting a longer TXT, when there is shoter TXT
+ Rrset longerTxt = rf.generateTxtRrset("/k1/k2/k3/k4", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>());
+ BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longerTxt, rf, ttl));
+}
-// Name& ksk = certs[0];
-// // Name& dsk = certs[1];
+BOOST_AUTO_TEST_CASE(AddRrSetDskCertPreConditon)
+{
+ // check pre-condition
+ Name zoneName("/ndns-test");
-// std::string output = TEST_CERTDIR.string() + "/ss.cert";
-// m_tool.exportCertificate(ksk, output);
+ // Check: throw if zone not exist
+ std::string certPath = TEST_CERTDIR.string();
+ BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
-// BOOST_CHECK_NO_THROW(findIdCert(parentZone, ksk));
+ m_tool.createZone(zoneName, ROOT_ZONE);
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, "/child-zone",
-// label::NS_RR_TYPE, NDNS_RESP));
-// BOOST_CHECK_NO_THROW(findRrSet(parentZone, "/child-zone", label::NS_RR_TYPE));
+ // Check: throw if certificate does not match
+ BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
-// //add KSK ID-CERT with illegal name and convert it
-// Name iZoneName = Name(parentZoneName).append("illegal");
-// Name illegalCertName = m_keyChain.createIdentity(iZoneName);
-// m_tool.exportCertificate(illegalCertName, output);
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
+ std::string rightCertPath = TEST_CERTDIR.string() + "/ss.cert";
+ m_tool.exportCertificate(otherKsk, rightCertPath);
-// Name legalCertName =
-// Name(parentZoneName)
-// .append("KEY")
-// .append("illegal")
-// .append(illegalCertName.getSubName(3));
-// BOOST_CHECK_NO_THROW(findIdCert(parentZone, legalCertName));
-// }
+ BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, rightCertPath));
+}
-// BOOST_FIXTURE_TEST_CASE(AddRrSet5, ManagementToolFixture)
-// {
-// //check using user provided certificate
-// Name parentZoneName("/ndns-test");
-// Name zoneName = Name(parentZoneName).append("child-zone");
+BOOST_AUTO_TEST_CASE(AddRrSetDskCert)
+{
+ Name parentZoneName("/ndns-test");
+ Name zoneName("/ndns-test/child-zone");
-// Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false);
-// shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
-// m_keyChain.addCertificateAsKeyDefault(*dskCert);
+ Zone parentZone(parentZoneName);
-// // check addRrSet1
-// m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
-// m_tool.createZone(zoneName, parentZoneName);
+ m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
+ m_tool.createZone(zoneName, parentZoneName);
-// std::vector<Name>&& certs = getCerts(zoneName);
-// BOOST_REQUIRE_EQUAL(certs.size(), 2);
-// std::sort(certs.begin(), certs.end());
+ std::vector<Name>&& certs = getCerts(zoneName);
+ BOOST_REQUIRE_EQUAL(certs.size(), 2);
+ std::sort(certs.begin(), certs.end());
-// Name& ksk = certs[0];
-// // Name& dsk = certs[1];
+ Name& ksk = certs[0];
-// std::string output = TEST_CERTDIR.string() + "/ss.cert";
-// m_tool.exportCertificate(ksk, output);
+ std::string output = TEST_CERTDIR.string() + "/ss.cert";
+ m_tool.exportCertificate(ksk, output);
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output, time::seconds(4600),
-// dskCert->getName()));
+ BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
+ BOOST_CHECK_NO_THROW(findIdCert(parentZone, ksk));
-// // check addRrSet2
-// Name label1("/net/ndnsim1");
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, "/l1", label::NS_RR_TYPE, NDNS_AUTH, -1, {},
-// dskCert->getName()));
-// }
+ // Add KSK ID-CERT with illegal name and convert it
+ Name iZoneName = Name(parentZoneName).append("illegal");
+ Name illegalCertName = m_keyChain.createIdentity(iZoneName);
+ m_tool.exportCertificate(illegalCertName, output);
+ BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
-// BOOST_FIXTURE_TEST_CASE(AddRrSet6, ManagementToolFixture)
-// {
-// //check invalid output
-// Name parentZoneName("/ndns-test");
-// Name zoneName = Name(parentZoneName).append("child-zone");
-// m_tool.createZone(zoneName, parentZoneName);
+ Name legalCertName = Name(parentZoneName).append("KEY")
+ .append("illegal")
+ .append(illegalCertName.getSubName(3));
+ BOOST_CHECK_NO_THROW(findIdCert(parentZone, legalCertName));
+}
-// Name content = "invalid data packet";
-// std::string output = TEST_CERTDIR.string() + "/ss.cert";
-// ndn::io::save(content, output);
+BOOST_AUTO_TEST_CASE(AddRrSetDskCertUserProvidedCert)
+{
+ //check using user provided certificate
+ Name parentZoneName("/ndns-test");
+ Name zoneName("/ndns-test/child-zone");
+
+ Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false);
+ shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
+ m_keyChain.addCertificateAsKeyDefault(*dskCert);
+
+ // check addRrSet1
+ m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
+ m_tool.createZone(zoneName, parentZoneName);
+
+ std::vector<Name>&& certs = getCerts(zoneName);
+ BOOST_REQUIRE_EQUAL(certs.size(), 2);
+ std::sort(certs.begin(), certs.end());
+
+ Name& ksk = certs[0];
+ // Name& dsk = certs[1];
+
+ std::string output = TEST_CERTDIR.string() + "/ss.cert";
+ m_tool.exportCertificate(ksk, output);
+
+ BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output, time::seconds(4600),
+ dskCert->getName()));
+}
+
+BOOST_AUTO_TEST_CASE(AddRrSetDskCertInvalidOutput)
+{
+ //check invalid output
+ Name parentZoneName("/ndns-test");
+ Name zoneName = Name(parentZoneName).append("child-zone");
+ m_tool.createZone(zoneName, parentZoneName);
+
+ Name content = "invalid data packet";
+ std::string output = TEST_CERTDIR.string() + "/ss.cert";
+ ndn::io::save(content, output);
+
+ BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, output), ndns::ManagementTool::Error);
+}
+
+BOOST_AUTO_TEST_CASE(AddRrSetVersionControl)
+{
+ //check version control
+ time::seconds ttl(4200);
+ Name parentZoneName("/ndns-test");
+ Name zoneName = Name(parentZoneName).append("child-zone");
+ m_tool.createZone(zoneName, parentZoneName);
+
+ Name label("/label");
+ uint64_t version = 110;
+
+ RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
+ rf.checkZoneKey();
+
+ Rrset rrset1 = rf.generateTxtRrset(label, label::NS_RR_TYPE, version, ttl, {});
+
+ m_tool.addRrset(rrset1);
+ // throw error when adding duplicated rrset with the same version
+ BOOST_CHECK_THROW(m_tool.addRrset(rrset1),
+ ndns::ManagementTool::Error);
+ version--;
+ Rrset rrset2 = rf.generateTxtRrset(label, label::NS_RR_TYPE, version, ttl, {});
+ // throw error when adding duplicated rrset with older version
+ BOOST_CHECK_THROW(m_tool.addRrset(rrset2),
+ ndns::ManagementTool::Error);
+
+ version++;
+ version++;
+ Rrset rrset3 = rf.generateTxtRrset(label, label::NS_RR_TYPE, version, ttl, {});
+ BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset3));
+
+ Zone zone(zoneName);
+ m_dbMgr.find(zone);
+ Rrset rrset;
+ rrset.setZone(&zone);
+ rrset.setLabel(label);
+ rrset.setType(label::NS_RR_TYPE);
+ m_dbMgr.find(rrset);
+
+ BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version));
+}
+
+BOOST_AUTO_TEST_CASE(AddRrSetDskCertFormat)
+{
+ //check input with different formats
+ Name parentZoneName("/ndns-test");
+ Name zoneName = Name(parentZoneName).append("child-zone");
+ m_tool.createZone(zoneName, parentZoneName);
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, output), ndns::ManagementTool::Error);
-// }
+ std::string output = TEST_CERTDIR.string() + "/a.cert";
-// BOOST_FIXTURE_TEST_CASE(AddRrSet7, ManagementToolFixture)
-// {
-// //check version control
-// Name parentZoneName("/ndns-test");
-// Name zoneName = Name(parentZoneName).append("child-zone");
-// m_tool.createZone(zoneName, parentZoneName);
+ // base64
+ Name dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
+ shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
-// Name label("/label");
-// uint64_t version = 110;
+ ndn::io::save(*dskCert, output, ndn::io::BASE64);
+ BOOST_CHECK_NO_THROW(
+ m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64));
-// m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version);
-// // throw error when adding duplicated rrset with the same version
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version),
-// ndns::ManagementTool::Error);
-// version--;
-// // throw error when adding duplicated rrset with older version
-// BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version),
-// ndns::ManagementTool::Error);
+ // raw
+ dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
+ dskCert = m_keyChain.selfSign(dskName);
-// version++;
-// version++;
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version));
+ ndn::io::save(*dskCert, output, ndn::io::NO_ENCODING);
+ BOOST_CHECK_NO_THROW(
+ m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING));
-// Zone zone(zoneName);
-// m_dbMgr.find(zone);
-// Rrset rrset;
-// rrset.setZone(&zone);
-// rrset.setLabel(label);
-// rrset.setType(label::NS_RR_TYPE);
-// m_dbMgr.find(rrset);
+ // hex
+ dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
+ dskCert = m_keyChain.selfSign(dskName);
-// BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version));
-// }
+ ndn::io::save(*dskCert, output, ndn::io::HEX);
+ BOOST_CHECK_NO_THROW(
+ m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX));
-// BOOST_FIXTURE_TEST_CASE(AddRrSet8, ManagementToolFixture)
-// {
-// //check input with different formats
-// Name parentZoneName("/ndns-test");
-// Name zoneName = Name(parentZoneName).append("child-zone");
-// m_tool.createZone(zoneName, parentZoneName);
+ // incorrect encoding input
+ dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
+ dskCert = m_keyChain.selfSign(dskName);
-// std::string output = TEST_CERTDIR.string() + "/a.cert";
+ ndn::io::save(*dskCert, output, ndn::io::HEX);
+ BOOST_CHECK_THROW(
+ m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT,
+ static_cast<ndn::io::IoEncoding>(127)),
+ ndns::ManagementTool::Error);
+}
-// // base64
-// Name dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
-// shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
+BOOST_AUTO_TEST_CASE(ListAllZones)
+{
+ m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk);
+ m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
-// ndn::io::save(*dskCert, output, ndn::io::BASE64);
-// BOOST_CHECK_NO_THROW(
-// m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64));
+ std::string expectedValue =
+ "/ ; default-ttl=1 default-key=/dsk-1416974006466 "
+ "default-certificate=/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28\n"
+ "/ndns-test ; default-ttl=10 default-key=/ndns-test/dsk-1416974006659 "
+ "default-certificate=/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n";
-// // raw
-// dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
-// dskCert = m_keyChain.selfSign(dskName);
+ output_test_stream testOutput;
+ m_tool.listAllZones(testOutput);
+ BOOST_CHECK(testOutput.is_equal(expectedValue));
+}
-// ndn::io::save(*dskCert, output, ndn::io::NO_ENCODING);
-// BOOST_CHECK_NO_THROW(
-// m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING));
+BOOST_AUTO_TEST_CASE(ListZone)
+{
+ m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
-// // hex
-// dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
-// dskCert = m_keyChain.selfSign(dskName);
+ RrsetFactory rf(TEST_DATABASE, "/ndns-test", m_keyChain, DEFAULT_CERT);
+ rf.checkZoneKey();
-// ndn::io::save(*dskCert, output, ndn::io::HEX);
-// BOOST_CHECK_NO_THROW(
-// m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX));
+ // Add NS with NDNS_RESP
-// // incorrect encoding input
-// dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
-// dskCert = m_keyChain.selfSign(dskName);
+ Link::DelegationSet ds = {std::pair<uint32_t, Name>(10,"/get/link")};
+ Rrset rrset1 = rf.generateNsRrset("/label1", label::NS_RR_TYPE, 100, DEFAULT_RR_TTL, ds);
+ m_tool.addRrset(rrset1);
-// ndn::io::save(*dskCert, output, ndn::io::HEX);
-// BOOST_CHECK_THROW(
-// m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT,
-// static_cast<ndn::io::IoEncoding>(127)),
-// ndns::ManagementTool::Error);
-// }
+ // Add NS with NDNS_AUTH
+ Rrset rrset2 = rf.generateAuthRrset("/label2", label::NS_RR_TYPE, 100000, DEFAULT_RR_TTL);
+ m_tool.addRrset(rrset2);
-// BOOST_FIXTURE_TEST_CASE(ListAllZones, ManagementToolFixture)
-// {
-// m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk);
-// m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
+ // Add TXT from file
+ std::string output = TEST_CERTDIR.string() + "/a.rrset";
+ Response re1;
+ re1.setZone("/ndns-test");
+ re1.setQueryType(label::NDNS_ITERATIVE_QUERY);
+ re1.setRrLabel("/label2");
+ re1.setRrType(label::TXT_RR_TYPE);
+ re1.setContentType(NDNS_RESP);
+ re1.setVersion(name::Component::fromVersion(654321));
+ re1.addRr("First RR");
+ re1.addRr("Second RR");
+ re1.addRr("Last RR");
+ shared_ptr<Data> data1 = re1.toData();
+ m_keyChain.sign(*data1, otherDsk);
+ ndn::io::save(*data1, output);
+ m_tool.addRrSet("/ndns-test", output);
-// std::string expectedValue =
-// "/ ; default-ttl=1 default-key=/dsk-1416974006466 "
-// "default-certificate=/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28\n"
-// "/ndns-test ; default-ttl=10 default-key=/ndns-test/dsk-1416974006659 "
-// "default-certificate=/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n";
+ // Add TXT in normal way
+ Rrset rrset3 = rf.generateTxtRrset("/label3", label::TXT_RR_TYPE, 3333, DEFAULT_RR_TTL, {"Hello", "World"});
+ m_tool.addRrset(rrset3);
-// output_test_stream testOutput;
-// m_tool.listAllZones(testOutput);
-// BOOST_CHECK(testOutput.is_equal(expectedValue));
-// }
+ output_test_stream testOutput;
+ m_tool.listZone("/ndns-test", testOutput, true);
-// BOOST_FIXTURE_TEST_CASE(ListZone, ManagementToolFixture)
-// {
-// m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
+ std::string expectedValue =
+ R"VALUE(; Zone /ndns-test
-// // Add NS with NDNS_RESP
-// m_tool.addRrSet("/ndns-test", "/label1", label::NS_RR_TYPE, NDNS_RESP, 100);
+; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT
+/label1 10 NS 10,/get/link;
-// // Add NS with NDNS_AUTH
-// m_tool.addRrSet("/ndns-test", "/label2", label::NS_RR_TYPE, NDNS_AUTH, 100000);
+; rrset=/label2 type=NS version=%FD%00%01%86%A0 signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT
+/label2 10 NS NDNS-Auth
-// // Add TXT from file
-// std::string output = TEST_CERTDIR.string() + "/a.rrset";
-// Response re1;
-// re1.setZone("/ndns-test");
-// re1.setQueryType(label::NDNS_ITERATIVE_QUERY);
-// re1.setRrLabel("/label2");
-// re1.setRrType(label::TXT_RR_TYPE);
-// re1.setNdnsType(NDNS_RESP);
-// re1.setVersion(name::Component::fromVersion(654321));
-// re1.addRr("First RR");
-// re1.addRr("Second RR");
-// re1.addRr("Last RR");
-// shared_ptr<Data> data1 = re1.toData();
-// m_keyChain.sign(*data1, otherDsk);
-// ndn::io::save(*data1, output);
-// m_tool.addRrSet("/ndns-test", output);
+; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT
+/label2 10 TXT First RR
+/label2 10 TXT Second RR
+/label2 10 TXT Last RR
-// // Add TXT in normal way
-// m_tool.addRrSet("/ndns-test", "/label3", label::TXT_RR_TYPE, NDNS_RESP, 3333,
-// {"Hello", "World"}, otherDsk);
+; rrset=/label3 type=TXT version=%FD%0D%05 signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT
+/label3 10 TXT Hello
+/label3 10 TXT World
-// // Add User-Defined
-// Response re2;
-// re2.setZone("/ndns-test");
-// re2.setQueryType(label::NDNS_ITERATIVE_QUERY);
-// re2.setRrLabel("/label4");
-// re2.setRrType(name::Component("USER-DEFINED"));
-// re2.setNdnsType(NDNS_RAW);
-// re2.setVersion(name::Component::fromVersion(1234567));
-// re2.setAppContent(makeBinaryBlock(ndn::tlv::Content, "Hello", sizeof("Hello")));
-// shared_ptr<Data> data2 = re2.toData();
-// m_keyChain.sign(*data2, otherDsk);
-// ndn::io::save(*data2, output);
-// m_tool.addRrSet("/ndns-test", output);
+/dsk-1416974006659 10 ID-CERT ; content-type=KEY version=%FD%00%00%01I%EA%3Bz%0E signed-by=/ndns-test/KEY/ksk-1416974006577/ID-CERT
+; Certificate name:
+; /ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E
+; Validity:
+; NotBefore: 19700101T000000
+; NotAfter: 20380119T031408
+; Subject Description:
+; 2.5.4.41: /ndns-test
+; Public key bits: (RSA)
+; MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAyBVC+xc/JpscSE/JdxbV
+; pvgrh/fokNFI/2t9D5inuIFr7cc4W+LyJ4GG1xr9olMx7MHamJU1Xg3VunjhSjL8
+; mOaeXlbS6gxWexBCtNK6U4euPB4wks/gMIKdp24mAAFb4T+mBfjcRgR+NdrjyO5C
+; 2OqM8qbDZmD/iuEmE6GPXnuMS0o6s13yzMj9YfDh3Df2jZnHESZcmG5Qpgg22T58
+; 7t7bRx8Ha2EC3hb29AeYKwgEKDx8JH8ZBJ80AQP321HbyjXWshJLomzy5SJZo9nA
+; bZOYlZPCQkomz92Zc9+kpLNQwDvtRLwkZ46B+b2JpKTFARbnvugONCEBuG6zNgoi
+; EQIB
+; Signature Information:
+; Signature Type: Unknown Signature Type
-// output_test_stream testOutput;
-// m_tool.listZone("/ndns-test", testOutput, true);
+)VALUE";
-// std::string expectedValue =
-// "; Zone /ndns-test\n"
-// "\n"
-// "; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
-// "/label1 10 NS \n"
-// "\n"
-// "/label2 10 NS ; content-type=NDNS-Auth version=%FD%00%01%86%A0 "
-// "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
-// "\n"
-// "; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 "
-// "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
-// "/label2 10 TXT First RR\n"
-// "/label2 10 TXT Second RR\n"
-// "/label2 10 TXT Last RR\n"
-// "\n"
-// "; rrset=/label3 type=TXT version=%FD%0D%05 "
-// "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
-// "/label3 10 TXT Hello\n"
-// "/label3 10 TXT World\n"
-// "\n"
-// "/label4 10 USER-DEFINED ; content-type=NDNS-Raw version=%FD%00%12%D6%87 "
-// "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
-// "; FQZIZWxsbwA=\n"
-// "\n"
-// "/dsk-1416974006659 10 ID-CERT ; content-type=NDNS-Raw version=%FD%00%00%01I%EA%3Bz%0E "
-// "signed-by=/ndns-test/KEY/ksk-1416974006577/ID-CERT\n"
-// "; Certificate name:\n"
-// "; /ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n"
-// "; Validity:\n"
-// "; NotBefore: 19700101T000000\n"
-// "; NotAfter: 20380119T031408\n"
-// "; Subject Description:\n"
-// "; 2.5.4.41: /ndns-test\n"
-// "; Public key bits: (RSA)\n"
-// "; MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAyBVC+xc/JpscSE/JdxbV\n"
-// "; pvgrh/fokNFI/2t9D5inuIFr7cc4W+LyJ4GG1xr9olMx7MHamJU1Xg3VunjhSjL8\n"
-// "; mOaeXlbS6gxWexBCtNK6U4euPB4wks/gMIKdp24mAAFb4T+mBfjcRgR+NdrjyO5C\n"
-// "; 2OqM8qbDZmD/iuEmE6GPXnuMS0o6s13yzMj9YfDh3Df2jZnHESZcmG5Qpgg22T58\n"
-// "; 7t7bRx8Ha2EC3hb29AeYKwgEKDx8JH8ZBJ80AQP321HbyjXWshJLomzy5SJZo9nA\n"
-// "; bZOYlZPCQkomz92Zc9+kpLNQwDvtRLwkZ46B+b2JpKTFARbnvugONCEBuG6zNgoi\n"
-// "; EQIB\n"
-// "; Signature Information:\n"
-// "; Signature Type: Unknown Signature Type\n"
-// "\n";
+ BOOST_CHECK(testOutput.is_equal(expectedValue));
+}
-// BOOST_CHECK(testOutput.is_equal(expectedValue));
-// }
+BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture)
+{
+ Name zoneName("/ndns-test");
+ m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
+ RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
+ rf.checkZoneKey();
+ Rrset rrset1 = rf.generateTxtRrset("/label", label::TXT_RR_TYPE, 100, DEFAULT_RR_TTL, {"Value1", "Value2"});
-// BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture)
-// {
-// Name zoneName("/ndns-test");
-// m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
+ m_tool.addRrset(rrset1);
-// m_tool.addRrSet(zoneName, "/label", name::Component("TXT"), NDNS_RESP, 100,
-// {"Value1", "Value2"});
+ std::string expectedValue =
+ R"VALUE(Bv0BeAchCAluZG5zLXRlc3QIBE5ETlMIBWxhYmVsCANUWFQIAv1kFAgYAgQ/GQID
+6BUQvwZWYWx1ZTG/BlZhbHVlMhYzGwEBHC4HLAgJbmRucy10ZXN0CANLRVkIEWRz
+ay0xNDE2OTc0MDA2NjU5CAdJRC1DRVJUF/0BAL7Phidi+mM5cWM6alaV38qpEd+D
+kV1bHEO1BT7jsjfxW8INS7OJVUbr5ducBDTjzCp9dYjKncKv0f3hcZIX7fl9/msL
+6FuCKqrYgEZIgSD3q6DFzh04FUjrMJvqZp1D3LBh1yIKARA9TI0C6TKrlOT40iuY
+wvifmpSna7gOuh1k+qvKvx+/Y6csCw9WVLxnW12/AJdlfv3PPPnDlKkN7DozUV+s
+c7Jf+hhhZDntij+fMYBVgk0Ub/udOJrznlcZKW6C7YK57wq806kO3430gLQBEkGC
+NuOojYCk2k4Skp830cvIdy1Ld5lY1qrBZOIKR38KIy8jchP9+MEB88jvXrY=
+)VALUE";
-// std::string expectedValue =
-// "Bv0BdwchCAluZG5zLXRlc3QIBE5ETlMIBWxhYmVsCANUWFQIAv1kFAcZAgPotAEB\n"
-// "FRC/BlZhbHVlMb8GVmFsdWUyFjMbAQEcLgcsCAluZG5zLXRlc3QIA0tFWQgRZHNr\n"
-// "LTE0MTY5NzQwMDY2NTkIB0lELUNFUlQX/QEAqhzoQmGGeFcUlZ9pEp0ohVoTEw18\n"
-// "qfB1DN6sssOpjCu3V41SHmoybPPkdW84i/h5n6TmuuePWva+fk6l9Xppd3F4lCX0\n"
-// "Tb1lyxjnLaQjBKTYxNReM3h55XY7sCvb2RpFCSDZ/PFfzuCwdWAIqcau10H9IjNm\n"
-// "2NO+m+jW43tnou9TLrNzN80bYFQc4FEwUCJUA4jPf+1NwDUMp9LWN5IILwU+Ttx6\n"
-// "45u2rK6KXfgcHR3zifwi2IZ9mEjr5bhXxvL8zP+tgaPb0t6O9gujry0an2h+hUH5\n"
-// "Aldt49RIyipHXO7R2736ZqkUZ553DSIUhaYPuXRlByNbiW6Za+LMPgJaPg==\n";
+ output_test_stream testOutput;
+ m_tool.getRrSet(zoneName, "/label",label::TXT_RR_TYPE, testOutput);
+ BOOST_CHECK(testOutput.check_length(expectedValue.length(), false));
+ BOOST_CHECK(testOutput.is_equal(expectedValue));
+}
-// output_test_stream testOutput;
-// m_tool.getRrSet(zoneName, "/label", name::Component("TXT"), testOutput);
-// BOOST_CHECK(testOutput.is_equal(expectedValue));
-// }
+BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture)
+{
+ Name zoneName("/ndns-test");
-// BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture)
-// {
-// Name zoneName("/ndns-test");
+ m_tool.createZone(zoneName, ROOT_ZONE);
+ RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
+ rf.checkZoneKey();
-// m_tool.createZone(zoneName, ROOT_ZONE);
+ Rrset rrset1 = rf.generateTxtRrset("/label", label::NS_RR_TYPE, 100, DEFAULT_RR_TTL, {});
-// BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/label", label::NS_RR_TYPE, NDNS_RESP));
+ BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1));
-// Zone zone(zoneName);
-// BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE));
+ Zone zone(zoneName);
+ BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE));
-// BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE));
+ BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE));
-// BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error);
-// }
+ BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error);
+}
BOOST_AUTO_TEST_SUITE_END()