blob: b61ac869b425d1f12e43af1aa9ef47bff8672687 [file] [log] [blame]
Jiewen Tan870b29b2014-11-17 19:09:49 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi767f35c2016-07-23 01:54:42 +00003 * Copyright (c) 2014-2016, 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"
Jiewen Tan870b29b2014-11-17 19:09:49 -080021
22#include "ndns-enum.hpp"
23#include "ndns-label.hpp"
24#include "ndns-tlv.hpp"
25
Jiewen Tan870b29b2014-11-17 19:09:49 -080026#include <boost/algorithm/string/replace.hpp>
27
Jiewen Tan870b29b2014-11-17 19:09:49 -080028#include <ndn-cxx/util/io.hpp>
29#include <ndn-cxx/util/regex.hpp>
30
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080031#include "test-common.hpp"
32
33using boost::test_tools::output_test_stream;
34
Jiewen Tan870b29b2014-11-17 19:09:49 -080035namespace ndn {
36namespace ndns {
37namespace tests {
38
39BOOST_AUTO_TEST_SUITE(ManagementTool)
40
41static const boost::filesystem::path TEST_DATABASE = TEST_CONFIG_PATH "/management_tool.db";
42static const boost::filesystem::path TEST_CERTDIR = TEST_CONFIG_PATH "/management_tool_certs";
43static const Name FAKE_ROOT("/fake-root/123456789");
44
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080045/**
46 * @brief Recursive copy a directory using Boost Filesystem
47 *
48 * Based on from http://stackoverflow.com/q/8593608/2150331
49 */
50void
51copyDir(const boost::filesystem::path& source, const boost::filesystem::path& destination)
52{
53 namespace fs = boost::filesystem;
54
55 fs::create_directory(destination);
56 for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file) {
57 fs::path current(file->path());
58 if (is_directory(current)) {
59 copyDir(current, destination / current.filename());
60 }
61 else {
62 // cannot use fs::copy_file, see https://svn.boost.org/trac/boost/ticket/10038
63 // fs::copy works, as it doesn't use problematic private API
64 copy(current, destination / current.filename());
65 }
66 }
67}
68
69class TestHome : boost::noncopyable
Jiewen Tan870b29b2014-11-17 19:09:49 -080070{
71public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080072 TestHome()
73 {
74 if (std::getenv("HOME"))
75 m_origHome = std::getenv("HOME");
76
77 setenv("HOME", TEST_CONFIG_PATH "/tests/unit/mgmt/", 1);
78 boost::filesystem::remove_all(TEST_CONFIG_PATH "/tests/unit/mgmt/");
79 boost::filesystem::create_directories(TEST_CONFIG_PATH "/tests/unit/mgmt");
80 copyDir("tests/unit/mgmt/.ndn", TEST_CONFIG_PATH "/tests/unit/mgmt/.ndn");
81 }
82
83 ~TestHome()
84 {
85 if (!m_origHome.empty())
86 setenv("HOME", m_origHome.c_str(), 1);
87 else
88 unsetenv("HOME");
89 }
90
91protected:
92 std::string m_origHome;
93};
94
95
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080096class ManagementToolFixture : public TestHome, public IdentityManagementFixture
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080097{
98public:
99 class Error : public std::runtime_error
100 {
101 public:
102 explicit
103 Error(const std::string& what)
104 : std::runtime_error(what)
105 {
106 }
107 };
108
109 class PreviousStateCleaner
110 {
111 public:
112 PreviousStateCleaner()
113 {
114 boost::filesystem::remove(TEST_DATABASE);
115 boost::filesystem::remove_all(TEST_CERTDIR);
116 }
117 };
118
Jiewen Tan870b29b2014-11-17 19:09:49 -0800119 ManagementToolFixture()
Alexander Afanasyevfde570c2016-12-19 16:02:55 -0800120 : m_tool(TEST_DATABASE.string().c_str(), m_keyChain)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800121 , m_dbMgr(TEST_DATABASE.string().c_str())
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800122
123 , rootKsk("/KEY/ksk-1416974006376/ID-CERT/%FD%00%00%01I%EA%3Bx%BD")
124 , rootDsk("/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28")
125
126 , otherKsk("/ndns-test/KEY/ksk-1416974006577/ID-CERT/%FD%00%00%01I%EA%3By%7F")
127 , otherDsk("/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E")
Jiewen Tan870b29b2014-11-17 19:09:49 -0800128 {
129 boost::filesystem::create_directory(TEST_CERTDIR);
130 }
131
132 ~ManagementToolFixture()
133 {
Jiewen Tan870b29b2014-11-17 19:09:49 -0800134 }
135
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800136 std::vector<Name>
137 getKeys(const Name& identity)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800138 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800139 std::vector<Name> keys;
140 m_keyChain.getAllKeyNamesOfIdentity(identity, keys, false);
141 m_keyChain.getAllKeyNamesOfIdentity(identity, keys, true);
142 return keys;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800143 }
144
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800145 std::vector<Name>
146 getCerts(const Name& identity)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800147 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800148 std::vector<Name> certs;
149 for (auto&& name : getKeys(identity)) {
150 m_keyChain.getAllCertificateNamesOfKey(name, certs, false);
151 m_keyChain.getAllCertificateNamesOfKey(name, certs, true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800152 }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800153 return certs;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800154 }
155
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800156 Rrset
157 findRrSet(Zone& zone, const Name& label, const name::Component& type)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800158 {
159 Rrset rrset(&zone);
160 rrset.setLabel(label);
161 rrset.setType(type);
162
163 if (!m_dbMgr.find(rrset))
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800164 throw Error("Record not found");
165 else
166 return rrset;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800167 }
168
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800169 Name
170 getLabel(const Zone& zone, const Name& fullName)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800171 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800172 size_t zoneNameSize = zone.getName().size();
173 return fullName.getSubName(zoneNameSize + 1, fullName.size() - zoneNameSize - 3);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800174 }
175
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800176 IdentityCertificate
177 findIdCert(Zone& zone, const Name& fullName)
178 {
179 Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE);
180 IdentityCertificate cert;
181 cert.wireDecode(rrset.getData());
182 return cert;
183 }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800184
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800185 Response
186 findResponse(Zone& zone, const Name& label, const name::Component& type)
187 {
188 Rrset rrset = findRrSet(zone, label, type);
189 Data data(rrset.getData());
190 Response resp;
191 resp.fromData("", zone.getName(), data);
192 return resp;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800193 }
194
195public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800196 PreviousStateCleaner cleaner; // must be first variable
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800197 ndns::ManagementTool m_tool;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800198 ndns::DbMgr m_dbMgr;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800199
200 // Names of pre-created certificates
201 // Uncomment and run InitPreconfiguredKeys test case and then update names in the
202 // constructor.
203 Name rootKsk;
204 Name rootDsk;
205 Name otherKsk;
206 Name otherDsk;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800207};
208
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800209// BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture)
210// {
211// using time::seconds;
212
213// auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name {
214// // to re-generate certificates, uncomment and then update rootKsk/rootDsk names
215// Name kskName = m_keyChain.generateRsaKeyPair(zone, true);
216// auto kskCert = m_keyChain
217// .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)),
218// time::fromUnixTimestamp(seconds(2147483648)), {});
219// if (parentCert.empty()) {
220// m_keyChain.selfSign(*kskCert);
221// }
222// else {
223// m_keyChain.sign(*kskCert, parentCert);
224// }
225// m_keyChain.addCertificate(*kskCert);
226
227// Name dskName = m_keyChain.generateRsaKeyPair(zone, false);
228// auto dskCert = m_keyChain
229// .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)),
230// time::fromUnixTimestamp(seconds(2147483648)), {});
231// m_keyChain.sign(*dskCert, kskCert->getName());
232// m_keyChain.addCertificate(*dskCert);
233
234// return dskCert->getName();
235// };
236
237// Name rootDsk = generateCerts(ROOT_ZONE);
238// generateCerts("/ndns-test", rootDsk);
239
240// copyDir(TEST_CONFIG_PATH "/tests/unit/mgmt/.ndn", "/tmp/.ndn");
241// std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl;
242// }
243
244BOOST_FIXTURE_TEST_CASE(CreateDeleteRootZone, ManagementToolFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800245{
Jiewen Tan870b29b2014-11-17 19:09:49 -0800246 m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(4600), time::seconds(4600),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800247 rootKsk, rootDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800248
249 Zone zone(ROOT_ZONE);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800250 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
251 BOOST_REQUIRE_NO_THROW(findIdCert(zone, rootDsk));
252 BOOST_CHECK_EQUAL(findIdCert(zone, rootDsk).getName(), rootDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800253
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800254 BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE));
255 BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800256}
257
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800258BOOST_FIXTURE_TEST_CASE(CreateDeleteChildZone, ManagementToolFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800259{
Jiewen Tan870b29b2014-11-17 19:09:49 -0800260 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800261 Name zoneName = Name(parentZoneName).append("child-zone");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800262
263 BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), false);
264
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800265 // will generate keys automatically
266 m_tool.createZone(zoneName, parentZoneName);
267 BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800268
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800269 std::vector<Name>&& certs = getCerts(zoneName);
270 BOOST_REQUIRE_EQUAL(certs.size(), 2);
271 std::sort(certs.begin(), certs.end());
272
273 // Name& ksk = certs[0];
274 Name& dsk = certs[1];
Jiewen Tan870b29b2014-11-17 19:09:49 -0800275
276 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800277 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
278 BOOST_REQUIRE_NO_THROW(findIdCert(zone, dsk));
279 BOOST_CHECK_EQUAL(findIdCert(zone, dsk).getName(), dsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800280
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800281 BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800282
283 BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800284 BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error);
285}
286
287BOOST_FIXTURE_TEST_CASE(CreateZoneWithTtl, ManagementToolFixture)
288{
289 Name parentZoneName("/ndns-test");
290 Name zoneName = Name(parentZoneName).append("child-zone");
291
292 m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30));
293 BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), true);
294
295 std::vector<Name>&& certs = getCerts(zoneName);
296 BOOST_REQUIRE_EQUAL(certs.size(), 2);
297 std::sort(certs.begin(), certs.end());
298
299 // Name& ksk = certs[0];
300 Name& dsk = certs[1];
301
302 // Check zone ttl
303 Zone zone(zoneName);
304 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
305 BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200));
306
307 // Check dsk rrset ttl
308 Rrset rrset;
309 BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE));
310 BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200));
311
312 // Check certificate freshnessPeriod and validity
313 IdentityCertificate cert;
314 BOOST_REQUIRE_NO_THROW(cert = findIdCert(zone, dsk));
315 BOOST_CHECK_EQUAL(cert.getMetaInfo().getFreshnessPeriod(), time::seconds(4200));
316 BOOST_CHECK_EQUAL(cert.getNotAfter() - cert.getNotBefore(), time::days(30));
317
318 m_tool.deleteZone(zoneName);
319}
320
321BOOST_FIXTURE_TEST_CASE(ZoneCreatePreconditions, ManagementToolFixture)
322{
323 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net"));
324 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error);
325
326 std::vector<Name>&& certs = getCerts("/net/ndnsim");
327 BOOST_REQUIRE_EQUAL(certs.size(), 2);
328 std::sort(certs.begin(), certs.end());
329
330 Name& ksk = certs[0];
331 Name& dsk = certs[1];
332
333 m_tool.deleteZone("/net/ndnsim");
334 // identity will still exist after the zone is deleted
335
336 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error);
337
338 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error);
339
340 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
341 time::seconds(1), time::days(1), ksk, dsk));
342 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2);
343 m_tool.deleteZone("/net/ndnsim");
344
Jiewen Tan01693fd2015-03-25 20:34:45 -0700345 // no ksk and dsk will be generated
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800346 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
347 time::seconds(1), time::days(1), Name(), dsk));
Jiewen Tan01693fd2015-03-25 20:34:45 -0700348 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800349 m_tool.deleteZone("/net/ndnsim");
350
351 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
352 time::seconds(1), time::days(1), ksk, Name()));
Jiewen Tan01693fd2015-03-25 20:34:45 -0700353 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 3);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800354 m_tool.deleteZone("/net/ndnsim");
355
356 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
357 time::seconds(1), time::days(1), "/com/ndnsim"),
358 ndns::ManagementTool::Error);
359
360 m_keyChain.deleteIdentity("/net/ndnsim");
361 Name cert = m_keyChain.createIdentity("/net/ndnsim");
362 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net",
363 time::seconds(1), time::days(1), cert));
364
365 cert = m_keyChain.createIdentity("/com/ndnsim");
366 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
367 time::seconds(1), time::days(1), cert),
368 ndns::ManagementTool::Error);
369
370 cert = m_keyChain.createIdentity("/net/ndnsim/www");
371 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
372 time::seconds(1), time::days(1), cert),
373 ndns::ManagementTool::Error);
374
375 cert = m_keyChain.createIdentity("/net/ndnsim");
376 m_keyChain.deleteKeyPairInTpm(m_keyChain.getCertificate(cert)->getPublicKeyName());
377 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
378 time::seconds(1), time::days(1), cert),
379 ndns::ManagementTool::Error);
380
381 // for root zone special case (requires a valid KSK to be specified)
382 BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error);
383
384 BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1),
385 rootKsk));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800386}
387
388class OutputTester
389{
390public:
391 OutputTester()
392 : savedBuf(std::clog.rdbuf())
393 {
394 std::cout.rdbuf(buffer.rdbuf());
395 }
396
397 ~OutputTester()
398 {
399 std::cout.rdbuf(savedBuf);
400 }
401
402public:
403 std::stringstream buffer;
404 std::streambuf* savedBuf;
405};
406
407BOOST_FIXTURE_TEST_CASE(ExportCertificate, ManagementToolFixture)
408{
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800409 std::string outputFile = TEST_CERTDIR.string() + "/ss.cert";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800410
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800411 BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile),
412 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800413
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800414 BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false);
415 // doesn't check the zone, export from KeyChain directly
416 BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
417 BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800418
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800419 std::string dskValue =
420 "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n"
421 "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n"
422 "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n"
423 "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n"
424 "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n"
425 "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n"
426 "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n"
427 "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n"
428 "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n"
429 "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n"
430 "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n"
431 "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n"
432 "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n"
433 "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n"
434 "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n"
435 "8UNqhMpjAZwW6pdvOZADVg==\n";
436
437 {
438 std::ifstream ifs(outputFile.c_str());
439 std::string actualValue((std::istreambuf_iterator<char>(ifs)),
440 std::istreambuf_iterator<char>());
441 BOOST_CHECK_EQUAL(actualValue, dskValue);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800442 }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800443 boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800444
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800445 // doesn't check the zone, export from KeyChain directly
446 BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile));
447 boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800448
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800449 Name zoneName("/ndns-test");
450 m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30),
451 otherKsk, otherDsk);
452
453 m_keyChain.deleteCertificate(otherKsk);
454 m_keyChain.deleteCertificate(otherDsk);
455
456 // retrieve cert from the zone
457 BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
458 {
459 std::ifstream ifs(outputFile.c_str());
460 std::string actualValue((std::istreambuf_iterator<char>(ifs)),
461 std::istreambuf_iterator<char>());
462 BOOST_CHECK_EQUAL(actualValue, dskValue);
463 }
464 boost::filesystem::remove(outputFile);
465
466 BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile),
467 ndns::ManagementTool::Error);
468
469 // output to std::cout
Jiewen Tan870b29b2014-11-17 19:09:49 -0800470 std::string acutalOutput;
471 {
472 OutputTester tester;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800473 m_tool.exportCertificate(otherDsk, "-");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800474 acutalOutput = tester.buffer.str();
475 }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800476 BOOST_CHECK_EQUAL(acutalOutput, dskValue);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800477}
478
479BOOST_FIXTURE_TEST_CASE(AddRrSet1, ManagementToolFixture)
480{
481 // check pre-condition
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800482 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_RESP),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800483 ndns::ManagementTool::Error);
484
485 Name zoneName("/ndns-test");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800486 Zone zone(zoneName);
487 m_dbMgr.insert(zone);
488
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800489 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_UNKNOWN),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800490 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800491 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, "/test", label::CERT_RR_TYPE, NDNS_RAW),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800492 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800493 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_RAW),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800494 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800495 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::TXT_RR_TYPE, NDNS_RAW),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800496 ndns::ManagementTool::Error);
497
498 m_dbMgr.remove(zone);
499}
500
501BOOST_FIXTURE_TEST_CASE(AddRrSet2, ManagementToolFixture)
502{
503 Name zoneName("/ndns-test");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800504 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800505
Jiewen Tan870b29b2014-11-17 19:09:49 -0800506 uint64_t version = 1234;
507 time::seconds ttl1(4200);
508 time::seconds ttl2(4500);
509 m_tool.createZone(zoneName, ROOT_ZONE, ttl1);
510
511 //add NS NDNS_AUTH and check user-defined ttl
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800512 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l1", label::NS_RR_TYPE, NDNS_AUTH, 7654,
Jiewen Tan870b29b2014-11-17 19:09:49 -0800513 {}, DEFAULT_CERT, ttl2));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800514 Response response;
515 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l1", label::NS_RR_TYPE));
516 BOOST_CHECK_EQUAL(response.getNdnsType(), NDNS_AUTH);
517 BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(7654));
518 BOOST_CHECK_EQUAL(response.getFreshnessPeriod(), ttl2);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800519
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800520 // add NS NDNS_RESP and check default ttl
521 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l2", label::NS_RR_TYPE, NDNS_RESP, 15));
522 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", label::NS_RR_TYPE));
523 BOOST_CHECK_EQUAL(response.getNdnsType(), NDNS_RESP);
524 BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(15));
525 BOOST_CHECK_EQUAL(response.getFreshnessPeriod(), ttl1);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800526
527 //add TXT NDNS_RESP and check rr
528 std::string test = "oops";
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800529 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l2", label::TXT_RR_TYPE, NDNS_RESP, version,
530 {"oops", "again"}));
531 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", label::TXT_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800532
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800533 BOOST_REQUIRE_EQUAL(response.getRrs().size(), 2);
534 {
535 const Block& block = response.getRrs()[0];
536 std::string someString(reinterpret_cast<const char*>(block.value()), block.value_size());
537 BOOST_CHECK_EQUAL("oops", someString);
538 }
539
540 {
541 const Block& block = response.getRrs()[1];
542 std::string someString(reinterpret_cast<const char*>(block.value()), block.value_size());
543 BOOST_CHECK_EQUAL("again", someString);
544 }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800545
546 //add user defined type
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800547 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, "/l2", name::Component("USER-DEFINED"), NDNS_RAW,
548 1112223, {"10.10.0.1", "SECOND_INVALID_DATA"}),
549 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800550
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800551 m_tool.addRrSet(zoneName, "/l2", name::Component("USER-DEFINED"), NDNS_RAW, 1112223,
552 {"10.10.0.1"});
553 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", name::Component("USER-DEFINED")));
554 BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(1112223));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800555
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800556 std::string actualValue(reinterpret_cast<const char*>(response.getAppContent().value()),
557 response.getAppContent().value_size());
558 BOOST_CHECK_EQUAL(actualValue, "10.10.0.1");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800559}
560
561BOOST_FIXTURE_TEST_CASE(AddRrSet3, ManagementToolFixture)
562{
563 // check pre-condition
564 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800565
Jiewen Tan870b29b2014-11-17 19:09:49 -0800566 std::string certPath = TEST_CERTDIR.string();
567 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
568
569 m_tool.createZone(zoneName, ROOT_ZONE);
570 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800571}
572
573BOOST_FIXTURE_TEST_CASE(AddRrSet4, ManagementToolFixture)
574{
575 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800576 Name zoneName = Name(parentZoneName).append("/child-zone");
577
578 Zone parentZone(parentZoneName);
579
580 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800581 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800582
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800583 std::vector<Name>&& certs = getCerts(zoneName);
584 BOOST_REQUIRE_EQUAL(certs.size(), 2);
585 std::sort(certs.begin(), certs.end());
586
587 Name& ksk = certs[0];
588 // Name& dsk = certs[1];
589
Jiewen Tan870b29b2014-11-17 19:09:49 -0800590 std::string output = TEST_CERTDIR.string() + "/ss.cert";
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800591 m_tool.exportCertificate(ksk, output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800592
Jiewen Tan870b29b2014-11-17 19:09:49 -0800593 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800594 BOOST_CHECK_NO_THROW(findIdCert(parentZone, ksk));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800595
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800596 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, "/child-zone",
597 label::NS_RR_TYPE, NDNS_RESP));
598 BOOST_CHECK_NO_THROW(findRrSet(parentZone, "/child-zone", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800599
600 //add KSK ID-CERT with illegal name and convert it
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800601 Name iZoneName = Name(parentZoneName).append("illegal");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800602 Name illegalCertName = m_keyChain.createIdentity(iZoneName);
603 m_tool.exportCertificate(illegalCertName, output);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800604 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800605
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800606 Name legalCertName =
607 Name(parentZoneName)
608 .append("KEY")
609 .append("illegal")
610 .append(illegalCertName.getSubName(3));
611 BOOST_CHECK_NO_THROW(findIdCert(parentZone, legalCertName));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800612}
613
614BOOST_FIXTURE_TEST_CASE(AddRrSet5, ManagementToolFixture)
615{
616 //check using user provided certificate
617 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800618 Name zoneName = Name(parentZoneName).append("child-zone");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800619
620 Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false);
621 shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
622 m_keyChain.addCertificateAsKeyDefault(*dskCert);
623
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800624 // check addRrSet1
625 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800626 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800627
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800628 std::vector<Name>&& certs = getCerts(zoneName);
629 BOOST_REQUIRE_EQUAL(certs.size(), 2);
630 std::sort(certs.begin(), certs.end());
631
632 Name& ksk = certs[0];
633 // Name& dsk = certs[1];
634
635 std::string output = TEST_CERTDIR.string() + "/ss.cert";
636 m_tool.exportCertificate(ksk, output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800637
638 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output, time::seconds(4600),
639 dskCert->getName()));
640
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800641 // check addRrSet2
Jiewen Tan870b29b2014-11-17 19:09:49 -0800642 Name label1("/net/ndnsim1");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800643 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, "/l1", label::NS_RR_TYPE, NDNS_AUTH, -1, {},
Jiewen Tan870b29b2014-11-17 19:09:49 -0800644 dskCert->getName()));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800645}
646
Jiewen Tand2d21822015-03-19 15:37:03 -0700647BOOST_FIXTURE_TEST_CASE(AddRrSet6, ManagementToolFixture)
648{
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700649 //check invalid output
Jiewen Tand2d21822015-03-19 15:37:03 -0700650 Name parentZoneName("/ndns-test");
651 Name zoneName = Name(parentZoneName).append("child-zone");
652 m_tool.createZone(zoneName, parentZoneName);
653
Jiewen Tand2d21822015-03-19 15:37:03 -0700654 Name content = "invalid data packet";
655 std::string output = TEST_CERTDIR.string() + "/ss.cert";
656 ndn::io::save(content, output);
657
658 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, output), ndns::ManagementTool::Error);
659}
660
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700661BOOST_FIXTURE_TEST_CASE(AddRrSet7, ManagementToolFixture)
662{
663 //check version control
664 Name parentZoneName("/ndns-test");
665 Name zoneName = Name(parentZoneName).append("child-zone");
666 m_tool.createZone(zoneName, parentZoneName);
667
668 Name label("/label");
669 uint64_t version = 110;
670
671 m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version);
672 // throw error when adding duplicated rrset with the same version
673 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version),
674 ndns::ManagementTool::Error);
675 version--;
676 // throw error when adding duplicated rrset with older version
677 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version),
678 ndns::ManagementTool::Error);
679
680 version++;
681 version++;
682 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version));
683
684 Zone zone(zoneName);
685 m_dbMgr.find(zone);
686 Rrset rrset;
687 rrset.setZone(&zone);
688 rrset.setLabel(label);
689 rrset.setType(label::NS_RR_TYPE);
690 m_dbMgr.find(rrset);
691
692 BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version));
693}
694
Jiewen Tan74d745c2015-03-20 01:40:41 -0700695BOOST_FIXTURE_TEST_CASE(AddRrSet8, ManagementToolFixture)
696{
697 //check input with different formats
698 Name parentZoneName("/ndns-test");
699 Name zoneName = Name(parentZoneName).append("child-zone");
700 m_tool.createZone(zoneName, parentZoneName);
701
702 std::string output = TEST_CERTDIR.string() + "/a.cert";
703
704 // base64
705 Name dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
706 shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
707
Junxiao Shidc2df7c2016-08-31 12:53:14 +0000708 ndn::io::save(*dskCert, output, ndn::io::BASE64);
Jiewen Tan74d745c2015-03-20 01:40:41 -0700709 BOOST_CHECK_NO_THROW(
Junxiao Shidc2df7c2016-08-31 12:53:14 +0000710 m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64));
Jiewen Tan74d745c2015-03-20 01:40:41 -0700711
712 // raw
713 dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
714 dskCert = m_keyChain.selfSign(dskName);
715
716 ndn::io::save(*dskCert, output, ndn::io::NO_ENCODING);
717 BOOST_CHECK_NO_THROW(
718 m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING));
719
720 // hex
721 dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
722 dskCert = m_keyChain.selfSign(dskName);
723
724 ndn::io::save(*dskCert, output, ndn::io::HEX);
725 BOOST_CHECK_NO_THROW(
726 m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX));
727
728 // incorrect encoding input
729 dskName = m_keyChain.generateRsaKeyPair(zoneName, false);
730 dskCert = m_keyChain.selfSign(dskName);
731
732 ndn::io::save(*dskCert, output, ndn::io::HEX);
733 BOOST_CHECK_THROW(
734 m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT,
735 static_cast<ndn::io::IoEncoding>(127)),
736 ndns::ManagementTool::Error);
737}
738
Jiewen Tan870b29b2014-11-17 19:09:49 -0800739BOOST_FIXTURE_TEST_CASE(ListAllZones, ManagementToolFixture)
740{
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800741 m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk);
742 m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800743
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800744 std::string expectedValue =
745 "/ ; default-ttl=1 default-key=/dsk-1416974006466 "
746 "default-certificate=/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28\n"
747 "/ndns-test ; default-ttl=10 default-key=/ndns-test/dsk-1416974006659 "
748 "default-certificate=/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800749
Jiewen Tan870b29b2014-11-17 19:09:49 -0800750 output_test_stream testOutput;
751 m_tool.listAllZones(testOutput);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800752 BOOST_CHECK(testOutput.is_equal(expectedValue));
753}
Jiewen Tan870b29b2014-11-17 19:09:49 -0800754
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800755BOOST_FIXTURE_TEST_CASE(ListZone, ManagementToolFixture)
756{
757 m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
758
759 // Add NS with NDNS_RESP
760 m_tool.addRrSet("/ndns-test", "/label1", label::NS_RR_TYPE, NDNS_RESP, 100);
761
762 // Add NS with NDNS_AUTH
763 m_tool.addRrSet("/ndns-test", "/label2", label::NS_RR_TYPE, NDNS_AUTH, 100000);
764
765 // Add TXT from file
766 std::string output = TEST_CERTDIR.string() + "/a.rrset";
767 Response re1;
768 re1.setZone("/ndns-test");
769 re1.setQueryType(label::NDNS_ITERATIVE_QUERY);
770 re1.setRrLabel("/label2");
771 re1.setRrType(label::TXT_RR_TYPE);
772 re1.setNdnsType(NDNS_RESP);
773 re1.setVersion(name::Component::fromVersion(654321));
774 re1.addRr("First RR");
775 re1.addRr("Second RR");
776 re1.addRr("Last RR");
777 shared_ptr<Data> data1 = re1.toData();
778 m_keyChain.sign(*data1, otherDsk);
779 ndn::io::save(*data1, output);
780 m_tool.addRrSet("/ndns-test", output);
781
782 // Add TXT in normal way
783 m_tool.addRrSet("/ndns-test", "/label3", label::TXT_RR_TYPE, NDNS_RESP, 3333,
784 {"Hello", "World"}, otherDsk);
785
786 // Add User-Defined
787 Response re2;
788 re2.setZone("/ndns-test");
789 re2.setQueryType(label::NDNS_ITERATIVE_QUERY);
790 re2.setRrLabel("/label4");
791 re2.setRrType(name::Component("USER-DEFINED"));
792 re2.setNdnsType(NDNS_RAW);
793 re2.setVersion(name::Component::fromVersion(1234567));
Junxiao Shi767f35c2016-07-23 01:54:42 +0000794 re2.setAppContent(makeBinaryBlock(ndn::tlv::Content, "Hello", sizeof("Hello")));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800795 shared_ptr<Data> data2 = re2.toData();
796 m_keyChain.sign(*data2, otherDsk);
797 ndn::io::save(*data2, output);
798 m_tool.addRrSet("/ndns-test", output);
799
800 output_test_stream testOutput;
801 m_tool.listZone("/ndns-test", testOutput, true);
802
803 std::string expectedValue =
804 "; Zone /ndns-test\n"
805 "\n"
806 "; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
807 "/label1 10 NS \n"
808 "\n"
809 "/label2 10 NS ; content-type=NDNS-Auth version=%FD%00%01%86%A0 "
810 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
811 "\n"
812 "; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 "
813 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
814 "/label2 10 TXT First RR\n"
815 "/label2 10 TXT Second RR\n"
816 "/label2 10 TXT Last RR\n"
817 "\n"
818 "; rrset=/label3 type=TXT version=%FD%0D%05 "
819 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
820 "/label3 10 TXT Hello\n"
821 "/label3 10 TXT World\n"
822 "\n"
823 "/label4 10 USER-DEFINED ; content-type=NDNS-Raw version=%FD%00%12%D6%87 "
824 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
825 "; FQZIZWxsbwA=\n"
826 "\n"
827 "/dsk-1416974006659 10 ID-CERT ; content-type=NDNS-Raw version=%FD%00%00%01I%EA%3Bz%0E "
828 "signed-by=/ndns-test/KEY/ksk-1416974006577/ID-CERT\n"
Jiewen Tand1dd86d2015-03-20 10:26:28 -0700829 "; Certificate name:\n"
830 "; /ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n"
831 "; Validity:\n"
832 "; NotBefore: 19700101T000000\n"
833 "; NotAfter: 20380119T031408\n"
834 "; Subject Description:\n"
835 "; 2.5.4.41: /ndns-test\n"
836 "; Public key bits: (RSA)\n"
837 "; MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAyBVC+xc/JpscSE/JdxbV\n"
838 "; pvgrh/fokNFI/2t9D5inuIFr7cc4W+LyJ4GG1xr9olMx7MHamJU1Xg3VunjhSjL8\n"
839 "; mOaeXlbS6gxWexBCtNK6U4euPB4wks/gMIKdp24mAAFb4T+mBfjcRgR+NdrjyO5C\n"
840 "; 2OqM8qbDZmD/iuEmE6GPXnuMS0o6s13yzMj9YfDh3Df2jZnHESZcmG5Qpgg22T58\n"
841 "; 7t7bRx8Ha2EC3hb29AeYKwgEKDx8JH8ZBJ80AQP321HbyjXWshJLomzy5SJZo9nA\n"
842 "; bZOYlZPCQkomz92Zc9+kpLNQwDvtRLwkZ46B+b2JpKTFARbnvugONCEBuG6zNgoi\n"
843 "; EQIB\n"
844 "; Signature Information:\n"
845 "; Signature Type: Unknown Signature Type\n"
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800846 "\n";
847
848 BOOST_CHECK(testOutput.is_equal(expectedValue));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800849}
850
851BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture)
852{
853 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800854 m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800855
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800856 m_tool.addRrSet(zoneName, "/label", name::Component("TXT"), NDNS_RESP, 100,
857 {"Value1", "Value2"});
Jiewen Tan870b29b2014-11-17 19:09:49 -0800858
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800859 std::string expectedValue =
860 "Bv0BdwchCAluZG5zLXRlc3QIBE5ETlMIBWxhYmVsCANUWFQIAv1kFAcZAgPotAEB\n"
861 "FRC/BlZhbHVlMb8GVmFsdWUyFjMbAQEcLgcsCAluZG5zLXRlc3QIA0tFWQgRZHNr\n"
862 "LTE0MTY5NzQwMDY2NTkIB0lELUNFUlQX/QEAqhzoQmGGeFcUlZ9pEp0ohVoTEw18\n"
863 "qfB1DN6sssOpjCu3V41SHmoybPPkdW84i/h5n6TmuuePWva+fk6l9Xppd3F4lCX0\n"
864 "Tb1lyxjnLaQjBKTYxNReM3h55XY7sCvb2RpFCSDZ/PFfzuCwdWAIqcau10H9IjNm\n"
865 "2NO+m+jW43tnou9TLrNzN80bYFQc4FEwUCJUA4jPf+1NwDUMp9LWN5IILwU+Ttx6\n"
866 "45u2rK6KXfgcHR3zifwi2IZ9mEjr5bhXxvL8zP+tgaPb0t6O9gujry0an2h+hUH5\n"
867 "Aldt49RIyipHXO7R2736ZqkUZ553DSIUhaYPuXRlByNbiW6Za+LMPgJaPg==\n";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800868
Jiewen Tan870b29b2014-11-17 19:09:49 -0800869 output_test_stream testOutput;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800870 m_tool.getRrSet(zoneName, "/label", name::Component("TXT"), testOutput);
871 BOOST_CHECK(testOutput.is_equal(expectedValue));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800872}
873
874BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture)
875{
876 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800877
Jiewen Tan870b29b2014-11-17 19:09:49 -0800878 m_tool.createZone(zoneName, ROOT_ZONE);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800879
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800880 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/label", label::NS_RR_TYPE, NDNS_RESP));
881
Jiewen Tan870b29b2014-11-17 19:09:49 -0800882 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800883 BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800884
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800885 BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800886
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800887 BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800888}
889
890BOOST_AUTO_TEST_SUITE_END()
891
892} // namespace tests
893} // namespace ndns
894} // namespace ndn