blob: f5137e12b7240f016a90bf76921b6742c7f64667 [file] [log] [blame]
Jiewen Tan870b29b2014-11-17 19:09:49 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
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
20#include "../../src/mgmt/management-tool.hpp"
21
22#include "../../boost-test.hpp"
23#include <boost/test/output_test_stream.hpp>
24using boost::test_tools::output_test_stream;
25
26#include "ndns-enum.hpp"
27#include "ndns-label.hpp"
28#include "ndns-tlv.hpp"
29
30#include <vector>
31#include <iostream>
32#include <fstream>
33#include <string>
34
35#include <boost/filesystem.hpp>
36#include <boost/algorithm/string/replace.hpp>
37
38#include <ndn-cxx/security/key-chain.hpp>
39#include <ndn-cxx/security/validator.hpp>
40#include <ndn-cxx/util/io.hpp>
41#include <ndn-cxx/util/regex.hpp>
42
43namespace ndn {
44namespace ndns {
45namespace tests {
46
47BOOST_AUTO_TEST_SUITE(ManagementTool)
48
49static const boost::filesystem::path TEST_DATABASE = TEST_CONFIG_PATH "/management_tool.db";
50static const boost::filesystem::path TEST_CERTDIR = TEST_CONFIG_PATH "/management_tool_certs";
51static const Name FAKE_ROOT("/fake-root/123456789");
52
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080053
54/**
55 * @brief Recursive copy a directory using Boost Filesystem
56 *
57 * Based on from http://stackoverflow.com/q/8593608/2150331
58 */
59void
60copyDir(const boost::filesystem::path& source, const boost::filesystem::path& destination)
61{
62 namespace fs = boost::filesystem;
63
64 fs::create_directory(destination);
65 for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file) {
66 fs::path current(file->path());
67 if (is_directory(current)) {
68 copyDir(current, destination / current.filename());
69 }
70 else {
71 // cannot use fs::copy_file, see https://svn.boost.org/trac/boost/ticket/10038
72 // fs::copy works, as it doesn't use problematic private API
73 copy(current, destination / current.filename());
74 }
75 }
76}
77
78class TestHome : boost::noncopyable
Jiewen Tan870b29b2014-11-17 19:09:49 -080079{
80public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080081 TestHome()
82 {
83 if (std::getenv("HOME"))
84 m_origHome = std::getenv("HOME");
85
86 setenv("HOME", TEST_CONFIG_PATH "/tests/unit/mgmt/", 1);
87 boost::filesystem::remove_all(TEST_CONFIG_PATH "/tests/unit/mgmt/");
88 boost::filesystem::create_directories(TEST_CONFIG_PATH "/tests/unit/mgmt");
89 copyDir("tests/unit/mgmt/.ndn", TEST_CONFIG_PATH "/tests/unit/mgmt/.ndn");
90 }
91
92 ~TestHome()
93 {
94 if (!m_origHome.empty())
95 setenv("HOME", m_origHome.c_str(), 1);
96 else
97 unsetenv("HOME");
98 }
99
100protected:
101 std::string m_origHome;
102};
103
104
105class ManagementToolFixture : public TestHome
106{
107public:
108 class Error : public std::runtime_error
109 {
110 public:
111 explicit
112 Error(const std::string& what)
113 : std::runtime_error(what)
114 {
115 }
116 };
117
118 class PreviousStateCleaner
119 {
120 public:
121 PreviousStateCleaner()
122 {
123 boost::filesystem::remove(TEST_DATABASE);
124 boost::filesystem::remove_all(TEST_CERTDIR);
125 }
126 };
127
Jiewen Tan870b29b2014-11-17 19:09:49 -0800128 ManagementToolFixture()
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800129 : m_keyChain("sqlite3", "file")
130 , m_tool(TEST_DATABASE.string().c_str(), m_keyChain)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800131 , m_dbMgr(TEST_DATABASE.string().c_str())
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800132
133 , rootKsk("/KEY/ksk-1416974006376/ID-CERT/%FD%00%00%01I%EA%3Bx%BD")
134 , rootDsk("/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28")
135
136 , otherKsk("/ndns-test/KEY/ksk-1416974006577/ID-CERT/%FD%00%00%01I%EA%3By%7F")
137 , otherDsk("/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E")
Jiewen Tan870b29b2014-11-17 19:09:49 -0800138 {
139 boost::filesystem::create_directory(TEST_CERTDIR);
140 }
141
142 ~ManagementToolFixture()
143 {
Jiewen Tan870b29b2014-11-17 19:09:49 -0800144 }
145
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800146 std::vector<Name>
147 getKeys(const Name& identity)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800148 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800149 std::vector<Name> keys;
150 m_keyChain.getAllKeyNamesOfIdentity(identity, keys, false);
151 m_keyChain.getAllKeyNamesOfIdentity(identity, keys, true);
152 return keys;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800153 }
154
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800155 std::vector<Name>
156 getCerts(const Name& identity)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800157 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800158 std::vector<Name> certs;
159 for (auto&& name : getKeys(identity)) {
160 m_keyChain.getAllCertificateNamesOfKey(name, certs, false);
161 m_keyChain.getAllCertificateNamesOfKey(name, certs, true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800162 }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800163 return certs;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800164 }
165
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800166 Rrset
167 findRrSet(Zone& zone, const Name& label, const name::Component& type)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800168 {
169 Rrset rrset(&zone);
170 rrset.setLabel(label);
171 rrset.setType(type);
172
173 if (!m_dbMgr.find(rrset))
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800174 throw Error("Record not found");
175 else
176 return rrset;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800177 }
178
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800179 Name
180 getLabel(const Zone& zone, const Name& fullName)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800181 {
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800182 size_t zoneNameSize = zone.getName().size();
183 return fullName.getSubName(zoneNameSize + 1, fullName.size() - zoneNameSize - 3);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800184 }
185
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800186 IdentityCertificate
187 findIdCert(Zone& zone, const Name& fullName)
188 {
189 Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE);
190 IdentityCertificate cert;
191 cert.wireDecode(rrset.getData());
192 return cert;
193 }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800194
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800195 Response
196 findResponse(Zone& zone, const Name& label, const name::Component& type)
197 {
198 Rrset rrset = findRrSet(zone, label, type);
199 Data data(rrset.getData());
200 Response resp;
201 resp.fromData("", zone.getName(), data);
202 return resp;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800203 }
204
205public:
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800206 PreviousStateCleaner cleaner; // must be first variable
Jiewen Tan870b29b2014-11-17 19:09:49 -0800207 ndn::KeyChain m_keyChain;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800208 ndns::ManagementTool m_tool;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800209 ndns::DbMgr m_dbMgr;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800210
211 // Names of pre-created certificates
212 // Uncomment and run InitPreconfiguredKeys test case and then update names in the
213 // constructor.
214 Name rootKsk;
215 Name rootDsk;
216 Name otherKsk;
217 Name otherDsk;
Jiewen Tan870b29b2014-11-17 19:09:49 -0800218};
219
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800220// BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture)
221// {
222// using time::seconds;
223
224// auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name {
225// // to re-generate certificates, uncomment and then update rootKsk/rootDsk names
226// Name kskName = m_keyChain.generateRsaKeyPair(zone, true);
227// auto kskCert = m_keyChain
228// .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)),
229// time::fromUnixTimestamp(seconds(2147483648)), {});
230// if (parentCert.empty()) {
231// m_keyChain.selfSign(*kskCert);
232// }
233// else {
234// m_keyChain.sign(*kskCert, parentCert);
235// }
236// m_keyChain.addCertificate(*kskCert);
237
238// Name dskName = m_keyChain.generateRsaKeyPair(zone, false);
239// auto dskCert = m_keyChain
240// .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)),
241// time::fromUnixTimestamp(seconds(2147483648)), {});
242// m_keyChain.sign(*dskCert, kskCert->getName());
243// m_keyChain.addCertificate(*dskCert);
244
245// return dskCert->getName();
246// };
247
248// Name rootDsk = generateCerts(ROOT_ZONE);
249// generateCerts("/ndns-test", rootDsk);
250
251// copyDir(TEST_CONFIG_PATH "/tests/unit/mgmt/.ndn", "/tmp/.ndn");
252// std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl;
253// }
254
255BOOST_FIXTURE_TEST_CASE(CreateDeleteRootZone, ManagementToolFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800256{
Jiewen Tan870b29b2014-11-17 19:09:49 -0800257 m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(4600), time::seconds(4600),
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800258 rootKsk, rootDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800259
260 Zone zone(ROOT_ZONE);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800261 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
262 BOOST_REQUIRE_NO_THROW(findIdCert(zone, rootDsk));
263 BOOST_CHECK_EQUAL(findIdCert(zone, rootDsk).getName(), rootDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800264
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800265 BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE));
266 BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800267}
268
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800269BOOST_FIXTURE_TEST_CASE(CreateDeleteChildZone, ManagementToolFixture)
Jiewen Tan870b29b2014-11-17 19:09:49 -0800270{
Jiewen Tan870b29b2014-11-17 19:09:49 -0800271 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800272 Name zoneName = Name(parentZoneName).append("child-zone");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800273
274 BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), false);
275
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800276 // will generate keys automatically
277 m_tool.createZone(zoneName, parentZoneName);
278 BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800279
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800280 std::vector<Name>&& certs = getCerts(zoneName);
281 BOOST_REQUIRE_EQUAL(certs.size(), 2);
282 std::sort(certs.begin(), certs.end());
283
284 // Name& ksk = certs[0];
285 Name& dsk = certs[1];
Jiewen Tan870b29b2014-11-17 19:09:49 -0800286
287 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800288 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
289 BOOST_REQUIRE_NO_THROW(findIdCert(zone, dsk));
290 BOOST_CHECK_EQUAL(findIdCert(zone, dsk).getName(), dsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800291
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800292 BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800293
294 BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800295 BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error);
296}
297
298BOOST_FIXTURE_TEST_CASE(CreateZoneWithTtl, ManagementToolFixture)
299{
300 Name parentZoneName("/ndns-test");
301 Name zoneName = Name(parentZoneName).append("child-zone");
302
303 m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30));
304 BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), true);
305
306 std::vector<Name>&& certs = getCerts(zoneName);
307 BOOST_REQUIRE_EQUAL(certs.size(), 2);
308 std::sort(certs.begin(), certs.end());
309
310 // Name& ksk = certs[0];
311 Name& dsk = certs[1];
312
313 // Check zone ttl
314 Zone zone(zoneName);
315 BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true);
316 BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200));
317
318 // Check dsk rrset ttl
319 Rrset rrset;
320 BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE));
321 BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200));
322
323 // Check certificate freshnessPeriod and validity
324 IdentityCertificate cert;
325 BOOST_REQUIRE_NO_THROW(cert = findIdCert(zone, dsk));
326 BOOST_CHECK_EQUAL(cert.getMetaInfo().getFreshnessPeriod(), time::seconds(4200));
327 BOOST_CHECK_EQUAL(cert.getNotAfter() - cert.getNotBefore(), time::days(30));
328
329 m_tool.deleteZone(zoneName);
330}
331
332BOOST_FIXTURE_TEST_CASE(ZoneCreatePreconditions, ManagementToolFixture)
333{
334 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net"));
335 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error);
336
337 std::vector<Name>&& certs = getCerts("/net/ndnsim");
338 BOOST_REQUIRE_EQUAL(certs.size(), 2);
339 std::sort(certs.begin(), certs.end());
340
341 Name& ksk = certs[0];
342 Name& dsk = certs[1];
343
344 m_tool.deleteZone("/net/ndnsim");
345 // identity will still exist after the zone is deleted
346
347 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error);
348
349 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error);
350
351 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
352 time::seconds(1), time::days(1), ksk, dsk));
353 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2);
354 m_tool.deleteZone("/net/ndnsim");
355
356 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
357 time::seconds(1), time::days(1), Name(), dsk));
358 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 3);
359 m_tool.deleteZone("/net/ndnsim");
360
361 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/",
362 time::seconds(1), time::days(1), ksk, Name()));
363 BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 4);
364 m_tool.deleteZone("/net/ndnsim");
365
366 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
367 time::seconds(1), time::days(1), "/com/ndnsim"),
368 ndns::ManagementTool::Error);
369
370 m_keyChain.deleteIdentity("/net/ndnsim");
371 Name cert = m_keyChain.createIdentity("/net/ndnsim");
372 BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net",
373 time::seconds(1), time::days(1), cert));
374
375 cert = m_keyChain.createIdentity("/com/ndnsim");
376 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
377 time::seconds(1), time::days(1), cert),
378 ndns::ManagementTool::Error);
379
380 cert = m_keyChain.createIdentity("/net/ndnsim/www");
381 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
382 time::seconds(1), time::days(1), cert),
383 ndns::ManagementTool::Error);
384
385 cert = m_keyChain.createIdentity("/net/ndnsim");
386 m_keyChain.deleteKeyPairInTpm(m_keyChain.getCertificate(cert)->getPublicKeyName());
387 BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net",
388 time::seconds(1), time::days(1), cert),
389 ndns::ManagementTool::Error);
390
391 // for root zone special case (requires a valid KSK to be specified)
392 BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error);
393
394 BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1),
395 rootKsk));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800396}
397
398class OutputTester
399{
400public:
401 OutputTester()
402 : savedBuf(std::clog.rdbuf())
403 {
404 std::cout.rdbuf(buffer.rdbuf());
405 }
406
407 ~OutputTester()
408 {
409 std::cout.rdbuf(savedBuf);
410 }
411
412public:
413 std::stringstream buffer;
414 std::streambuf* savedBuf;
415};
416
417BOOST_FIXTURE_TEST_CASE(ExportCertificate, ManagementToolFixture)
418{
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800419 std::string outputFile = TEST_CERTDIR.string() + "/ss.cert";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800420
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800421 BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile),
422 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800423
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800424 BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false);
425 // doesn't check the zone, export from KeyChain directly
426 BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
427 BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800428
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800429 std::string dskValue =
430 "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n"
431 "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n"
432 "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n"
433 "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n"
434 "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n"
435 "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n"
436 "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n"
437 "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n"
438 "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n"
439 "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n"
440 "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n"
441 "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n"
442 "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n"
443 "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n"
444 "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n"
445 "8UNqhMpjAZwW6pdvOZADVg==\n";
446
447 {
448 std::ifstream ifs(outputFile.c_str());
449 std::string actualValue((std::istreambuf_iterator<char>(ifs)),
450 std::istreambuf_iterator<char>());
451 BOOST_CHECK_EQUAL(actualValue, dskValue);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800452 }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800453 boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800454
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800455 // doesn't check the zone, export from KeyChain directly
456 BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile));
457 boost::filesystem::remove(outputFile);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800458
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800459 Name zoneName("/ndns-test");
460 m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30),
461 otherKsk, otherDsk);
462
463 m_keyChain.deleteCertificate(otherKsk);
464 m_keyChain.deleteCertificate(otherDsk);
465
466 // retrieve cert from the zone
467 BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile));
468 {
469 std::ifstream ifs(outputFile.c_str());
470 std::string actualValue((std::istreambuf_iterator<char>(ifs)),
471 std::istreambuf_iterator<char>());
472 BOOST_CHECK_EQUAL(actualValue, dskValue);
473 }
474 boost::filesystem::remove(outputFile);
475
476 BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile),
477 ndns::ManagementTool::Error);
478
479 // output to std::cout
Jiewen Tan870b29b2014-11-17 19:09:49 -0800480 std::string acutalOutput;
481 {
482 OutputTester tester;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800483 m_tool.exportCertificate(otherDsk, "-");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800484 acutalOutput = tester.buffer.str();
485 }
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800486 BOOST_CHECK_EQUAL(acutalOutput, dskValue);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800487}
488
489BOOST_FIXTURE_TEST_CASE(AddRrSet1, ManagementToolFixture)
490{
491 // check pre-condition
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800492 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_RESP),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800493 ndns::ManagementTool::Error);
494
495 Name zoneName("/ndns-test");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800496 Zone zone(zoneName);
497 m_dbMgr.insert(zone);
498
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800499 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_UNKNOWN),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800500 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800501 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, "/test", label::CERT_RR_TYPE, NDNS_RAW),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800502 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800503 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::NS_RR_TYPE, NDNS_RAW),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800504 ndns::ManagementTool::Error);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800505 BOOST_CHECK_THROW(m_tool.addRrSet(ROOT_ZONE, "/test", label::TXT_RR_TYPE, NDNS_RAW),
Jiewen Tan870b29b2014-11-17 19:09:49 -0800506 ndns::ManagementTool::Error);
507
508 m_dbMgr.remove(zone);
509}
510
511BOOST_FIXTURE_TEST_CASE(AddRrSet2, ManagementToolFixture)
512{
513 Name zoneName("/ndns-test");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800514 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800515
Jiewen Tan870b29b2014-11-17 19:09:49 -0800516 uint64_t version = 1234;
517 time::seconds ttl1(4200);
518 time::seconds ttl2(4500);
519 m_tool.createZone(zoneName, ROOT_ZONE, ttl1);
520
521 //add NS NDNS_AUTH and check user-defined ttl
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800522 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l1", label::NS_RR_TYPE, NDNS_AUTH, 7654,
Jiewen Tan870b29b2014-11-17 19:09:49 -0800523 {}, DEFAULT_CERT, ttl2));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800524 Response response;
525 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l1", label::NS_RR_TYPE));
526 BOOST_CHECK_EQUAL(response.getNdnsType(), NDNS_AUTH);
527 BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(7654));
528 BOOST_CHECK_EQUAL(response.getFreshnessPeriod(), ttl2);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800529
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800530 // add NS NDNS_RESP and check default ttl
531 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l2", label::NS_RR_TYPE, NDNS_RESP, 15));
532 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", label::NS_RR_TYPE));
533 BOOST_CHECK_EQUAL(response.getNdnsType(), NDNS_RESP);
534 BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(15));
535 BOOST_CHECK_EQUAL(response.getFreshnessPeriod(), ttl1);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800536
537 //add TXT NDNS_RESP and check rr
538 std::string test = "oops";
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800539 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/l2", label::TXT_RR_TYPE, NDNS_RESP, version,
540 {"oops", "again"}));
541 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", label::TXT_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800542
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800543 BOOST_REQUIRE_EQUAL(response.getRrs().size(), 2);
544 {
545 const Block& block = response.getRrs()[0];
546 std::string someString(reinterpret_cast<const char*>(block.value()), block.value_size());
547 BOOST_CHECK_EQUAL("oops", someString);
548 }
549
550 {
551 const Block& block = response.getRrs()[1];
552 std::string someString(reinterpret_cast<const char*>(block.value()), block.value_size());
553 BOOST_CHECK_EQUAL("again", someString);
554 }
Jiewen Tan870b29b2014-11-17 19:09:49 -0800555
556 //add user defined type
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800557 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, "/l2", name::Component("USER-DEFINED"), NDNS_RAW,
558 1112223, {"10.10.0.1", "SECOND_INVALID_DATA"}),
559 ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800560
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800561 m_tool.addRrSet(zoneName, "/l2", name::Component("USER-DEFINED"), NDNS_RAW, 1112223,
562 {"10.10.0.1"});
563 BOOST_CHECK_NO_THROW(response = findResponse(zone, "/l2", name::Component("USER-DEFINED")));
564 BOOST_CHECK_EQUAL(response.getVersion(), name::Component::fromVersion(1112223));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800565
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800566 std::string actualValue(reinterpret_cast<const char*>(response.getAppContent().value()),
567 response.getAppContent().value_size());
568 BOOST_CHECK_EQUAL(actualValue, "10.10.0.1");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800569}
570
571BOOST_FIXTURE_TEST_CASE(AddRrSet3, ManagementToolFixture)
572{
573 // check pre-condition
574 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800575
Jiewen Tan870b29b2014-11-17 19:09:49 -0800576 std::string certPath = TEST_CERTDIR.string();
577 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
578
579 m_tool.createZone(zoneName, ROOT_ZONE);
580 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800581}
582
583BOOST_FIXTURE_TEST_CASE(AddRrSet4, ManagementToolFixture)
584{
585 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800586 Name zoneName = Name(parentZoneName).append("/child-zone");
587
588 Zone parentZone(parentZoneName);
589
590 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800591 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800592
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800593 std::vector<Name>&& certs = getCerts(zoneName);
594 BOOST_REQUIRE_EQUAL(certs.size(), 2);
595 std::sort(certs.begin(), certs.end());
596
597 Name& ksk = certs[0];
598 // Name& dsk = certs[1];
599
Jiewen Tan870b29b2014-11-17 19:09:49 -0800600 std::string output = TEST_CERTDIR.string() + "/ss.cert";
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800601 m_tool.exportCertificate(ksk, output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800602
Jiewen Tan870b29b2014-11-17 19:09:49 -0800603 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800604 BOOST_CHECK_NO_THROW(findIdCert(parentZone, ksk));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800605
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800606 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, "/child-zone",
607 label::NS_RR_TYPE, NDNS_RESP));
608 BOOST_CHECK_NO_THROW(findRrSet(parentZone, "/child-zone", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800609
610 //add KSK ID-CERT with illegal name and convert it
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800611 Name iZoneName = Name(parentZoneName).append("illegal");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800612 Name illegalCertName = m_keyChain.createIdentity(iZoneName);
613 m_tool.exportCertificate(illegalCertName, output);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800614 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800615
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800616 Name legalCertName =
617 Name(parentZoneName)
618 .append("KEY")
619 .append("illegal")
620 .append(illegalCertName.getSubName(3));
621 BOOST_CHECK_NO_THROW(findIdCert(parentZone, legalCertName));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800622}
623
624BOOST_FIXTURE_TEST_CASE(AddRrSet5, ManagementToolFixture)
625{
626 //check using user provided certificate
627 Name parentZoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800628 Name zoneName = Name(parentZoneName).append("child-zone");
Jiewen Tan870b29b2014-11-17 19:09:49 -0800629
630 Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false);
631 shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName);
632 m_keyChain.addCertificateAsKeyDefault(*dskCert);
633
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800634 // check addRrSet1
635 m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800636 m_tool.createZone(zoneName, parentZoneName);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800637
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800638 std::vector<Name>&& certs = getCerts(zoneName);
639 BOOST_REQUIRE_EQUAL(certs.size(), 2);
640 std::sort(certs.begin(), certs.end());
641
642 Name& ksk = certs[0];
643 // Name& dsk = certs[1];
644
645 std::string output = TEST_CERTDIR.string() + "/ss.cert";
646 m_tool.exportCertificate(ksk, output);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800647
648 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output, time::seconds(4600),
649 dskCert->getName()));
650
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800651 // check addRrSet2
Jiewen Tan870b29b2014-11-17 19:09:49 -0800652 Name label1("/net/ndnsim1");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800653 BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, "/l1", label::NS_RR_TYPE, NDNS_AUTH, -1, {},
Jiewen Tan870b29b2014-11-17 19:09:49 -0800654 dskCert->getName()));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800655}
656
Jiewen Tand2d21822015-03-19 15:37:03 -0700657BOOST_FIXTURE_TEST_CASE(AddRrSet6, ManagementToolFixture)
658{
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700659 //check invalid output
Jiewen Tand2d21822015-03-19 15:37:03 -0700660 Name parentZoneName("/ndns-test");
661 Name zoneName = Name(parentZoneName).append("child-zone");
662 m_tool.createZone(zoneName, parentZoneName);
663
Jiewen Tand2d21822015-03-19 15:37:03 -0700664 Name content = "invalid data packet";
665 std::string output = TEST_CERTDIR.string() + "/ss.cert";
666 ndn::io::save(content, output);
667
668 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, output), ndns::ManagementTool::Error);
669}
670
Jiewen Tan8cd35ea2015-03-20 00:44:23 -0700671BOOST_FIXTURE_TEST_CASE(AddRrSet7, ManagementToolFixture)
672{
673 //check version control
674 Name parentZoneName("/ndns-test");
675 Name zoneName = Name(parentZoneName).append("child-zone");
676 m_tool.createZone(zoneName, parentZoneName);
677
678 Name label("/label");
679 uint64_t version = 110;
680
681 m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version);
682 // throw error when adding duplicated rrset with the same version
683 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version),
684 ndns::ManagementTool::Error);
685 version--;
686 // throw error when adding duplicated rrset with older version
687 BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version),
688 ndns::ManagementTool::Error);
689
690 version++;
691 version++;
692 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, label, label::NS_RR_TYPE, NDNS_RESP, version));
693
694 Zone zone(zoneName);
695 m_dbMgr.find(zone);
696 Rrset rrset;
697 rrset.setZone(&zone);
698 rrset.setLabel(label);
699 rrset.setType(label::NS_RR_TYPE);
700 m_dbMgr.find(rrset);
701
702 BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version));
703}
704
Jiewen Tan870b29b2014-11-17 19:09:49 -0800705BOOST_FIXTURE_TEST_CASE(ListAllZones, ManagementToolFixture)
706{
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800707 m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk);
708 m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800709
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800710 std::string expectedValue =
711 "/ ; default-ttl=1 default-key=/dsk-1416974006466 "
712 "default-certificate=/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28\n"
713 "/ndns-test ; default-ttl=10 default-key=/ndns-test/dsk-1416974006659 "
714 "default-certificate=/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800715
Jiewen Tan870b29b2014-11-17 19:09:49 -0800716 output_test_stream testOutput;
717 m_tool.listAllZones(testOutput);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800718 BOOST_CHECK(testOutput.is_equal(expectedValue));
719}
Jiewen Tan870b29b2014-11-17 19:09:49 -0800720
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800721BOOST_FIXTURE_TEST_CASE(ListZone, ManagementToolFixture)
722{
723 m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk);
724
725 // Add NS with NDNS_RESP
726 m_tool.addRrSet("/ndns-test", "/label1", label::NS_RR_TYPE, NDNS_RESP, 100);
727
728 // Add NS with NDNS_AUTH
729 m_tool.addRrSet("/ndns-test", "/label2", label::NS_RR_TYPE, NDNS_AUTH, 100000);
730
731 // Add TXT from file
732 std::string output = TEST_CERTDIR.string() + "/a.rrset";
733 Response re1;
734 re1.setZone("/ndns-test");
735 re1.setQueryType(label::NDNS_ITERATIVE_QUERY);
736 re1.setRrLabel("/label2");
737 re1.setRrType(label::TXT_RR_TYPE);
738 re1.setNdnsType(NDNS_RESP);
739 re1.setVersion(name::Component::fromVersion(654321));
740 re1.addRr("First RR");
741 re1.addRr("Second RR");
742 re1.addRr("Last RR");
743 shared_ptr<Data> data1 = re1.toData();
744 m_keyChain.sign(*data1, otherDsk);
745 ndn::io::save(*data1, output);
746 m_tool.addRrSet("/ndns-test", output);
747
748 // Add TXT in normal way
749 m_tool.addRrSet("/ndns-test", "/label3", label::TXT_RR_TYPE, NDNS_RESP, 3333,
750 {"Hello", "World"}, otherDsk);
751
752 // Add User-Defined
753 Response re2;
754 re2.setZone("/ndns-test");
755 re2.setQueryType(label::NDNS_ITERATIVE_QUERY);
756 re2.setRrLabel("/label4");
757 re2.setRrType(name::Component("USER-DEFINED"));
758 re2.setNdnsType(NDNS_RAW);
759 re2.setVersion(name::Component::fromVersion(1234567));
760 re2.setAppContent(dataBlock(ndn::tlv::Content, "Hello", sizeof("Hello")));
761 shared_ptr<Data> data2 = re2.toData();
762 m_keyChain.sign(*data2, otherDsk);
763 ndn::io::save(*data2, output);
764 m_tool.addRrSet("/ndns-test", output);
765
766 output_test_stream testOutput;
767 m_tool.listZone("/ndns-test", testOutput, true);
768
769 std::string expectedValue =
770 "; Zone /ndns-test\n"
771 "\n"
772 "; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
773 "/label1 10 NS \n"
774 "\n"
775 "/label2 10 NS ; content-type=NDNS-Auth version=%FD%00%01%86%A0 "
776 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
777 "\n"
778 "; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 "
779 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
780 "/label2 10 TXT First RR\n"
781 "/label2 10 TXT Second RR\n"
782 "/label2 10 TXT Last RR\n"
783 "\n"
784 "; rrset=/label3 type=TXT version=%FD%0D%05 "
785 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
786 "/label3 10 TXT Hello\n"
787 "/label3 10 TXT World\n"
788 "\n"
789 "/label4 10 USER-DEFINED ; content-type=NDNS-Raw version=%FD%00%12%D6%87 "
790 "signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT\n"
791 "; FQZIZWxsbwA=\n"
792 "\n"
793 "/dsk-1416974006659 10 ID-CERT ; content-type=NDNS-Raw version=%FD%00%00%01I%EA%3Bz%0E "
794 "signed-by=/ndns-test/KEY/ksk-1416974006577/ID-CERT\n"
795 "; Ff0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8yMDM4MDExOTAzMTQwOFowEzAR\n"
796 "; BgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3DQEBAQUAA4IBDQAwggEIAoIB\n"
797 "; AQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30PmKe4gWvtxzhb4vIngYbXGv2i\n"
798 "; UzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK00rpTh648HjCSz+Awgp2nbiYA\n"
799 "; AVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYToY9ee4xLSjqzXfLMyP1h8OHc\n"
800 "; N/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0B5grCAQoPHwkfxkEnzQBA/fb\n"
801 "; UdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz36Sks1DAO+1EvCRnjoH5vYmk\n"
802 "; pMUBFue+6A40IQG4brM2CiIRAgER\n"
803 "\n";
804
805 BOOST_CHECK(testOutput.is_equal(expectedValue));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800806}
807
808BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture)
809{
810 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800811 m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800812
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800813 m_tool.addRrSet(zoneName, "/label", name::Component("TXT"), NDNS_RESP, 100,
814 {"Value1", "Value2"});
Jiewen Tan870b29b2014-11-17 19:09:49 -0800815
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800816 std::string expectedValue =
817 "Bv0BdwchCAluZG5zLXRlc3QIBE5ETlMIBWxhYmVsCANUWFQIAv1kFAcZAgPotAEB\n"
818 "FRC/BlZhbHVlMb8GVmFsdWUyFjMbAQEcLgcsCAluZG5zLXRlc3QIA0tFWQgRZHNr\n"
819 "LTE0MTY5NzQwMDY2NTkIB0lELUNFUlQX/QEAqhzoQmGGeFcUlZ9pEp0ohVoTEw18\n"
820 "qfB1DN6sssOpjCu3V41SHmoybPPkdW84i/h5n6TmuuePWva+fk6l9Xppd3F4lCX0\n"
821 "Tb1lyxjnLaQjBKTYxNReM3h55XY7sCvb2RpFCSDZ/PFfzuCwdWAIqcau10H9IjNm\n"
822 "2NO+m+jW43tnou9TLrNzN80bYFQc4FEwUCJUA4jPf+1NwDUMp9LWN5IILwU+Ttx6\n"
823 "45u2rK6KXfgcHR3zifwi2IZ9mEjr5bhXxvL8zP+tgaPb0t6O9gujry0an2h+hUH5\n"
824 "Aldt49RIyipHXO7R2736ZqkUZ553DSIUhaYPuXRlByNbiW6Za+LMPgJaPg==\n";
Jiewen Tan870b29b2014-11-17 19:09:49 -0800825
Jiewen Tan870b29b2014-11-17 19:09:49 -0800826 output_test_stream testOutput;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800827 m_tool.getRrSet(zoneName, "/label", name::Component("TXT"), testOutput);
828 BOOST_CHECK(testOutput.is_equal(expectedValue));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800829}
830
831BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture)
832{
833 Name zoneName("/ndns-test");
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800834
Jiewen Tan870b29b2014-11-17 19:09:49 -0800835 m_tool.createZone(zoneName, ROOT_ZONE);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800836
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800837 BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, "/label", label::NS_RR_TYPE, NDNS_RESP));
838
Jiewen Tan870b29b2014-11-17 19:09:49 -0800839 Zone zone(zoneName);
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800840 BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800841
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800842 BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE));
Jiewen Tan870b29b2014-11-17 19:09:49 -0800843
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -0800844 BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error);
Jiewen Tan870b29b2014-11-17 19:09:49 -0800845}
846
847BOOST_AUTO_TEST_SUITE_END()
848
849} // namespace tests
850} // namespace ndns
851} // namespace ndn