blob: d4f6234726ab179634c921e725f5a05a8891caa8 [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 }
205
206 Certificate
207 findCertFromDb(Zone& zone, const Name& fullName)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800208 {
209 Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE);
Yumin Xia2c509c22017-02-09 14:37:36 -0800210 Certificate cert;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800211 cert.wireDecode(rrset.getData());
212 return cert;
213 }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800214
Yumin Xia2c509c22017-02-09 14:37:36 -0800215 Certificate
216 findDkeyFromDb(const Name& zoneName)
217 {
218 Zone zone(zoneName);
219 std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone);
220 return Certificate(zoneInfo["dkey"]);
221 }
222
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800223 Response
224 findResponse(Zone& zone, const Name& label, const name::Component& type)
225 {
226 Rrset rrset = findRrSet(zone, label, type);
227 Data data(rrset.getData());
228 Response resp;
Yumin Xia6343c5b2016-10-20 15:45:50 -0700229 resp.fromData(zone.getName(), data);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800230 return resp;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800231 }
232
233public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800234 PreviousStateCleaner cleaner; // must be first variable
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800235 ndns::ManagementTool m_tool;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800236 ndns::DbMgr m_dbMgr;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800237
238 // Names of pre-created certificates
239 // Uncomment and run InitPreconfiguredKeys test case and then update names in the
240 // constructor.
241 Name rootKsk;
242 Name rootDsk;
243 Name otherKsk;
244 Name otherDsk;
Yumin Xia2c509c22017-02-09 14:37:36 -0800245 Name rootDkey;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800246};
247
Yumin Xia9d110ce2016-11-15 14:03:14 -0800248BOOST_FIXTURE_TEST_SUITE(ManagementTool, ManagementToolFixture)
249
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800250// BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture)
251// {
252// using time::seconds;
253
254// auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name {
255// // to re-generate certificates, uncomment and then update rootKsk/rootDsk names
256// Name kskName = m_keyChain.generateRsaKeyPair(zone, true);
257// auto kskCert = m_keyChain
258// .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)),
259// time::fromUnixTimestamp(seconds(2147483648)), {});
260// if (parentCert.empty()) {
261// m_keyChain.selfSign(*kskCert);
262// }
263// else {
264// m_keyChain.sign(*kskCert, parentCert);
265// }
266// m_keyChain.addCertificate(*kskCert);
267
268// Name dskName = m_keyChain.generateRsaKeyPair(zone, false);
269// auto dskCert = m_keyChain
270// .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)),
271// time::fromUnixTimestamp(seconds(2147483648)), {});
272// m_keyChain.sign(*dskCert, kskCert->getName());
273// m_keyChain.addCertificate(*dskCert);
274
275// return dskCert->getName();
276// };
277
278// Name rootDsk = generateCerts(ROOT_ZONE);
279// generateCerts("/ndns-test", rootDsk);
280
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500281// copyDir(UNIT_TESTS_TMPDIR "/tests/unit/mgmt/.ndn", "/tmp/.ndn");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800282// std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl;
283// }
284
Yumin Xia55a7cc42017-05-14 18:43:34 -0700285BOOST_AUTO_TEST_CASE(SqliteLabelOrder)
286{
287 // the correctness of our DoE design rely on the ordering of SQLite
288 // this unit test make sure that our label::isSmallerInLabelOrder
289 // is the same as the ordering of BLOB in SQLite
290
Davide Pesavento948c50c2020-12-26 21:30:45 -0500291 auto genRandomString = [] (size_t length) {
292 static const std::string charset = "0123456789"
293 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
294 "abcdefghijklmnopqrstuvwxyz";
Yumin Xia55a7cc42017-05-14 18:43:34 -0700295 std::uniform_int_distribution<size_t> dist(0, charset.size() - 1);
296
297 std::string str(length, 0);
Davide Pesavento948c50c2020-12-26 21:30:45 -0500298 std::generate_n(str.begin(), length,
299 [&] { return charset[dist(random::getRandomNumberEngine())]; });
Yumin Xia55a7cc42017-05-14 18:43:34 -0700300 return str;
301 };
302
Davide Pesavento948c50c2020-12-26 21:30:45 -0500303 auto genRandomLabel = [&] {
Yumin Xia55a7cc42017-05-14 18:43:34 -0700304 std::uniform_int_distribution<size_t> numberOfLabelsDist(1, 5);
305 std::uniform_int_distribution<size_t> labelSizeDist(1, 10);
Davide Pesavento948c50c2020-12-26 21:30:45 -0500306
Yumin Xia55a7cc42017-05-14 18:43:34 -0700307 Name nm;
Davide Pesavento948c50c2020-12-26 21:30:45 -0500308 size_t length = numberOfLabelsDist(random::getRandomNumberEngine());
Yumin Xia55a7cc42017-05-14 18:43:34 -0700309 for (size_t i = 0; i < length; i++) {
Davide Pesavento948c50c2020-12-26 21:30:45 -0500310 nm.append(genRandomString(labelSizeDist(random::getRandomNumberEngine())));
Yumin Xia55a7cc42017-05-14 18:43:34 -0700311 }
312 return nm;
313 };
314
315 const size_t NGENERATED_LABELS = 10;
316
317 Zone zone = m_tool.createZone("/net/ndnsim", "/net");
318 RrsetFactory rrsetFactory(TEST_DATABASE.string(), zone.getName(),
319 m_keyChain, DEFAULT_CERT);
320 rrsetFactory.checkZoneKey();
321 std::vector<Rrset> rrsets;
322 std::vector<Name> names;
323 for (size_t i = 0; i < NGENERATED_LABELS; i++) {
324 Name randomLabel = genRandomLabel();
325 Rrset randomTxt = rrsetFactory.generateTxtRrset(randomLabel,
326 VERSION_USE_UNIX_TIMESTAMP,
327 DEFAULT_CACHE_TTL,
328 {});
329
330 rrsets.push_back(randomTxt);
331 m_dbMgr.insert(randomTxt);
332 names.push_back(randomLabel);
333 }
334
335 std::sort(rrsets.begin(), rrsets.end());
336
337 using boost::adaptors::filtered;
338 using boost::adaptors::transformed;
339
340 std::vector<Rrset> rrsetsFromDb = m_dbMgr.findRrsets(zone);
341 auto fromDbFiltered = rrsetsFromDb | filtered([] (const Rrset& rrset) {
342 return rrset.getType() == label::TXT_RR_TYPE;
343 });
344
345 auto extractLabel = [] (const Rrset& rr) {
346 return rr.getLabel();
347 };
348 auto expected = rrsets | transformed(extractLabel);
349 auto actual = fromDbFiltered | transformed(extractLabel);
350
351 BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
352 actual.begin(), actual.end());
353}
354
Yumin Xia9d110ce2016-11-15 14:03:14 -0800355BOOST_AUTO_TEST_CASE(CreateDeleteRootFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800356{
Yumin Xia2c509c22017-02-09 14:37:36 -0800357 // creating root_zone need a rootDkey
358 BOOST_CHECK_THROW(m_tool.createZone(ROOT_ZONE, ROOT_ZONE,
359 time::seconds(4600),
360 time::seconds(4600),
361 rootKsk, rootDsk), ndns::ManagementTool::Error);
362
363 m_tool.createZone(ROOT_ZONE, ROOT_ZONE,
364 time::seconds(4600),
365 time::seconds(4600),
366 rootKsk, rootDsk, rootDkey);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800367
368 Zone zone(ROOT_ZONE);
Yumin Xia2c509c22017-02-09 14:37:36 -0800369 Name zoneIdentityName = Name(ROOT_ZONE).append("NDNS");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800370 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
Yumin Xia2c509c22017-02-09 14:37:36 -0800371 BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, rootDsk));
372 BOOST_CHECK_EQUAL(findCertFromDb(zone, rootDsk).getName(), rootDsk);
373 BOOST_CHECK_EQUAL(findCertFromDb(zone, rootKsk).getName(), rootKsk);
374 BOOST_CHECK_EQUAL(findDkeyFromDb(ROOT_ZONE).getName(), rootDkey);
375
376 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootDsk).getName(), rootDsk);
377 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootKsk).getName(), rootKsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800378
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800379 BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE));
380 BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800381}
382
Yumin Xia9d110ce2016-11-15 14:03:14 -0800383BOOST_AUTO_TEST_CASE(CreateDeleteChildFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800384{
Jiewen Tan870b29b2014-11-17 19:09:49 -0800385 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800386 Name zoneName = Name(parentZoneName).append("child-zone");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800387
Yumin Xia2c509c22017-02-09 14:37:36 -0800388 Zone zone1(zoneName);
Yumin Xia918343d2017-03-17 19:04:55 -0700389 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Yumin Xia2c509c22017-02-09 14:37:36 -0800390 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone1), false);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800391
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800392 // will generate keys automatically
393 m_tool.createZone(zoneName, parentZoneName);
Yumin Xia2c509c22017-02-09 14:37:36 -0800394 BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800395
Yumin Xia2c509c22017-02-09 14:37:36 -0800396 std::vector<Certificate>&& certs = getCerts(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800397 BOOST_REQUIRE_EQUAL(certs.size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800398
Yumin Xia2c509c22017-02-09 14:37:36 -0800399 const Name& ksk = certs[0].getName();
400 const Name& dsk = certs[1].getName();
Jiewen Tan870b29b2014-11-17 19:09:49 -0800401
402 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800403 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
Yumin Xia2c509c22017-02-09 14:37:36 -0800404 BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, dsk));
405 BOOST_CHECK_EQUAL(findCertFromDb(zone, dsk).getName(), dsk);
406 BOOST_CHECK_EQUAL(findCertFromDb(zone, ksk).getName(), ksk);
407
408 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, dsk), findCertFromDb(zone, dsk));
409 BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, ksk), findCertFromDb(zone, ksk));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800410
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800411 BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800412
413 BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800414 BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error);
415}
416
Yumin Xia9d110ce2016-11-15 14:03:14 -0800417BOOST_AUTO_TEST_CASE(CreateZoneWithFixture)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800418{
419 Name parentZoneName("/ndns-test");
420 Name zoneName = Name(parentZoneName).append("child-zone");
Yumin Xia918343d2017-03-17 19:04:55 -0700421 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800422
423 m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30));
Yumin Xia2c509c22017-02-09 14:37:36 -0800424 BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800425
Yumin Xia2c509c22017-02-09 14:37:36 -0800426 std::vector<Certificate>&& certs = getCerts(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800427 BOOST_REQUIRE_EQUAL(certs.size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800428
Yumin Xia2c509c22017-02-09 14:37:36 -0800429 const Name& dsk = certs[1].getName();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800430
431 // Check zone ttl
432 Zone zone(zoneName);
433 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
434 BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200));
435
Yumin Xia2c509c22017-02-09 14:37:36 -0800436 // check dkey name
437 Name dkeyName = Name(parentZoneName).append("NDNS").append(zoneName.getSubName(parentZoneName.size()));
438 Certificate dkey = findDkeyFromDb(zoneName);
439 BOOST_CHECK(dkeyName.isPrefixOf(dkey.getName()));
440
441 // TODO: check signing hierarchy
442
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800443 // Check dsk rrset ttl
444 Rrset rrset;
445 BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE));
446 BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200));
447
448 // Check certificate freshnessPeriod and validity
Yumin Xia2c509c22017-02-09 14:37:36 -0800449 Certificate cert = CertHelper::getCertificate(m_keyChain, zoneIdentityName, dsk);
Davide Pesavento38fd3982022-04-18 22:22:02 -0400450 auto [beg, end] = cert.getValidityPeriod().getPeriod();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800451
Yumin Xia2c509c22017-02-09 14:37:36 -0800452 BOOST_REQUIRE_NO_THROW(cert = findCertFromDb(zone, dsk));
453 BOOST_CHECK_EQUAL(cert.getFreshnessPeriod(), time::seconds(4200));
454 BOOST_CHECK_EQUAL(end - beg, time::days(30));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800455 m_tool.deleteZone(zoneName);
456}
457
Yumin Xia9d110ce2016-11-15 14:03:14 -0800458BOOST_AUTO_TEST_CASE(ZoneCreatePreconditions)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800459{
460 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net"));
461 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error);
462
Yumin Xia2c509c22017-02-09 14:37:36 -0800463 std::vector<Certificate>&& certs = getCerts("/net/ndnsim");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800464 BOOST_REQUIRE_EQUAL(certs.size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800465
Yumin Xia2c509c22017-02-09 14:37:36 -0800466 const Name& ksk = certs[0].getName();
467 const Name& dsk = certs[1].getName();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800468
469 m_tool.deleteZone("/net/ndnsim");
470 // identity will still exist after the zone is deleted
471
472 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error);
473
474 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error);
475
476 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
477 time::seconds(1), time::days(1), ksk, dsk));
478 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2);
479 m_tool.deleteZone("/net/ndnsim");
480
481 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
482 time::seconds(1), time::days(1), Name(), dsk));
Yumin Xia2c509c22017-02-09 14:37:36 -0800483
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800484 m_tool.deleteZone("/net/ndnsim");
485
486 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
487 time::seconds(1), time::days(1), ksk, Name()));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800488 m_tool.deleteZone("/net/ndnsim");
489
490 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
491 time::seconds(1), time::days(1), "/com/ndnsim"),
Yumin Xia2c509c22017-02-09 14:37:36 -0800492 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800493
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500494 Identity id = m_keyChain.createIdentity("/net/ndnsim/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800495 Certificate cert = id.getDefaultKey().getDefaultCertificate();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800496 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800497 time::seconds(1), time::days(1), cert.getName()));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800498
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500499 id = m_keyChain.createIdentity("/com/ndnsim/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800500 cert = id.getDefaultKey().getDefaultCertificate();
501
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800502 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800503 time::seconds(1), time::days(1), cert.getName()),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800504 ndns::ManagementTool::Error);
505
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500506 id = m_keyChain.createIdentity("/net/ndnsim/www/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800507 cert = id.getDefaultKey().getDefaultCertificate();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800508 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800509 time::seconds(1), time::days(1), cert.getName()),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800510 ndns::ManagementTool::Error);
511
Davide Pesaventobdd88c12020-11-26 00:35:08 -0500512 id = m_keyChain.createIdentity("/net/ndnsim/NDNS");
Yumin Xia2c509c22017-02-09 14:37:36 -0800513 cert = id.getDefaultKey().getDefaultCertificate();
514 m_keyChain.deleteCertificate(id.getDefaultKey(), cert.getName());
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800515 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
Yumin Xia2c509c22017-02-09 14:37:36 -0800516 time::seconds(1), time::days(1), cert.getName()),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800517 ndns::ManagementTool::Error);
518
Yumin Xia2c509c22017-02-09 14:37:36 -0800519 // for root zone special case (requires a valid DKEY to be specified)
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800520 BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error);
521
522 BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1),
Yumin Xia2c509c22017-02-09 14:37:36 -0800523 DEFAULT_CERT, DEFAULT_CERT, rootDkey));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800524}
525
526class OutputTester
527{
528public:
529 OutputTester()
530 : savedBuf(std::clog.rdbuf())
531 {
532 std::cout.rdbuf(buffer.rdbuf());
533 }
534
535 ~OutputTester()
536 {
537 std::cout.rdbuf(savedBuf);
538 }
539
540public:
541 std::stringstream buffer;
542 std::streambuf* savedBuf;
543};
544
Yumin Xia2c509c22017-02-09 14:37:36 -0800545// BOOST_AUTO_TEST_CASE(ExportCertificate)
546// {
547// std::string outputFile = TEST_CERTDIR.string() + "/ss.cert";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800548
Yumin Xia2c509c22017-02-09 14:37:36 -0800549// BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile),
550// ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800551
Yumin Xia2c509c22017-02-09 14:37:36 -0800552// BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false);
553// // doesn't check the zone, export from KeyChain directly
554// BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
555// BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800556
Yumin Xia2c509c22017-02-09 14:37:36 -0800557// std::string dskValue =
558// "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n"
559// "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n"
560// "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n"
561// "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n"
562// "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n"
563// "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n"
564// "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n"
565// "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n"
566// "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n"
567// "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n"
568// "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n"
569// "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n"
570// "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n"
571// "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n"
572// "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n"
573// "8UNqhMpjAZwW6pdvOZADVg==\n";
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800574
Yumin Xia2c509c22017-02-09 14:37:36 -0800575// {
576// std::ifstream ifs(outputFile.c_str());
577// std::string actualValue((std::istreambuf_iterator<char>(ifs)),
578// std::istreambuf_iterator<char>());
579// BOOST_CHECK_EQUAL(actualValue, dskValue);
580// }
581// boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800582
Yumin Xia2c509c22017-02-09 14:37:36 -0800583// // doesn't check the zone, export from KeyChain directly
584// BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile));
585// boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800586
Yumin Xia2c509c22017-02-09 14:37:36 -0800587// Name zoneName("/ndns-test");
588// m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30),
589// otherKsk, otherDsk);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800590
Yumin Xia2c509c22017-02-09 14:37:36 -0800591// m_keyChain.deleteCertificate(otherKsk);
592// m_keyChain.deleteCertificate(otherDsk);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800593
Yumin Xia2c509c22017-02-09 14:37:36 -0800594// // retrieve cert from the zone
595// BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
596// {
597// std::ifstream ifs(outputFile.c_str());
598// std::string actualValue((std::istreambuf_iterator<char>(ifs)),
599// std::istreambuf_iterator<char>());
600// BOOST_CHECK_EQUAL(actualValue, dskValue);
601// }
602// boost::filesystem::remove(outputFile);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800603
Yumin Xia2c509c22017-02-09 14:37:36 -0800604// BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile),
605// ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800606
Yumin Xia2c509c22017-02-09 14:37:36 -0800607// // output to std::cout
608// std::string acutalOutput;
609// {
610// OutputTester tester;
611// m_tool.exportCertificate(otherDsk, "-");
612// acutalOutput = tester.buffer.str();
613// }
614// BOOST_CHECK_EQUAL(acutalOutput, dskValue);
615// }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800616
Yumin Xia9d110ce2016-11-15 14:03:14 -0800617BOOST_AUTO_TEST_CASE(AddRrset)
618{
619 Name zoneName("/ndns-test");
620 Zone zone(zoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800621
Yumin Xia9d110ce2016-11-15 14:03:14 -0800622 time::seconds ttl1(4200);
623 time::seconds ttl2(4500);
624 m_tool.createZone(zoneName, ROOT_ZONE, ttl1);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800625
Yumin Xia9d110ce2016-11-15 14:03:14 -0800626 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
627 rf.checkZoneKey();
Junxiao Shi81e98762022-01-11 18:17:24 +0000628 Rrset rrset1 = rf.generateNsRrset("/l1", 7654, ttl2, {});
Jiewen Tan870b29b2014-11-17 19:09:49 -0800629
Yumin Xia9d110ce2016-11-15 14:03:14 -0800630 BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1));
631 Rrset rrset2 = findRrSet(zone, "/l1", label::NS_RR_TYPE);
632 BOOST_CHECK_EQUAL(rrset1, rrset2);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800633}
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800634
Yumin Xia9d110ce2016-11-15 14:03:14 -0800635BOOST_AUTO_TEST_CASE(AddMultiLevelLabelRrset)
636{
Yumin Xia9d110ce2016-11-15 14:03:14 -0800637 Name zoneName("/ndns-test");
638 Zone zone(zoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800639
Yumin Xia9d110ce2016-11-15 14:03:14 -0800640 time::seconds ttl(4200);
641 m_tool.createZone(zoneName, ROOT_ZONE, ttl);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800642
Yumin Xia9d110ce2016-11-15 14:03:14 -0800643 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
644 rf.checkZoneKey();
Jiewen Tan870b29b2014-11-17 19:09:49 -0800645
Yumin Xia9d110ce2016-11-15 14:03:14 -0800646 auto checkRrset = [&zone, &zoneName, this](Name label,
647 name::Component type,
648 NdnsContentType contentType) -> void {
649 Rrset rr1 = findRrSet(zone, label, type);
650 BOOST_CHECK_EQUAL(Data(rr1.getData()).getContentType(), contentType);
651 Response response1;
652 response1.fromData(zoneName, Data(rr1.getData()));
653 BOOST_CHECK_EQUAL(response1.getRrLabel(), label);
654 };
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800655
Yumin Xia9d110ce2016-11-15 14:03:14 -0800656 Name labelName("/l1/l2/l3");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800657
Junxiao Shi81e98762022-01-11 18:17:24 +0000658 Rrset rrset1 = rf.generateNsRrset(labelName, 7654, ttl, {});
Jiewen Tan870b29b2014-11-17 19:09:49 -0800659
Yumin Xia9d110ce2016-11-15 14:03:14 -0800660 //add NS NDNS_AUTH and check user-defined ttl
661 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(rrset1, rf, ttl));
662 Rrset rrset2 = findRrSet(zone, labelName, label::NS_RR_TYPE);
663 BOOST_CHECK_EQUAL(rrset1, rrset2);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800664
Yumin Xia9d110ce2016-11-15 14:03:14 -0800665 checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH);
666 checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800667
Yumin Xia9d110ce2016-11-15 14:03:14 -0800668 // insert a same-name rrset with TXT type
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700669 Rrset txtRr = rf.generateTxtRrset("/l1/l2/l3", 7654, ttl, std::vector<std::string>());
Yumin Xia9d110ce2016-11-15 14:03:14 -0800670 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(txtRr, rf, ttl));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800671
Yumin Xia9d110ce2016-11-15 14:03:14 -0800672 checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH);
673 checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH);
674 checkRrset("/l1/l2/l3", label::TXT_RR_TYPE, ndns::NDNS_RESP);
675 // check that there is no confliction
676 checkRrset("/l1/l2/l3", label::NS_RR_TYPE, ndns::NDNS_LINK);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800677
Yumin Xia9d110ce2016-11-15 14:03:14 -0800678 // insert a shorter NS, when there are longer NS or TXT
Junxiao Shi81e98762022-01-11 18:17:24 +0000679 Rrset shorterNs = rf.generateNsRrset("/l1/l2", 7654, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800680 BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(shorterNs, rf, ttl),
681 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800682
Yumin Xia9d110ce2016-11-15 14:03:14 -0800683 // insert a longer NS, when there is already a shorter NS
Junxiao Shi81e98762022-01-11 18:17:24 +0000684 Rrset longerNs = rf.generateNsRrset("/l1/l2/l3/l4", 7654, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800685 BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(longerNs, rf, ttl),
686 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800687
Yumin Xia9d110ce2016-11-15 14:03:14 -0800688 // insert a smaller TXT, when there are longer NS and TXT
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700689 Rrset shorterTxt = rf.generateTxtRrset("/l1/l2", 7654, ttl, std::vector<std::string>());
Yumin Xia9d110ce2016-11-15 14:03:14 -0800690 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(shorterTxt, rf, ttl));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800691
Yumin Xia9d110ce2016-11-15 14:03:14 -0800692 // insert a smaller NS, when there is long TXT
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700693 Rrset longTxt = rf.generateTxtRrset("/k1/k2/k3", 7654, ttl, std::vector<std::string>());
Junxiao Shi81e98762022-01-11 18:17:24 +0000694 Rrset smallerNs = rf.generateNsRrset("/k1/k2", 7654, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800695 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longTxt, rf, ttl));
696 BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(smallerNs, rf, ttl),
697 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800698
Yumin Xia9d110ce2016-11-15 14:03:14 -0800699 // inserting a longer TXT, when there is shoter TXT
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700700 Rrset longerTxt = rf.generateTxtRrset("/k1/k2/k3/k4", 7654, ttl, std::vector<std::string>());
Yumin Xia9d110ce2016-11-15 14:03:14 -0800701 BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longerTxt, rf, ttl));
702}
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800703
Yumin Xia9d110ce2016-11-15 14:03:14 -0800704BOOST_AUTO_TEST_CASE(AddRrSetDskCertPreConditon)
705{
706 // check pre-condition
707 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800708
Yumin Xia9d110ce2016-11-15 14:03:14 -0800709 // Check: throw if zone not exist
710 std::string certPath = TEST_CERTDIR.string();
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800711 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800712
Yumin Xia9d110ce2016-11-15 14:03:14 -0800713 m_tool.createZone(zoneName, ROOT_ZONE);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800714
Yumin Xia9d110ce2016-11-15 14:03:14 -0800715 // Check: throw if certificate does not match
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800716 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800717
Yumin Xia9d110ce2016-11-15 14:03:14 -0800718 std::string rightCertPath = TEST_CERTDIR.string() + "/ss.cert";
Yumin Xia2c509c22017-02-09 14:37:36 -0800719 std::vector<Certificate>&& certs = getCerts(zoneName);
720 const Name& ksk = certs[0].getName();
721 m_tool.exportCertificate(ksk, rightCertPath);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800722
Yumin Xia2c509c22017-02-09 14:37:36 -0800723 // Check: throw if it's a duplicated certificate
724 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, rightCertPath), ndns::ManagementTool::Error);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800725}
Jiewen Tan870b29b2014-11-17 19:09:49 -0800726
Yumin Xia9d110ce2016-11-15 14:03:14 -0800727BOOST_AUTO_TEST_CASE(AddRrSetDskCert)
728{
729 Name parentZoneName("/ndns-test");
730 Name zoneName("/ndns-test/child-zone");
Yumin Xia918343d2017-03-17 19:04:55 -0700731 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800732
Yumin Xia9d110ce2016-11-15 14:03:14 -0800733 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
734 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800735
Yumin Xia2c509c22017-02-09 14:37:36 -0800736 Zone zone(zoneName);
737 Zone parentZone(parentZoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800738
Yumin Xia2c509c22017-02-09 14:37:36 -0800739 Certificate dkey(findDkeyFromDb(zone.getName()));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800740 std::string output = TEST_CERTDIR.string() + "/ss.cert";
Yumin Xia2c509c22017-02-09 14:37:36 -0800741 ndn::io::save(dkey, output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800742
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800743 BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output));
Yumin Xia2c509c22017-02-09 14:37:36 -0800744 // Check if child zone's d-key could be inserted correctly
745 BOOST_CHECK_NO_THROW(findRrSet(parentZone, getLabel(parentZone, dkey.getName()), label::CERT_RR_TYPE));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800746}
Jiewen Tand2d21822015-03-19 15:37:03 -0700747
Yumin Xia9d110ce2016-11-15 14:03:14 -0800748BOOST_AUTO_TEST_CASE(AddRrSetDskCertUserProvidedCert)
749{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500750 // check using user provided certificate
Yumin Xia9d110ce2016-11-15 14:03:14 -0800751 Name parentZoneName("/ndns-test");
Yumin Xia918343d2017-03-17 19:04:55 -0700752 Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800753 Name zoneName("/ndns-test/child-zone");
Yumin Xia918343d2017-03-17 19:04:55 -0700754 Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800755
Yumin Xia2c509c22017-02-09 14:37:36 -0800756 // Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false);
757 Identity id = CertHelper::getIdentity(m_keyChain, parentZoneIdentityName);
758 Key dsk = m_keyChain.createKey(id);
759 Certificate dskCert = dsk.getDefaultCertificate();
Yumin Xia9d110ce2016-11-15 14:03:14 -0800760
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800761 // check addRrsetFromFile1
Yumin Xia9d110ce2016-11-15 14:03:14 -0800762 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
763 m_tool.createZone(zoneName, parentZoneName);
764
Yumin Xia2c509c22017-02-09 14:37:36 -0800765 Certificate dkey(findDkeyFromDb(zoneName));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800766 std::string output = TEST_CERTDIR.string() + "/ss.cert";
Yumin Xia2c509c22017-02-09 14:37:36 -0800767 ndn::io::save(dkey, output);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800768
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800769 BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output, time::seconds(4600),
Yumin Xia2c509c22017-02-09 14:37:36 -0800770 dskCert.getName()));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800771}
772
773BOOST_AUTO_TEST_CASE(AddRrSetDskCertInvalidOutput)
774{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500775 // check invalid output
Yumin Xia9d110ce2016-11-15 14:03:14 -0800776 Name parentZoneName("/ndns-test");
777 Name zoneName = Name(parentZoneName).append("child-zone");
778 m_tool.createZone(zoneName, parentZoneName);
779
780 Name content = "invalid data packet";
781 std::string output = TEST_CERTDIR.string() + "/ss.cert";
782 ndn::io::save(content, output);
783
Yumin Xiac5ed63f2017-01-26 13:44:38 -0800784 BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, output), ndns::ManagementTool::Error);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800785}
786
787BOOST_AUTO_TEST_CASE(AddRrSetVersionControl)
788{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500789 // check version control
Yumin Xia9d110ce2016-11-15 14:03:14 -0800790 time::seconds ttl(4200);
791 Name parentZoneName("/ndns-test");
792 Name zoneName = Name(parentZoneName).append("child-zone");
793 m_tool.createZone(zoneName, parentZoneName);
794
795 Name label("/label");
796 uint64_t version = 110;
797
798 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
799 rf.checkZoneKey();
800
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700801 Rrset rrset1 = rf.generateTxtRrset(label, version, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800802
803 m_tool.addRrset(rrset1);
804 // throw error when adding duplicated rrset with the same version
805 BOOST_CHECK_THROW(m_tool.addRrset(rrset1),
806 ndns::ManagementTool::Error);
807 version--;
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700808 Rrset rrset2 = rf.generateTxtRrset(label, version, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800809 // throw error when adding duplicated rrset with older version
810 BOOST_CHECK_THROW(m_tool.addRrset(rrset2),
811 ndns::ManagementTool::Error);
812
813 version++;
814 version++;
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700815 Rrset rrset3 = rf.generateTxtRrset(label, version, ttl, {});
Yumin Xia9d110ce2016-11-15 14:03:14 -0800816 BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset3));
817
818 Zone zone(zoneName);
819 m_dbMgr.find(zone);
820 Rrset rrset;
821 rrset.setZone(&zone);
822 rrset.setLabel(label);
Yumin Xiad4e8ce52017-03-17 19:56:52 -0700823 rrset.setType(label::TXT_RR_TYPE);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800824 m_dbMgr.find(rrset);
825
826 BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version));
827}
828
829BOOST_AUTO_TEST_CASE(AddRrSetDskCertFormat)
830{
Davide Pesavento7f27ec12022-03-10 20:10:54 -0500831 // check input with different formats
Yumin Xia9d110ce2016-11-15 14:03:14 -0800832 Name parentZoneName("/ndns-test");
833 Name zoneName = Name(parentZoneName).append("child-zone");
Yumin Xia2c509c22017-02-09 14:37:36 -0800834 Zone parentZone(parentZoneName);
835
836 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800837 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tand2d21822015-03-19 15:37:03 -0700838
Yumin Xia2c509c22017-02-09 14:37:36 -0800839 Certificate cert(findDkeyFromDb(zoneName));
Yumin Xia9d110ce2016-11-15 14:03:14 -0800840 std::string output = TEST_CERTDIR.string() + "/a.cert";
Jiewen Tand2d21822015-03-19 15:37:03 -0700841
Yumin Xia918343d2017-03-17 19:04:55 -0700842 Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY);
843
Yumin Xia9d110ce2016-11-15 14:03:14 -0800844 // base64
Yumin Xia2c509c22017-02-09 14:37:36 -0800845 ndn::io::save(cert, output, ndn::io::BASE64);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800846 BOOST_CHECK_NO_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800847 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64));
848 m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE);
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700849
Yumin Xia9d110ce2016-11-15 14:03:14 -0800850 // raw
Yumin Xia2c509c22017-02-09 14:37:36 -0800851 ndn::io::save(cert, output, ndn::io::NO_ENCODING);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800852 BOOST_CHECK_NO_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800853 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING));
854 m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE);
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700855
Yumin Xia9d110ce2016-11-15 14:03:14 -0800856 // hex
Yumin Xia2c509c22017-02-09 14:37:36 -0800857 ndn::io::save(cert, output, ndn::io::HEX);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800858 BOOST_CHECK_NO_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800859 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX));
860 m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE);
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700861
Yumin Xia9d110ce2016-11-15 14:03:14 -0800862 // incorrect encoding input
Yumin Xia2c509c22017-02-09 14:37:36 -0800863 ndn::io::save(cert, output, ndn::io::HEX);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800864 BOOST_CHECK_THROW(
Yumin Xia2c509c22017-02-09 14:37:36 -0800865 m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT,
866 static_cast<ndn::io::IoEncoding>(127)),
Yumin Xia9d110ce2016-11-15 14:03:14 -0800867 ndns::ManagementTool::Error);
868}
Jiewen Tan74d745c2015-03-20 01:40:41 -0700869
Yumin Xia9d110ce2016-11-15 14:03:14 -0800870BOOST_AUTO_TEST_CASE(ListAllZones)
871{
Yumin Xia2c509c22017-02-09 14:37:36 -0800872 m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk, rootDkey);
Yumin Xia9d110ce2016-11-15 14:03:14 -0800873 m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700874
Yumin Xia2c509c22017-02-09 14:37:36 -0800875 Name rootDskName = CertHelper::getCertificate(m_keyChain, "/NDNS/", rootDsk).getKeyName();
876 Name otherDskName = CertHelper::getCertificate(m_keyChain, "/ndns-test/NDNS/", otherDsk).getKeyName();
877
Yumin Xia9d110ce2016-11-15 14:03:14 -0800878 std::string expectedValue =
Yumin Xia2c509c22017-02-09 14:37:36 -0800879 "/ ; default-ttl=1 default-key=" + rootDskName.toUri() + " "
880 "default-certificate=" + rootDsk.toUri() + "\n"
881 "/ndns-test ; default-ttl=10 default-key=" + otherDskName.toUri() + " "
882 "default-certificate=" + otherDsk.toUri() + "\n";
Jiewen Tan74d745c2015-03-20 01:40:41 -0700883
Yumin Xia9d110ce2016-11-15 14:03:14 -0800884 output_test_stream testOutput;
885 m_tool.listAllZones(testOutput);
886 BOOST_CHECK(testOutput.is_equal(expectedValue));
887}
Jiewen Tan74d745c2015-03-20 01:40:41 -0700888
Yumin Xia55a7cc42017-05-14 18:43:34 -0700889// Test need to fix values of keys, otherwise it produces different values every time
Yumin Xia2c509c22017-02-09 14:37:36 -0800890
Yumin Xia55a7cc42017-05-14 18:43:34 -0700891// BOOST_AUTO_TEST_CASE(ListZone)
892// {
893// m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700894
Yumin Xia55a7cc42017-05-14 18:43:34 -0700895// RrsetFactory rf(TEST_DATABASE, "/ndns-test", m_keyChain, DEFAULT_CERT);
896// rf.checkZoneKey();
Jiewen Tan74d745c2015-03-20 01:40:41 -0700897
Yumin Xia55a7cc42017-05-14 18:43:34 -0700898// // Add NS with NDNS_RESP
899// Delegation del;
900// del.preference = 10;
901// del.name = Name("/get/link");
902// DelegationList ds = {del};
903// Rrset rrset1 = rf.generateNsRrset("/label1", 100, DEFAULT_RR_TTL, ds);
904// m_tool.addRrset(rrset1);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700905
Yumin Xia55a7cc42017-05-14 18:43:34 -0700906// // Add NS with NDNS_AUTH
907// Rrset rrset2 = rf.generateAuthRrset("/label2", 100000, DEFAULT_RR_TTL);
908// m_tool.addRrset(rrset2);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700909
Yumin Xia55a7cc42017-05-14 18:43:34 -0700910// // Add TXT from file
911// std::string output = TEST_CERTDIR.string() + "/a.rrset";
912// Response re1;
913// re1.setZone("/ndns-test");
914// re1.setQueryType(label::NDNS_ITERATIVE_QUERY);
915// re1.setRrLabel("/label2");
916// re1.setRrType(label::TXT_RR_TYPE);
917// re1.setContentType(NDNS_RESP);
918// re1.setVersion(name::Component::fromVersion(654321));
919// re1.addRr("First RR");
920// re1.addRr("Second RR");
921// re1.addRr("Last RR");
922// shared_ptr<Data> data1 = re1.toData();
923// m_keyChain.sign(*data1, security::signingByCertificate(otherDsk));
924// ndn::io::save(*data1, output);
925// m_tool.addRrsetFromFile("/ndns-test", output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800926
Yumin Xia55a7cc42017-05-14 18:43:34 -0700927// // Add TXT in normal way
928// Rrset rrset3 = rf.generateTxtRrset("/label3", 3333, DEFAULT_RR_TTL, {"Hello", "World"});
929// m_tool.addRrset(rrset3);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800930
Yumin Xia55a7cc42017-05-14 18:43:34 -0700931// m_tool.listZone("/ndns-test", std::cout, true);
Yumin Xia2c509c22017-02-09 14:37:36 -0800932
Yumin Xia55a7cc42017-05-14 18:43:34 -0700933// output_test_stream testOutput;
934// m_tool.listZone("/ndns-test", testOutput, true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800935
Yumin Xia55a7cc42017-05-14 18:43:34 -0700936// std::string expectedValue =
937// R"VALUE(; Zone /ndns-test
Yumin Xia2c509c22017-02-09 14:37:36 -0800938
Yumin Xia55a7cc42017-05-14 18:43:34 -0700939// ; rrset=/ type=DOE version=%FD%00%00%01b%26e%AE%99 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
940// / 3600 DOE Bw0IBmxhYmVsMwgDVFhU
941// / 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800942
Yumin Xia55a7cc42017-05-14 18:43:34 -0700943// /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
944// Certificate name:
945// /ndns-test/NDNS/KEY/%12%05t%90%3AjvA/CERT/%FD%00%00%01b%26e%AEY
946// Validity:
947// NotBefore: 20180314T212340
948// NotAfter: 20180324T212340
949// Public key bits:
950// MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA
951// AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA////
952// ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd
953// NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5
954// RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA
955// //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABHU62fbCa6KR7G1iyMr6/NtF
956// 5oHrAdzttIgh5pk1VS1YcFO1zhpUnpJS43FlduYHVBLrXwYS6tZ15Ge/D3uy1f4=
957// Signature Information:
958// Signature Type: SignatureSha256WithEcdsa
959// Key Locator: Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800960
Yumin Xia55a7cc42017-05-14 18:43:34 -0700961// ; 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
962// /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ=
963// /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800964
Yumin Xia55a7cc42017-05-14 18:43:34 -0700965// /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
966// Certificate name:
967// /ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT/%FD%00%00%01b%26e%AEX
968// Validity:
969// NotBefore: 20180314T212340
970// NotAfter: 20180324T212340
971// Public key bits:
972// MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA
973// AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA////
974// ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd
975// NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5
976// RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA
977// //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABMRVD/FUfCQVvjcwQLe9k1aS
978// 5pZ/xmFndOHn1+a0OYVzxCV1JcxL1eojcij42tCP5mtocrj9DjYyFBv4Atg1RZE=
979// Signature Information:
980// Signature Type: SignatureSha256WithEcdsa
981// Key Locator: Self-Signed Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800982
Yumin Xia55a7cc42017-05-14 18:43:34 -0700983// ; 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
984// /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ=
985// /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BwwIBmxhYmVsMQgCTlM=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800986
Yumin Xia55a7cc42017-05-14 18:43:34 -0700987// ; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
988// /label1 10 NS 10
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800989
Yumin Xia55a7cc42017-05-14 18:43:34 -0700990// ; rrset=/label1/NS type=DOE version=%FD%00%00%01b%26e%AE%94 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
991// /label1/NS 3600 DOE BwwIBmxhYmVsMQgCTlM=
992// /label1/NS 3600 DOE BwwIBmxhYmVsMggCTlM=
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800993
Yumin Xia55a7cc42017-05-14 18:43:34 -0700994// ; rrset=/label2 type=NS version=%FD%00%01%86%A0 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
995// /label2 10 NS NDNS-Auth
996
997// ; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
998// /label2 10 TXT First RR
999// /label2 10 TXT Second RR
1000// /label2 10 TXT Last RR
1001
1002// ; rrset=/label2/NS type=DOE version=%FD%00%00%01b%26e%AE%96 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1003// /label2/NS 3600 DOE BwwIBmxhYmVsMggCTlM=
1004// /label2/NS 3600 DOE Bw0IBmxhYmVsMggDVFhU
1005
1006// ; rrset=/label2/TXT type=DOE version=%FD%00%00%01b%26e%AE%97 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1007// /label2/TXT 3600 DOE Bw0IBmxhYmVsMggDVFhU
1008// /label2/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU
1009
1010// ; rrset=/label3 type=TXT version=%FD%0D%05 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1011// /label3 10 TXT Hello
1012// /label3 10 TXT World
1013
1014// ; rrset=/label3/TXT type=DOE version=%FD%00%00%01b%26e%AE%98 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA
1015// /label3/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU
1016// /label3/TXT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ=
1017
1018// )VALUE";
1019
1020// BOOST_CHECK(testOutput.is_equal(expectedValue));
1021// }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -08001022
Yumin Xia9d110ce2016-11-15 14:03:14 -08001023BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture)
1024{
1025 Name zoneName("/ndns-test");
1026 m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
1027 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
1028 rf.checkZoneKey();
Yumin Xiad4e8ce52017-03-17 19:56:52 -07001029 Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {"Value1", "Value2"});
Jiewen Tan870b29b2014-11-17 19:09:49 -08001030
Yumin Xia9d110ce2016-11-15 14:03:14 -08001031 m_tool.addRrset(rrset1);
Jiewen Tan870b29b2014-11-17 19:09:49 -08001032
Yumin Xia2c509c22017-02-09 14:37:36 -08001033 std::stringstream os;
1034
1035 using security::transform::base64Encode;
1036 using security::transform::streamSink;
1037 using security::transform::bufferSource;
1038
Davide Pesavento98026122022-03-14 22:00:03 -04001039 bufferSource(rrset1.getData()) >> base64Encode() >> streamSink(os);
Yumin Xia2c509c22017-02-09 14:37:36 -08001040
1041 std::string expectedValue = os.str();
Jiewen Tan870b29b2014-11-17 19:09:49 -08001042
Yumin Xia9d110ce2016-11-15 14:03:14 -08001043 output_test_stream testOutput;
1044 m_tool.getRrSet(zoneName, "/label",label::TXT_RR_TYPE, testOutput);
Yumin Xia9d110ce2016-11-15 14:03:14 -08001045 BOOST_CHECK(testOutput.is_equal(expectedValue));
1046}
Jiewen Tan870b29b2014-11-17 19:09:49 -08001047
Yumin Xia9d110ce2016-11-15 14:03:14 -08001048BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture)
1049{
1050 Name zoneName("/ndns-test");
Jiewen Tan870b29b2014-11-17 19:09:49 -08001051
Yumin Xia9d110ce2016-11-15 14:03:14 -08001052 m_tool.createZone(zoneName, ROOT_ZONE);
1053 RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT);
1054 rf.checkZoneKey();
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -08001055
Yumin Xiad4e8ce52017-03-17 19:56:52 -07001056 Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {});
Jiewen Tan870b29b2014-11-17 19:09:49 -08001057
Yumin Xia9d110ce2016-11-15 14:03:14 -08001058 BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -08001059
Yumin Xia9d110ce2016-11-15 14:03:14 -08001060 Zone zone(zoneName);
Yumin Xiad4e8ce52017-03-17 19:56:52 -07001061 BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::TXT_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -08001062
Yumin Xia9d110ce2016-11-15 14:03:14 -08001063 BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -08001064
Yumin Xia9d110ce2016-11-15 14:03:14 -08001065 BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error);
1066}
Jiewen Tan870b29b2014-11-17 19:09:49 -08001067
1068BOOST_AUTO_TEST_SUITE_END()
1069
1070} // namespace tests
1071} // namespace ndns
1072} // namespace ndn