blob: db2eaa0bf79ade823367ed3ab8473a7d6662c76f [file] [log] [blame]
Jiewen Tan870b29b2014-11-17 19:09:49 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Junxiao Shi81e98762022-01-11 18:17:24 +00003 * Copyright (c) 2014-2022, Regents of the University of California.
Jiewen Tan870b29b2014-11-17 19:09:49 -08004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080020#include "mgmt/management-tool.hpp"
Davide Pesavento948c50c2020-12-26 21:30:45 -050021
Yumin Xia9d110ce2016-11-15 14:03:14 -080022#include "daemon/rrset-factory.hpp"
Yumin Xia2c509c22017-02-09 14:37:36 -080023#include "util/cert-helper.hpp"
Jiewen Tan870b29b2014-11-17 19:09:49 -080024#include "ndns-enum.hpp"
25#include "ndns-label.hpp"
26#include "ndns-tlv.hpp"
Davide Pesaventobdd88c12020-11-26 00:35:08 -050027
28#include "boost-test.hpp"
29#include "key-chain-fixture.hpp"
Jiewen Tan870b29b2014-11-17 19:09:49 -080030
Jiewen Tan870b29b2014-11-17 19:09:49 -080031#include <boost/algorithm/string/replace.hpp>
Yumin Xia55a7cc42017-05-14 18:43:34 -070032#include <boost/range/adaptors.hpp>
Davide Pesavento28229df2020-01-04 15:11:25 -050033#include <boost/test/tools/output_test_stream.hpp>
Jiewen Tan870b29b2014-11-17 19:09:49 -080034
Davide Pesavento28229df2020-01-04 15:11:25 -050035#include <ndn-cxx/security/transform.hpp>
Jiewen Tan870b29b2014-11-17 19:09:49 -080036#include <ndn-cxx/util/io.hpp>
Davide Pesavento948c50c2020-12-26 21:30:45 -050037#include <ndn-cxx/util/random.hpp>
Jiewen Tan870b29b2014-11-17 19:09:49 -080038#include <ndn-cxx/util/regex.hpp>
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080039
Davide Pesavento948c50c2020-12-26 21:30:45 -050040#include <iostream>
41
Jiewen Tan870b29b2014-11-17 19:09:49 -080042namespace ndn {
43namespace ndns {
44namespace tests {
45
Davide Pesaventobdd88c12020-11-26 00:35:08 -050046using boost::test_tools::output_test_stream;
47
48const auto TEST_DATABASE = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "management_tool.db";
49const auto TEST_CERTDIR = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "management_tool_certs";
50const Name FAKE_ROOT("/fake-root/123456789");
Jiewen Tan870b29b2014-11-17 19:09:49 -080051
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080052/**
53 * @brief Recursive copy a directory using Boost Filesystem
54 *
55 * Based on from http://stackoverflow.com/q/8593608/2150331
56 */
Davide Pesaventobdd88c12020-11-26 00:35:08 -050057static void
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080058copyDir(const boost::filesystem::path& source, const boost::filesystem::path& destination)
59{
60 namespace fs = boost::filesystem;
61
62 fs::create_directory(destination);
63 for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file) {
64 fs::path current(file->path());
65 if (is_directory(current)) {
66 copyDir(current, destination / current.filename());
67 }
68 else {
Eric Newberry9edaf262018-06-07 23:44:57 -070069 copy_file(current, destination / current.filename());
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080070 }
71 }
72}
73
74class TestHome : boost::noncopyable
Jiewen Tan870b29b2014-11-17 19:09:49 -080075{
76public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080077 TestHome()
78 {
79 if (std::getenv("HOME"))
80 m_origHome = std::getenv("HOME");
81
Davide Pesaventobdd88c12020-11-26 00:35:08 -050082 auto p = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "tests" / "unit" / "mgmt";
83 setenv("HOME", p.c_str(), 1);
84 boost::filesystem::remove_all(p);
85 boost::filesystem::create_directories(p);
86 copyDir("tests/unit/mgmt/.ndn", p / ".ndn");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080087 }
88
89 ~TestHome()
90 {
91 if (!m_origHome.empty())
Davide Pesaventobdd88c12020-11-26 00:35:08 -050092 setenv("HOME", m_origHome.data(), 1);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080093 else
94 unsetenv("HOME");
95 }
96
97protected:
98 std::string m_origHome;
99};
100
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500101class ManagementToolFixture : public TestHome, public KeyChainFixture
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800102{
103public:
104 class Error : public std::runtime_error
105 {
106 public:
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500107 using std::runtime_error::runtime_error;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800108 };
109
110 class PreviousStateCleaner
111 {
112 public:
113 PreviousStateCleaner()
114 {
115 boost::filesystem::remove(TEST_DATABASE);
116 boost::filesystem::remove_all(TEST_CERTDIR);
117 }
118 };
119
Jiewen Tan870b29b2014-11-17 19:09:49 -0800120 ManagementToolFixture()
Alexander Afanasyevfde570c2016-12-19 16:02:55 -0800121 : m_tool(TEST_DATABASE.string().c_str(), m_keyChain)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800122 , m_dbMgr(TEST_DATABASE.string().c_str())
123 {
124 boost::filesystem::create_directory(TEST_CERTDIR);
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500125 Identity root = m_keyChain.createIdentity("NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800126 Key ksk = root.getDefaultKey();
127 m_keyChain.deleteCertificate(ksk, ksk.getDefaultCertificate().getName());
128 Certificate kskCert = CertHelper::createCertificate(m_keyChain, ksk, ksk, "CERT");
129 m_keyChain.addCertificate(ksk, kskCert);
130 rootKsk = kskCert.getName();
131
132 Key dsk = m_keyChain.createKey(root);
133 // replace rootDsk's default cert with ksk-signing cert
134 m_keyChain.deleteCertificate(dsk, dsk.getDefaultCertificate().getName());
135 Certificate dskCert = CertHelper::createCertificate(m_keyChain, dsk, ksk, "CERT");
136 m_keyChain.addCertificate(dsk, dskCert);
137 rootDsk = dskCert.getName();
138
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500139 Identity other = m_keyChain.createIdentity("/ndns-test/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800140 Key otherKskKey = other.getDefaultKey();
141 m_keyChain.deleteCertificate(otherKskKey, otherKskKey.getDefaultCertificate().getName());
142 Certificate otherKskCert = CertHelper::createCertificate(m_keyChain, otherKskKey, otherKskKey, "CERT");
143 m_keyChain.addCertificate(otherKskKey, otherKskCert);
144 otherKsk = otherKskCert.getName();
145
146 // replace rootDsk's default cert with ksk-signing cert
147 Key otherDskKey = m_keyChain.createKey(other);
148 m_keyChain.deleteCertificate(otherDskKey, otherDskKey.getDefaultCertificate().getName());
149 Certificate otherDskCert = CertHelper::createCertificate(m_keyChain, otherDskKey, otherKskKey, "CERT");
150 m_keyChain.addCertificate(otherDskKey, otherDskCert);
151 otherDsk = otherDskCert.getName();
152
153 Certificate rootDkeyCert = CertHelper::createCertificate(m_keyChain, otherDskKey, otherKskKey, "CERT");
154 m_keyChain.addCertificate(otherDskKey, rootDkeyCert);
155 rootDkey = rootDkeyCert.getName();
Jiewen Tan870b29b2014-11-17 19:09:49 -0800156 }
157
Yumin Xia2c509c22017-02-09 14:37:36 -0800158 std::vector<Certificate>
159 getCerts(const Name& zoneName)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800160 {
Yumin Xia2c509c22017-02-09 14:37:36 -0800161 Zone zone(zoneName);
162 std::vector<Certificate> certs;
163 std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone);
164 // ksk are always the first key
165 certs.push_back(Certificate(zoneInfo["ksk"]));
166 certs.push_back(Certificate(zoneInfo["dsk"]));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800167 return certs;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800168 }
169
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800170 Rrset
171 findRrSet(Zone& zone, const Name& label, const name::Component& type)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800172 {
173 Rrset rrset(&zone);
174 rrset.setLabel(label);
175 rrset.setType(type);
176
177 if (!m_dbMgr.find(rrset))
Davide Pesavento948c50c2020-12-26 21:30:45 -0500178 NDN_THROW(Error("Record not found"));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800179 else
180 return rrset;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800181 }
182
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800183 Name
184 getLabel(const Zone& zone, const Name& fullName)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800185 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800186 size_t zoneNameSize = zone.getName().size();
187 return fullName.getSubName(zoneNameSize + 1, fullName.size() - zoneNameSize - 3);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800188 }
189
Yumin Xia2c509c22017-02-09 14:37:36 -0800190 Certificate
191 findCertFromIdentity(const Name& identityName, const Name& certName)
192 {
193 Certificate rtn;
194 Identity identity = CertHelper::getIdentity(m_keyChain, identityName);
195 for (const auto& key : identity.getKeys()) {
196 for (const auto& cert : key.getCertificates()) {
197 if (cert.getName() == certName) {
198 rtn = cert;
199 return rtn;
200 }
201 }
202 }
Davide Pesavento948c50c2020-12-26 21:30:45 -0500203 NDN_THROW(Error("Certificate not found in keyChain"));
Yumin Xia2c509c22017-02-09 14:37:36 -0800204 return rtn;
205 }
206
207 Certificate
208 findCertFromDb(Zone& zone, const Name& fullName)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800209 {
210 Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE);
Yumin Xia2c509c22017-02-09 14:37:36 -0800211 Certificate cert;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800212 cert.wireDecode(rrset.getData());
213 return cert;
214 }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800215
Yumin Xia2c509c22017-02-09 14:37:36 -0800216 Certificate
217 findDkeyFromDb(const Name& zoneName)
218 {
219 Zone zone(zoneName);
220 std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone);
221 return Certificate(zoneInfo["dkey"]);
222 }
223
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800224 Response
225 findResponse(Zone& zone, const Name& label, const name::Component& type)
226 {
227 Rrset rrset = findRrSet(zone, label, type);
228 Data data(rrset.getData());
229 Response resp;
Yumin Xia6343c5b2016-10-20 15:45:50 -0700230 resp.fromData(zone.getName(), data);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800231 return resp;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800232 }
233
234public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800235 PreviousStateCleaner cleaner; // must be first variable
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800236 ndns::ManagementTool m_tool;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800237 ndns::DbMgr m_dbMgr;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800238
239 // Names of pre-created certificates
240 // Uncomment and run InitPreconfiguredKeys test case and then update names in the
241 // constructor.
242 Name rootKsk;
243 Name rootDsk;
244 Name otherKsk;
245 Name otherDsk;
Yumin Xia2c509c22017-02-09 14:37:36 -0800246 Name rootDkey;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800247};
248
Yumin Xia9d110ce2016-11-15 14:03:14 -0800249BOOST_FIXTURE_TEST_SUITE(ManagementTool, ManagementToolFixture)
250
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800251// BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture)
252// {
253// using time::seconds;
254
255// auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name {
256// // to re-generate certificates, uncomment and then update rootKsk/rootDsk names
257// Name kskName = m_keyChain.generateRsaKeyPair(zone, true);
258// auto kskCert = m_keyChain
259// .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)),
260// time::fromUnixTimestamp(seconds(2147483648)), {});
261// if (parentCert.empty()) {
262// m_keyChain.selfSign(*kskCert);
263// }
264// else {
265// m_keyChain.sign(*kskCert, parentCert);
266// }
267// m_keyChain.addCertificate(*kskCert);
268
269// Name dskName = m_keyChain.generateRsaKeyPair(zone, false);
270// auto dskCert = m_keyChain
271// .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)),
272// time::fromUnixTimestamp(seconds(2147483648)), {});
273// m_keyChain.sign(*dskCert, kskCert->getName());
274// m_keyChain.addCertificate(*dskCert);
275
276// return dskCert->getName();
277// };
278
279// Name rootDsk = generateCerts(ROOT_ZONE);
280// generateCerts("/ndns-test", rootDsk);
281
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500282// copyDir(UNIT_TESTS_TMPDIR "/tests/unit/mgmt/.ndn", "/tmp/.ndn");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800283// std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl;
284// }
285
Yumin Xia55a7cc42017-05-14 18:43:34 -0700286BOOST_AUTO_TEST_CASE(SqliteLabelOrder)
287{
288 // the correctness of our DoE design rely on the ordering of SQLite
289 // this unit test make sure that our label::isSmallerInLabelOrder
290 // is the same as the ordering of BLOB in SQLite
291
Davide Pesavento948c50c2020-12-26 21:30:45 -0500292 auto genRandomString = [] (size_t length) {
293 static const std::string charset = "0123456789"
294 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
295 "abcdefghijklmnopqrstuvwxyz";
Yumin Xia55a7cc42017-05-14 18:43:34 -0700296 std::uniform_int_distribution<size_t> dist(0, charset.size() - 1);
297
298 std::string str(length, 0);
Davide Pesavento948c50c2020-12-26 21:30:45 -0500299 std::generate_n(str.begin(), length,
300 [&] { return charset[dist(random::getRandomNumberEngine())]; });
Yumin Xia55a7cc42017-05-14 18:43:34 -0700301 return str;
302 };
303
Davide Pesavento948c50c2020-12-26 21:30:45 -0500304 auto genRandomLabel = [&] {
Yumin Xia55a7cc42017-05-14 18:43:34 -0700305 std::uniform_int_distribution<size_t> numberOfLabelsDist(1, 5);
306 std::uniform_int_distribution<size_t> labelSizeDist(1, 10);
Davide Pesavento948c50c2020-12-26 21:30:45 -0500307
Yumin Xia55a7cc42017-05-14 18:43:34 -0700308 Name nm;
Davide Pesavento948c50c2020-12-26 21:30:45 -0500309 size_t length = numberOfLabelsDist(random::getRandomNumberEngine());
Yumin Xia55a7cc42017-05-14 18:43:34 -0700310 for (size_t i = 0; i < length; i++) {
Davide Pesavento948c50c2020-12-26 21:30:45 -0500311 nm.append(genRandomString(labelSizeDist(random::getRandomNumberEngine())));
Yumin Xia55a7cc42017-05-14 18:43:34 -0700312 }
313 return nm;
314 };
315
316 const size_t NGENERATED_LABELS = 10;
317
318 Zone zone = m_tool.createZone("/net/ndnsim", "/net");
319 RrsetFactory rrsetFactory(TEST_DATABASE.string(), zone.getName(),
320 m_keyChain, DEFAULT_CERT);
321 rrsetFactory.checkZoneKey();
322 std::vector<Rrset> rrsets;
323 std::vector<Name> names;
324 for (size_t i = 0; i < NGENERATED_LABELS; i++) {
325 Name randomLabel = genRandomLabel();
326 Rrset randomTxt = rrsetFactory.generateTxtRrset(randomLabel,
327 VERSION_USE_UNIX_TIMESTAMP,
328 DEFAULT_CACHE_TTL,
329 {});
330
331 rrsets.push_back(randomTxt);
332 m_dbMgr.insert(randomTxt);
333 names.push_back(randomLabel);
334 }
335
336 std::sort(rrsets.begin(), rrsets.end());
337
338 using boost::adaptors::filtered;
339 using boost::adaptors::transformed;
340
341 std::vector<Rrset> rrsetsFromDb = m_dbMgr.findRrsets(zone);
342 auto fromDbFiltered = rrsetsFromDb | filtered([] (const Rrset& rrset) {
343 return rrset.getType() == label::TXT_RR_TYPE;
344 });
345
346 auto extractLabel = [] (const Rrset& rr) {
347 return rr.getLabel();
348 };
349 auto expected = rrsets | transformed(extractLabel);
350 auto actual = fromDbFiltered | transformed(extractLabel);
351
352 BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
353 actual.begin(), actual.end());
354}
355
Yumin Xia9d110ce2016-11-15 14:03:14 -0800356BOOST_AUTO_TEST_CASE(CreateDeleteRootFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800357{
Yumin Xia2c509c22017-02-09 14:37:36 -0800358 // creating root_zone need a rootDkey
359 BOOST_CHECK_THROW(m_tool.createZone(ROOT_ZONE, ROOT_ZONE,
360 time::seconds(4600),
361 time::seconds(4600),
362 rootKsk, rootDsk), ndns::ManagementTool::Error);
363
364 m_tool.createZone(ROOT_ZONE, ROOT_ZONE,
365 time::seconds(4600),
366 time::seconds(4600),
367 rootKsk, rootDsk, rootDkey);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800368
369 Zone zone(ROOT_ZONE);
Yumin Xia2c509c22017-02-09 14:37:36 -0800370 Name zoneIdentityName = Name(ROOT_ZONE).append("NDNS");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800371 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
Yumin Xia2c509c22017-02-09 14:37:36 -0800372 BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, rootDsk));
373 BOOST_CHECK_EQUAL(findCertFromDb(zone, rootDsk).getName(), rootDsk);
374 BOOST_CHECK_EQUAL(findCertFromDb(zone, rootKsk).getName(), rootKsk);
375 BOOST_CHECK_EQUAL(findDkeyFromDb(ROOT_ZONE).getName(), rootDkey);
376
377 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootDsk).getName(), rootDsk);
378 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootKsk).getName(), rootKsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800379
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800380 BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE));
381 BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800382}
383
Yumin Xia9d110ce2016-11-15 14:03:14 -0800384BOOST_AUTO_TEST_CASE(CreateDeleteChildFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800385{
Jiewen Tan870b29b2014-11-17 19:09:49 -0800386 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800387 Name zoneName = Name(parentZoneName).append("child-zone");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800388
Yumin Xia2c509c22017-02-09 14:37:36 -0800389 Zone zone1(zoneName);
Yumin Xia918343d2017-03-17 19:04:55 -0700390 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Yumin Xia2c509c22017-02-09 14:37:36 -0800391 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone1), false);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800392
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800393 // will generate keys automatically
394 m_tool.createZone(zoneName, parentZoneName);
Yumin Xia2c509c22017-02-09 14:37:36 -0800395 BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800396
Yumin Xia2c509c22017-02-09 14:37:36 -0800397 std::vector<Certificate>&& certs = getCerts(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800398 BOOST_REQUIRE_EQUAL(certs.size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800399
Yumin Xia2c509c22017-02-09 14:37:36 -0800400 const Name& ksk = certs[0].getName();
401 const Name& dsk = certs[1].getName();
Jiewen Tan870b29b2014-11-17 19:09:49 -0800402
403 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800404 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
Yumin Xia2c509c22017-02-09 14:37:36 -0800405 BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, dsk));
406 BOOST_CHECK_EQUAL(findCertFromDb(zone, dsk).getName(), dsk);
407 BOOST_CHECK_EQUAL(findCertFromDb(zone, ksk).getName(), ksk);
408
409 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, dsk), findCertFromDb(zone, dsk));
410 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, ksk), findCertFromDb(zone, ksk));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800411
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800412 BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800413
414 BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800415 BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error);
416}
417
Yumin Xia9d110ce2016-11-15 14:03:14 -0800418BOOST_AUTO_TEST_CASE(CreateZoneWithFixture)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800419{
420 Name parentZoneName("/ndns-test");
421 Name zoneName = Name(parentZoneName).append("child-zone");
Yumin Xia918343d2017-03-17 19:04:55 -0700422 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800423
424 m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30));
Yumin Xia2c509c22017-02-09 14:37:36 -0800425 BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800426
Yumin Xia2c509c22017-02-09 14:37:36 -0800427 std::vector<Certificate>&& certs = getCerts(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800428 BOOST_REQUIRE_EQUAL(certs.size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800429
Yumin Xia2c509c22017-02-09 14:37:36 -0800430 const Name& dsk = certs[1].getName();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800431
432 // Check zone ttl
433 Zone zone(zoneName);
434 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
435 BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200));
436
Yumin Xia2c509c22017-02-09 14:37:36 -0800437 // check dkey name
438 Name dkeyName = Name(parentZoneName).append("NDNS").append(zoneName.getSubName(parentZoneName.size()));
439 Certificate dkey = findDkeyFromDb(zoneName);
440 BOOST_CHECK(dkeyName.isPrefixOf(dkey.getName()));
441
442 // TODO: check signing hierarchy
443
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800444 // Check dsk rrset ttl
445 Rrset rrset;
446 BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE));
447 BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200));
448
449 // Check certificate freshnessPeriod and validity
Yumin Xia2c509c22017-02-09 14:37:36 -0800450 Certificate cert = CertHelper::getCertificate(m_keyChain, zoneIdentityName, dsk);
451 time::system_clock::TimePoint beg,end;
452 std::tie(beg, end) = cert.getValidityPeriod().getPeriod();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800453
Yumin Xia2c509c22017-02-09 14:37:36 -0800454 BOOST_REQUIRE_NO_THROW(cert = findCertFromDb(zone, dsk));
455 BOOST_CHECK_EQUAL(cert.getFreshnessPeriod(), time::seconds(4200));
456 BOOST_CHECK_EQUAL(end - beg, time::days(30));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800457 m_tool.deleteZone(zoneName);
458}
459
Yumin Xia9d110ce2016-11-15 14:03:14 -0800460BOOST_AUTO_TEST_CASE(ZoneCreatePreconditions)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800461{
462 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net"));
463 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error);
464
Yumin Xia2c509c22017-02-09 14:37:36 -0800465 std::vector<Certificate>&& certs = getCerts("/net/ndnsim");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800466 BOOST_REQUIRE_EQUAL(certs.size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800467
Yumin Xia2c509c22017-02-09 14:37:36 -0800468 const Name& ksk = certs[0].getName();
469 const Name& dsk = certs[1].getName();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800470
471 m_tool.deleteZone("/net/ndnsim");
472 // identity will still exist after the zone is deleted
473
474 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error);
475
476 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error);
477
478 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
479 time::seconds(1), time::days(1), ksk, dsk));
480 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2);
481 m_tool.deleteZone("/net/ndnsim");
482
483 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
484 time::seconds(1), time::days(1), Name(), dsk));
Yumin Xia2c509c22017-02-09 14:37:36 -0800485
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800486 m_tool.deleteZone("/net/ndnsim");
487
488 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
489 time::seconds(1), time::days(1), ksk, Name()));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800490 m_tool.deleteZone("/net/ndnsim");
491
492 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
493 time::seconds(1), time::days(1), "/com/ndnsim"),
Yumin Xia2c509c22017-02-09 14:37:36 -0800494 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800495
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500496 Identity id = m_keyChain.createIdentity("/net/ndnsim/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800497 Certificate cert = id.getDefaultKey().getDefaultCertificate();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800498 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800499 time::seconds(1), time::days(1), cert.getName()));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800500
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500501 id = m_keyChain.createIdentity("/com/ndnsim/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800502 cert = id.getDefaultKey().getDefaultCertificate();
503
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800504 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800505 time::seconds(1), time::days(1), cert.getName()),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800506 ndns::ManagementTool::Error);
507
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500508 id = m_keyChain.createIdentity("/net/ndnsim/www/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800509 cert = id.getDefaultKey().getDefaultCertificate();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800510 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800511 time::seconds(1), time::days(1), cert.getName()),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800512 ndns::ManagementTool::Error);
513
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500514 id = m_keyChain.createIdentity("/net/ndnsim/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800515 cert = id.getDefaultKey().getDefaultCertificate();
516 m_keyChain.deleteCertificate(id.getDefaultKey(), cert.getName());
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800517 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800518 time::seconds(1), time::days(1), cert.getName()),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800519 ndns::ManagementTool::Error);
520
Yumin Xia2c509c22017-02-09 14:37:36 -0800521 // for root zone special case (requires a valid DKEY to be specified)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800522 BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error);
523
524 BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1),
Yumin Xia2c509c22017-02-09 14:37:36 -0800525 DEFAULT_CERT, DEFAULT_CERT, rootDkey));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800526}
527
528class OutputTester
529{
530public:
531 OutputTester()
532 : savedBuf(std::clog.rdbuf())
533 {
534 std::cout.rdbuf(buffer.rdbuf());
535 }
536
537 ~OutputTester()
538 {
539 std::cout.rdbuf(savedBuf);
540 }
541
542public:
543 std::stringstream buffer;
544 std::streambuf* savedBuf;
545};
546
Yumin Xia2c509c22017-02-09 14:37:36 -0800547// BOOST_AUTO_TEST_CASE(ExportCertificate)
548// {
549// std::string outputFile = TEST_CERTDIR.string() + "/ss.cert";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800550
Yumin Xia2c509c22017-02-09 14:37:36 -0800551// BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile),
552// ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800553
Yumin Xia2c509c22017-02-09 14:37:36 -0800554// BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false);
555// // doesn't check the zone, export from KeyChain directly
556// BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
557// BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800558
Yumin Xia2c509c22017-02-09 14:37:36 -0800559// std::string dskValue =
560// "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n"
561// "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n"
562// "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n"
563// "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n"
564// "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n"
565// "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n"
566// "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n"
567// "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n"
568// "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n"
569// "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n"
570// "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n"
571// "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n"
572// "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n"
573// "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n"
574// "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n"
575// "8UNqhMpjAZwW6pdvOZADVg==\n";
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800576
Yumin Xia2c509c22017-02-09 14:37:36 -0800577// {
578// std::ifstream ifs(outputFile.c_str());
579// std::string actualValue((std::istreambuf_iterator<char>(ifs)),
580// std::istreambuf_iterator<char>());
581// BOOST_CHECK_EQUAL(actualValue, dskValue);
582// }
583// boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800584
Yumin Xia2c509c22017-02-09 14:37:36 -0800585// // doesn't check the zone, export from KeyChain directly
586// BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile));
587// boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800588
Yumin Xia2c509c22017-02-09 14:37:36 -0800589// Name zoneName("/ndns-test");
590// m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30),
591// otherKsk, otherDsk);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800592
Yumin Xia2c509c22017-02-09 14:37:36 -0800593// m_keyChain.deleteCertificate(otherKsk);
594// m_keyChain.deleteCertificate(otherDsk);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800595
Yumin Xia2c509c22017-02-09 14:37:36 -0800596// // retrieve cert from the zone
597// BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
598// {
599// std::ifstream ifs(outputFile.c_str());
600// std::string actualValue((std::istreambuf_iterator<char>(ifs)),
601// std::istreambuf_iterator<char>());
602// BOOST_CHECK_EQUAL(actualValue, dskValue);
603// }
604// boost::filesystem::remove(outputFile);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800605
Yumin Xia2c509c22017-02-09 14:37:36 -0800606// BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile),
607// ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800608
Yumin Xia2c509c22017-02-09 14:37:36 -0800609// // output to std::cout
610// std::string acutalOutput;
611// {
612// OutputTester tester;
613// m_tool.exportCertificate(otherDsk, "-");
614// acutalOutput = tester.buffer.str();
615// }
616// BOOST_CHECK_EQUAL(acutalOutput, dskValue);
617// }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800618
Yumin Xia9d110ce2016-11-15 14:03:14 -0800619BOOST_AUTO_TEST_CASE(AddRrset)
620{
621 Name zoneName("/ndns-test");
622 Zone zone(zoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800623
Yumin Xia9d110ce2016-11-15 14:03:14 -0800624 time::seconds ttl1(4200);
625 time::seconds ttl2(4500);
626 m_tool.createZone(zoneName, ROOT_ZONE, ttl1);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800627
Yumin Xia9d110ce2016-11-15 14:03:14 -0800628 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
629 rf.checkZoneKey();
Junxiao Shi81e98762022-01-11 18:17:24 +0000630 Rrset rrset1 = rf.generateNsRrset("/l1", 7654, ttl2, {});
Jiewen Tan870b29b2014-11-17 19:09:49 -0800631
Yumin Xia9d110ce2016-11-15 14:03:14 -0800632 BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1));
633 Rrset rrset2 = findRrSet(zone, "/l1", label::NS_RR_TYPE);
634 BOOST_CHECK_EQUAL(rrset1, rrset2);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800635}
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800636
Yumin Xia9d110ce2016-11-15 14:03:14 -0800637BOOST_AUTO_TEST_CASE(AddMultiLevelLabelRrset)
638{
Yumin Xia9d110ce2016-11-15 14:03:14 -0800639 Name zoneName("/ndns-test");
640 Zone zone(zoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800641
Yumin Xia9d110ce2016-11-15 14:03:14 -0800642 time::seconds ttl(4200);
643 m_tool.createZone(zoneName, ROOT_ZONE, ttl);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800644
Yumin Xia9d110ce2016-11-15 14:03:14 -0800645 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
646 rf.checkZoneKey();
Jiewen Tan870b29b2014-11-17 19:09:49 -0800647
Yumin Xia9d110ce2016-11-15 14:03:14 -0800648 auto checkRrset = [&zone, &zoneName, this](Name label,
649 name::Component type,
650 NdnsContentType contentType) -> void {
651 Rrset rr1 = findRrSet(zone, label, type);
652 BOOST_CHECK_EQUAL(Data(rr1.getData()).getContentType(), contentType);
653 Response response1;
654 response1.fromData(zoneName, Data(rr1.getData()));
655 BOOST_CHECK_EQUAL(response1.getRrLabel(), label);
656 };
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800657
Yumin Xia9d110ce2016-11-15 14:03:14 -0800658 Name labelName("/l1/l2/l3");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800659
Junxiao Shi81e98762022-01-11 18:17:24 +0000660 Rrset rrset1 = rf.generateNsRrset(labelName, 7654, ttl, {});
Jiewen Tan870b29b2014-11-17 19:09:49 -0800661
Yumin Xia9d110ce2016-11-15 14:03:14 -0800662 //add NS NDNS_AUTH and check user-defined ttl
663 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(rrset1, rf, ttl));
664 Rrset rrset2 = findRrSet(zone, labelName, label::NS_RR_TYPE);
665 BOOST_CHECK_EQUAL(rrset1, rrset2);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800666
Yumin Xia9d110ce2016-11-15 14:03:14 -0800667 checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH);
668 checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800669
Yumin Xia9d110ce2016-11-15 14:03:14 -0800670 // insert a same-name rrset with TXT type
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700671 Rrset txtRr = rf.generateTxtRrset("/l1/l2/l3", 7654, ttl, std::vector<std::string>());
Yumin Xia9d110ce2016-11-15 14:03:14 -0800672 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(txtRr, rf, ttl));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800673
Yumin Xia9d110ce2016-11-15 14:03:14 -0800674 checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH);
675 checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH);
676 checkRrset("/l1/l2/l3", label::TXT_RR_TYPE, ndns::NDNS_RESP);
677 // check that there is no confliction
678 checkRrset("/l1/l2/l3", label::NS_RR_TYPE, ndns::NDNS_LINK);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800679
Yumin Xia9d110ce2016-11-15 14:03:14 -0800680 // insert a shorter NS, when there are longer NS or TXT
Junxiao Shi81e98762022-01-11 18:17:24 +0000681 Rrset shorterNs = rf.generateNsRrset("/l1/l2", 7654, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800682 BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(shorterNs, rf, ttl),
683 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800684
Yumin Xia9d110ce2016-11-15 14:03:14 -0800685 // insert a longer NS, when there is already a shorter NS
Junxiao Shi81e98762022-01-11 18:17:24 +0000686 Rrset longerNs = rf.generateNsRrset("/l1/l2/l3/l4", 7654, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800687 BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(longerNs, rf, ttl),
688 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800689
Yumin Xia9d110ce2016-11-15 14:03:14 -0800690 // insert a smaller TXT, when there are longer NS and TXT
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700691 Rrset shorterTxt = rf.generateTxtRrset("/l1/l2", 7654, ttl, std::vector<std::string>());
Yumin Xia9d110ce2016-11-15 14:03:14 -0800692 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(shorterTxt, rf, ttl));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800693
Yumin Xia9d110ce2016-11-15 14:03:14 -0800694 // insert a smaller NS, when there is long TXT
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700695 Rrset longTxt = rf.generateTxtRrset("/k1/k2/k3", 7654, ttl, std::vector<std::string>());
Junxiao Shi81e98762022-01-11 18:17:24 +0000696 Rrset smallerNs = rf.generateNsRrset("/k1/k2", 7654, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800697 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longTxt, rf, ttl));
698 BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(smallerNs, rf, ttl),
699 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800700
Yumin Xia9d110ce2016-11-15 14:03:14 -0800701 // inserting a longer TXT, when there is shoter TXT
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700702 Rrset longerTxt = rf.generateTxtRrset("/k1/k2/k3/k4", 7654, ttl, std::vector<std::string>());
Yumin Xia9d110ce2016-11-15 14:03:14 -0800703 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longerTxt, rf, ttl));
704}
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800705
Yumin Xia9d110ce2016-11-15 14:03:14 -0800706BOOST_AUTO_TEST_CASE(AddRrSetDskCertPreConditon)
707{
708 // check pre-condition
709 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800710
Yumin Xia9d110ce2016-11-15 14:03:14 -0800711 // Check: throw if zone not exist
712 std::string certPath = TEST_CERTDIR.string();
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800713 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800714
Yumin Xia9d110ce2016-11-15 14:03:14 -0800715 m_tool.createZone(zoneName, ROOT_ZONE);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800716
Yumin Xia9d110ce2016-11-15 14:03:14 -0800717 // Check: throw if certificate does not match
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800718 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800719
Yumin Xia9d110ce2016-11-15 14:03:14 -0800720 std::string rightCertPath = TEST_CERTDIR.string() + "/ss.cert";
Yumin Xia2c509c22017-02-09 14:37:36 -0800721 std::vector<Certificate>&& certs = getCerts(zoneName);
722 const Name& ksk = certs[0].getName();
723 m_tool.exportCertificate(ksk, rightCertPath);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800724
Yumin Xia2c509c22017-02-09 14:37:36 -0800725 // Check: throw if it's a duplicated certificate
726 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, rightCertPath), ndns::ManagementTool::Error);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800727}
Jiewen Tan870b29b2014-11-17 19:09:49 -0800728
Yumin Xia9d110ce2016-11-15 14:03:14 -0800729BOOST_AUTO_TEST_CASE(AddRrSetDskCert)
730{
731 Name parentZoneName("/ndns-test");
732 Name zoneName("/ndns-test/child-zone");
Yumin Xia918343d2017-03-17 19:04:55 -0700733 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800734
Yumin Xia9d110ce2016-11-15 14:03:14 -0800735 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
736 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800737
Yumin Xia2c509c22017-02-09 14:37:36 -0800738 Zone zone(zoneName);
739 Zone parentZone(parentZoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800740
Yumin Xia2c509c22017-02-09 14:37:36 -0800741 Certificate dkey(findDkeyFromDb(zone.getName()));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800742 std::string output = TEST_CERTDIR.string() + "/ss.cert";
Yumin Xia2c509c22017-02-09 14:37:36 -0800743 ndn::io::save(dkey, output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800744
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800745 BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output));
Yumin Xia2c509c22017-02-09 14:37:36 -0800746 // Check if child zone's d-key could be inserted correctly
747 BOOST_CHECK_NO_THROW(findRrSet(parentZone, getLabel(parentZone, dkey.getName()), label::CERT_RR_TYPE));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800748}
Jiewen Tand2d21822015-03-19 15:37:03 -0700749
Yumin Xia9d110ce2016-11-15 14:03:14 -0800750BOOST_AUTO_TEST_CASE(AddRrSetDskCertUserProvidedCert)
751{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500752 // check using user provided certificate
Yumin Xia9d110ce2016-11-15 14:03:14 -0800753 Name parentZoneName("/ndns-test");
Yumin Xia918343d2017-03-17 19:04:55 -0700754 Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800755 Name zoneName("/ndns-test/child-zone");
Yumin Xia918343d2017-03-17 19:04:55 -0700756 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800757
Yumin Xia2c509c22017-02-09 14:37:36 -0800758 // Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false);
759 Identity id = CertHelper::getIdentity(m_keyChain, parentZoneIdentityName);
760 Key dsk = m_keyChain.createKey(id);
761 Certificate dskCert = dsk.getDefaultCertificate();
Yumin Xia9d110ce2016-11-15 14:03:14 -0800762
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800763 // check addRrsetFromFile1
Yumin Xia9d110ce2016-11-15 14:03:14 -0800764 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
765 m_tool.createZone(zoneName, parentZoneName);
766
Yumin Xia2c509c22017-02-09 14:37:36 -0800767 Certificate dkey(findDkeyFromDb(zoneName));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800768 std::string output = TEST_CERTDIR.string() + "/ss.cert";
Yumin Xia2c509c22017-02-09 14:37:36 -0800769 ndn::io::save(dkey, output);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800770
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800771 BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output, time::seconds(4600),
Yumin Xia2c509c22017-02-09 14:37:36 -0800772 dskCert.getName()));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800773}
774
775BOOST_AUTO_TEST_CASE(AddRrSetDskCertInvalidOutput)
776{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500777 // check invalid output
Yumin Xia9d110ce2016-11-15 14:03:14 -0800778 Name parentZoneName("/ndns-test");
779 Name zoneName = Name(parentZoneName).append("child-zone");
780 m_tool.createZone(zoneName, parentZoneName);
781
782 Name content = "invalid data packet";
783 std::string output = TEST_CERTDIR.string() + "/ss.cert";
784 ndn::io::save(content, output);
785
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800786 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, output), ndns::ManagementTool::Error);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800787}
788
789BOOST_AUTO_TEST_CASE(AddRrSetVersionControl)
790{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500791 // check version control
Yumin Xia9d110ce2016-11-15 14:03:14 -0800792 time::seconds ttl(4200);
793 Name parentZoneName("/ndns-test");
794 Name zoneName = Name(parentZoneName).append("child-zone");
795 m_tool.createZone(zoneName, parentZoneName);
796
797 Name label("/label");
798 uint64_t version = 110;
799
800 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
801 rf.checkZoneKey();
802
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700803 Rrset rrset1 = rf.generateTxtRrset(label, version, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800804
805 m_tool.addRrset(rrset1);
806 // throw error when adding duplicated rrset with the same version
807 BOOST_CHECK_THROW(m_tool.addRrset(rrset1),
808 ndns::ManagementTool::Error);
809 version--;
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700810 Rrset rrset2 = rf.generateTxtRrset(label, version, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800811 // throw error when adding duplicated rrset with older version
812 BOOST_CHECK_THROW(m_tool.addRrset(rrset2),
813 ndns::ManagementTool::Error);
814
815 version++;
816 version++;
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700817 Rrset rrset3 = rf.generateTxtRrset(label, version, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800818 BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset3));
819
820 Zone zone(zoneName);
821 m_dbMgr.find(zone);
822 Rrset rrset;
823 rrset.setZone(&zone);
824 rrset.setLabel(label);
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700825 rrset.setType(label::TXT_RR_TYPE);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800826 m_dbMgr.find(rrset);
827
828 BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version));
829}
830
831BOOST_AUTO_TEST_CASE(AddRrSetDskCertFormat)
832{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500833 // check input with different formats
Yumin Xia9d110ce2016-11-15 14:03:14 -0800834 Name parentZoneName("/ndns-test");
835 Name zoneName = Name(parentZoneName).append("child-zone");
Yumin Xia2c509c22017-02-09 14:37:36 -0800836 Zone parentZone(parentZoneName);
837
838 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800839 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tand2d21822015-03-19 15:37:03 -0700840
Yumin Xia2c509c22017-02-09 14:37:36 -0800841 Certificate cert(findDkeyFromDb(zoneName));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800842 std::string output = TEST_CERTDIR.string() + "/a.cert";
Jiewen Tand2d21822015-03-19 15:37:03 -0700843
Yumin Xia918343d2017-03-17 19:04:55 -0700844 Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY);
845
Yumin Xia9d110ce2016-11-15 14:03:14 -0800846 // base64
Yumin Xia2c509c22017-02-09 14:37:36 -0800847 ndn::io::save(cert, output, ndn::io::BASE64);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800848 BOOST_CHECK_NO_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800849 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64));
850 m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE);
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700851
Yumin Xia9d110ce2016-11-15 14:03:14 -0800852 // raw
Yumin Xia2c509c22017-02-09 14:37:36 -0800853 ndn::io::save(cert, output, ndn::io::NO_ENCODING);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800854 BOOST_CHECK_NO_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800855 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING));
856 m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE);
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700857
Yumin Xia9d110ce2016-11-15 14:03:14 -0800858 // hex
Yumin Xia2c509c22017-02-09 14:37:36 -0800859 ndn::io::save(cert, output, ndn::io::HEX);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800860 BOOST_CHECK_NO_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800861 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX));
862 m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE);
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700863
Yumin Xia9d110ce2016-11-15 14:03:14 -0800864 // incorrect encoding input
Yumin Xia2c509c22017-02-09 14:37:36 -0800865 ndn::io::save(cert, output, ndn::io::HEX);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800866 BOOST_CHECK_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800867 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT,
868 static_cast<ndn::io::IoEncoding>(127)),
Yumin Xia9d110ce2016-11-15 14:03:14 -0800869 ndns::ManagementTool::Error);
870}
Jiewen Tan74d745c2015-03-20 01:40:41 -0700871
Yumin Xia9d110ce2016-11-15 14:03:14 -0800872BOOST_AUTO_TEST_CASE(ListAllZones)
873{
Yumin Xia2c509c22017-02-09 14:37:36 -0800874 m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk, rootDkey);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800875 m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700876
Yumin Xia2c509c22017-02-09 14:37:36 -0800877 Name rootDskName = CertHelper::getCertificate(m_keyChain, "/NDNS/", rootDsk).getKeyName();
878 Name otherDskName = CertHelper::getCertificate(m_keyChain, "/ndns-test/NDNS/", otherDsk).getKeyName();
879
Yumin Xia9d110ce2016-11-15 14:03:14 -0800880 std::string expectedValue =
Yumin Xia2c509c22017-02-09 14:37:36 -0800881 "/ ; default-ttl=1 default-key=" + rootDskName.toUri() + " "
882 "default-certificate=" + rootDsk.toUri() + "\n"
883 "/ndns-test ; default-ttl=10 default-key=" + otherDskName.toUri() + " "
884 "default-certificate=" + otherDsk.toUri() + "\n";
Jiewen Tan74d745c2015-03-20 01:40:41 -0700885
Yumin Xia9d110ce2016-11-15 14:03:14 -0800886 output_test_stream testOutput;
887 m_tool.listAllZones(testOutput);
888 BOOST_CHECK(testOutput.is_equal(expectedValue));
889}
Jiewen Tan74d745c2015-03-20 01:40:41 -0700890
Yumin Xia55a7cc42017-05-14 18:43:34 -0700891// Test need to fix values of keys, otherwise it produces different values every time
Yumin Xia2c509c22017-02-09 14:37:36 -0800892
Yumin Xia55a7cc42017-05-14 18:43:34 -0700893// BOOST_AUTO_TEST_CASE(ListZone)
894// {
895// m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700896
Yumin Xia55a7cc42017-05-14 18:43:34 -0700897// RrsetFactory rf(TEST_DATABASE, "/ndns-test", m_keyChain, DEFAULT_CERT);
898// rf.checkZoneKey();
Jiewen Tan74d745c2015-03-20 01:40:41 -0700899
Yumin Xia55a7cc42017-05-14 18:43:34 -0700900// // Add NS with NDNS_RESP
901// Delegation del;
902// del.preference = 10;
903// del.name = Name("/get/link");
904// DelegationList ds = {del};
905// Rrset rrset1 = rf.generateNsRrset("/label1", 100, DEFAULT_RR_TTL, ds);
906// m_tool.addRrset(rrset1);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700907
Yumin Xia55a7cc42017-05-14 18:43:34 -0700908// // Add NS with NDNS_AUTH
909// Rrset rrset2 = rf.generateAuthRrset("/label2", 100000, DEFAULT_RR_TTL);
910// m_tool.addRrset(rrset2);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700911
Yumin Xia55a7cc42017-05-14 18:43:34 -0700912// // Add TXT from file
913// std::string output = TEST_CERTDIR.string() + "/a.rrset";
914// Response re1;
915// re1.setZone("/ndns-test");
916// re1.setQueryType(label::NDNS_ITERATIVE_QUERY);
917// re1.setRrLabel("/label2");
918// re1.setRrType(label::TXT_RR_TYPE);
919// re1.setContentType(NDNS_RESP);
920// re1.setVersion(name::Component::fromVersion(654321));
921// re1.addRr("First RR");
922// re1.addRr("Second RR");
923// re1.addRr("Last RR");
924// shared_ptr<Data> data1 = re1.toData();
925// m_keyChain.sign(*data1, security::signingByCertificate(otherDsk));
926// ndn::io::save(*data1, output);
927// m_tool.addRrsetFromFile("/ndns-test", output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800928
Yumin Xia55a7cc42017-05-14 18:43:34 -0700929// // Add TXT in normal way
930// Rrset rrset3 = rf.generateTxtRrset("/label3", 3333, DEFAULT_RR_TTL, {"Hello", "World"});
931// m_tool.addRrset(rrset3);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800932
Yumin Xia55a7cc42017-05-14 18:43:34 -0700933// m_tool.listZone("/ndns-test", std::cout, true);
Yumin Xia2c509c22017-02-09 14:37:36 -0800934
Yumin Xia55a7cc42017-05-14 18:43:34 -0700935// output_test_stream testOutput;
936// m_tool.listZone("/ndns-test", testOutput, true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800937
Yumin Xia55a7cc42017-05-14 18:43:34 -0700938// std::string expectedValue =
939// R"VALUE(; Zone /ndns-test
Yumin Xia2c509c22017-02-09 14:37:36 -0800940
Yumin Xia55a7cc42017-05-14 18:43:34 -0700941// ; rrset=/ type=DOE version=%FD%00%00%01b%26e%AE%99 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
942// / 3600 DOE Bw0IBmxhYmVsMwgDVFhU
943// / 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800944
Yumin Xia55a7cc42017-05-14 18:43:34 -0700945// /KEY/%12%05t%90%3AjvA 10 CERT ; content-type=KEY version=%FD%00%00%01b%26e%AEY signed-by=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4
946// Certificate name:
947// /ndns-test/NDNS/KEY/%12%05t%90%3AjvA/CERT/%FD%00%00%01b%26e%AEY
948// Validity:
949// NotBefore: 20180314T212340
950// NotAfter: 20180324T212340
951// Public key bits:
952// MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA
953// AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA////
954// ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd
955// NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5
956// RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA
957// //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABHU62fbCa6KR7G1iyMr6/NtF
958// 5oHrAdzttIgh5pk1VS1YcFO1zhpUnpJS43FlduYHVBLrXwYS6tZ15Ge/D3uy1f4=
959// Signature Information:
960// Signature Type: SignatureSha256WithEcdsa
961// Key Locator: Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800962
Yumin Xia55a7cc42017-05-14 18:43:34 -0700963// ; rrset=/KEY/%12%05t%90%3AjvA/CERT type=DOE version=%FD%00%00%01b%26e%AE%91 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
964// /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ=
965// /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800966
Yumin Xia55a7cc42017-05-14 18:43:34 -0700967// /KEY/%8D%1Dj%1E%BE%B0%2A%E4 10 CERT ; content-type=KEY version=%FD%00%00%01b%26e%AEX signed-by=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4
968// Certificate name:
969// /ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT/%FD%00%00%01b%26e%AEX
970// Validity:
971// NotBefore: 20180314T212340
972// NotAfter: 20180324T212340
973// Public key bits:
974// MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA
975// AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA////
976// ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd
977// NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5
978// RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA
979// //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABMRVD/FUfCQVvjcwQLe9k1aS
980// 5pZ/xmFndOHn1+a0OYVzxCV1JcxL1eojcij42tCP5mtocrj9DjYyFBv4Atg1RZE=
981// Signature Information:
982// Signature Type: SignatureSha256WithEcdsa
983// Key Locator: Self-Signed Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800984
Yumin Xia55a7cc42017-05-14 18:43:34 -0700985// ; rrset=/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT type=DOE version=%FD%00%00%01b%26e%AE%93 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
986// /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ=
987// /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BwwIBmxhYmVsMQgCTlM=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800988
Yumin Xia55a7cc42017-05-14 18:43:34 -0700989// ; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
990// /label1 10 NS 10
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800991
Yumin Xia55a7cc42017-05-14 18:43:34 -0700992// ; rrset=/label1/NS type=DOE version=%FD%00%00%01b%26e%AE%94 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
993// /label1/NS 3600 DOE BwwIBmxhYmVsMQgCTlM=
994// /label1/NS 3600 DOE BwwIBmxhYmVsMggCTlM=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800995
Yumin Xia55a7cc42017-05-14 18:43:34 -0700996// ; rrset=/label2 type=NS version=%FD%00%01%86%A0 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
997// /label2 10 NS NDNS-Auth
998
999// ; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1000// /label2 10 TXT First RR
1001// /label2 10 TXT Second RR
1002// /label2 10 TXT Last RR
1003
1004// ; rrset=/label2/NS type=DOE version=%FD%00%00%01b%26e%AE%96 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1005// /label2/NS 3600 DOE BwwIBmxhYmVsMggCTlM=
1006// /label2/NS 3600 DOE Bw0IBmxhYmVsMggDVFhU
1007
1008// ; rrset=/label2/TXT type=DOE version=%FD%00%00%01b%26e%AE%97 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1009// /label2/TXT 3600 DOE Bw0IBmxhYmVsMggDVFhU
1010// /label2/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU
1011
1012// ; rrset=/label3 type=TXT version=%FD%0D%05 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1013// /label3 10 TXT Hello
1014// /label3 10 TXT World
1015
1016// ; rrset=/label3/TXT type=DOE version=%FD%00%00%01b%26e%AE%98 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1017// /label3/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU
1018// /label3/TXT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ=
1019
1020// )VALUE";
1021
1022// BOOST_CHECK(testOutput.is_equal(expectedValue));
1023// }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -08001024
Yumin Xia9d110ce2016-11-15 14:03:14 -08001025BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture)
1026{
1027 Name zoneName("/ndns-test");
1028 m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
1029 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
1030 rf.checkZoneKey();
Yumin Xiad4e8ce52017-03-17 19:56:52 -07001031 Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {"Value1", "Value2"});
Jiewen Tan870b29b2014-11-17 19:09:49 -08001032
Yumin Xia9d110ce2016-11-15 14:03:14 -08001033 m_tool.addRrset(rrset1);
Jiewen Tan870b29b2014-11-17 19:09:49 -08001034
Yumin Xia2c509c22017-02-09 14:37:36 -08001035 std::stringstream os;
1036
1037 using security::transform::base64Encode;
1038 using security::transform::streamSink;
1039 using security::transform::bufferSource;
1040
1041 bufferSource(rrset1.getData().wire(), rrset1.getData().size()) >> base64Encode() >> streamSink(os);
1042
1043 std::string expectedValue = os.str();
Jiewen Tan870b29b2014-11-17 19:09:49 -08001044
Yumin Xia9d110ce2016-11-15 14:03:14 -08001045 output_test_stream testOutput;
1046 m_tool.getRrSet(zoneName, "/label",label::TXT_RR_TYPE, testOutput);
Yumin Xia9d110ce2016-11-15 14:03:14 -08001047 BOOST_CHECK(testOutput.is_equal(expectedValue));
1048}
Jiewen Tan870b29b2014-11-17 19:09:49 -08001049
Yumin Xia9d110ce2016-11-15 14:03:14 -08001050BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture)
1051{
1052 Name zoneName("/ndns-test");
Jiewen Tan870b29b2014-11-17 19:09:49 -08001053
Yumin Xia9d110ce2016-11-15 14:03:14 -08001054 m_tool.createZone(zoneName, ROOT_ZONE);
1055 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
1056 rf.checkZoneKey();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -08001057
Yumin Xiad4e8ce52017-03-17 19:56:52 -07001058 Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {});
Jiewen Tan870b29b2014-11-17 19:09:49 -08001059
Yumin Xia9d110ce2016-11-15 14:03:14 -08001060 BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -08001061
Yumin Xia9d110ce2016-11-15 14:03:14 -08001062 Zone zone(zoneName);
Yumin Xiad4e8ce52017-03-17 19:56:52 -07001063 BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::TXT_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -08001064
Yumin Xia9d110ce2016-11-15 14:03:14 -08001065 BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -08001066
Yumin Xia9d110ce2016-11-15 14:03:14 -08001067 BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error);
1068}
Jiewen Tan870b29b2014-11-17 19:09:49 -08001069
1070BOOST_AUTO_TEST_SUITE_END()
1071
1072} // namespace tests
1073} // namespace ndns
1074} // namespace ndn