Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, Regents of the University of California. |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 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 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 20 | #include "mgmt/management-tool.hpp" |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 21 | #include "daemon/rrset-factory.hpp" |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 22 | |
| 23 | #include "ndns-enum.hpp" |
| 24 | #include "ndns-label.hpp" |
| 25 | #include "ndns-tlv.hpp" |
| 26 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 27 | #include <boost/algorithm/string/replace.hpp> |
| 28 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 29 | #include <ndn-cxx/util/io.hpp> |
| 30 | #include <ndn-cxx/util/regex.hpp> |
| 31 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 32 | #include "test-common.hpp" |
| 33 | |
| 34 | using boost::test_tools::output_test_stream; |
| 35 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 36 | namespace ndn { |
| 37 | namespace ndns { |
| 38 | namespace tests { |
| 39 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 40 | static const boost::filesystem::path TEST_DATABASE = TEST_CONFIG_PATH "/management_tool.db"; |
| 41 | static const boost::filesystem::path TEST_CERTDIR = TEST_CONFIG_PATH "/management_tool_certs"; |
| 42 | static const Name FAKE_ROOT("/fake-root/123456789"); |
| 43 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 44 | /** |
| 45 | * @brief Recursive copy a directory using Boost Filesystem |
| 46 | * |
| 47 | * Based on from http://stackoverflow.com/q/8593608/2150331 |
| 48 | */ |
| 49 | void |
| 50 | copyDir(const boost::filesystem::path& source, const boost::filesystem::path& destination) |
| 51 | { |
| 52 | namespace fs = boost::filesystem; |
| 53 | |
| 54 | fs::create_directory(destination); |
| 55 | for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file) { |
| 56 | fs::path current(file->path()); |
| 57 | if (is_directory(current)) { |
| 58 | copyDir(current, destination / current.filename()); |
| 59 | } |
| 60 | else { |
| 61 | // cannot use fs::copy_file, see https://svn.boost.org/trac/boost/ticket/10038 |
| 62 | // fs::copy works, as it doesn't use problematic private API |
| 63 | copy(current, destination / current.filename()); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | class TestHome : boost::noncopyable |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 69 | { |
| 70 | public: |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 71 | TestHome() |
| 72 | { |
| 73 | if (std::getenv("HOME")) |
| 74 | m_origHome = std::getenv("HOME"); |
| 75 | |
| 76 | setenv("HOME", TEST_CONFIG_PATH "/tests/unit/mgmt/", 1); |
| 77 | boost::filesystem::remove_all(TEST_CONFIG_PATH "/tests/unit/mgmt/"); |
| 78 | boost::filesystem::create_directories(TEST_CONFIG_PATH "/tests/unit/mgmt"); |
| 79 | copyDir("tests/unit/mgmt/.ndn", TEST_CONFIG_PATH "/tests/unit/mgmt/.ndn"); |
| 80 | } |
| 81 | |
| 82 | ~TestHome() |
| 83 | { |
| 84 | if (!m_origHome.empty()) |
| 85 | setenv("HOME", m_origHome.c_str(), 1); |
| 86 | else |
| 87 | unsetenv("HOME"); |
| 88 | } |
| 89 | |
| 90 | protected: |
| 91 | std::string m_origHome; |
| 92 | }; |
| 93 | |
| 94 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 95 | class ManagementToolFixture : public TestHome, public IdentityManagementFixture |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 96 | { |
| 97 | public: |
| 98 | class Error : public std::runtime_error |
| 99 | { |
| 100 | public: |
| 101 | explicit |
| 102 | Error(const std::string& what) |
| 103 | : std::runtime_error(what) |
| 104 | { |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | class PreviousStateCleaner |
| 109 | { |
| 110 | public: |
| 111 | PreviousStateCleaner() |
| 112 | { |
| 113 | boost::filesystem::remove(TEST_DATABASE); |
| 114 | boost::filesystem::remove_all(TEST_CERTDIR); |
| 115 | } |
| 116 | }; |
| 117 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 118 | ManagementToolFixture() |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 119 | : m_tool(TEST_DATABASE.string().c_str(), m_keyChain) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 120 | , m_dbMgr(TEST_DATABASE.string().c_str()) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 121 | |
| 122 | , rootKsk("/KEY/ksk-1416974006376/ID-CERT/%FD%00%00%01I%EA%3Bx%BD") |
| 123 | , rootDsk("/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28") |
| 124 | |
| 125 | , otherKsk("/ndns-test/KEY/ksk-1416974006577/ID-CERT/%FD%00%00%01I%EA%3By%7F") |
| 126 | , otherDsk("/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E") |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 127 | { |
| 128 | boost::filesystem::create_directory(TEST_CERTDIR); |
| 129 | } |
| 130 | |
| 131 | ~ManagementToolFixture() |
| 132 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 135 | std::vector<Name> |
| 136 | getKeys(const Name& identity) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 137 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 138 | std::vector<Name> keys; |
| 139 | m_keyChain.getAllKeyNamesOfIdentity(identity, keys, false); |
| 140 | m_keyChain.getAllKeyNamesOfIdentity(identity, keys, true); |
| 141 | return keys; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 144 | std::vector<Name> |
| 145 | getCerts(const Name& identity) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 146 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 147 | std::vector<Name> certs; |
| 148 | for (auto&& name : getKeys(identity)) { |
| 149 | m_keyChain.getAllCertificateNamesOfKey(name, certs, false); |
| 150 | m_keyChain.getAllCertificateNamesOfKey(name, certs, true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 151 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 152 | return certs; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 155 | Rrset |
| 156 | findRrSet(Zone& zone, const Name& label, const name::Component& type) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 157 | { |
| 158 | Rrset rrset(&zone); |
| 159 | rrset.setLabel(label); |
| 160 | rrset.setType(type); |
| 161 | |
| 162 | if (!m_dbMgr.find(rrset)) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 163 | throw Error("Record not found"); |
| 164 | else |
| 165 | return rrset; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 168 | Name |
| 169 | getLabel(const Zone& zone, const Name& fullName) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 170 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 171 | size_t zoneNameSize = zone.getName().size(); |
| 172 | return fullName.getSubName(zoneNameSize + 1, fullName.size() - zoneNameSize - 3); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 175 | IdentityCertificate |
| 176 | findIdCert(Zone& zone, const Name& fullName) |
| 177 | { |
| 178 | Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE); |
| 179 | IdentityCertificate cert; |
| 180 | cert.wireDecode(rrset.getData()); |
| 181 | return cert; |
| 182 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 183 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 184 | Response |
| 185 | findResponse(Zone& zone, const Name& label, const name::Component& type) |
| 186 | { |
| 187 | Rrset rrset = findRrSet(zone, label, type); |
| 188 | Data data(rrset.getData()); |
| 189 | Response resp; |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 190 | resp.fromData(zone.getName(), data); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 191 | return resp; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | public: |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 195 | PreviousStateCleaner cleaner; // must be first variable |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 196 | ndns::ManagementTool m_tool; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 197 | ndns::DbMgr m_dbMgr; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 198 | |
| 199 | // Names of pre-created certificates |
| 200 | // Uncomment and run InitPreconfiguredKeys test case and then update names in the |
| 201 | // constructor. |
| 202 | Name rootKsk; |
| 203 | Name rootDsk; |
| 204 | Name otherKsk; |
| 205 | Name otherDsk; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 206 | }; |
| 207 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 208 | BOOST_FIXTURE_TEST_SUITE(ManagementTool, ManagementToolFixture) |
| 209 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 210 | // BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture) |
| 211 | // { |
| 212 | // using time::seconds; |
| 213 | |
| 214 | // auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name { |
| 215 | // // to re-generate certificates, uncomment and then update rootKsk/rootDsk names |
| 216 | // Name kskName = m_keyChain.generateRsaKeyPair(zone, true); |
| 217 | // auto kskCert = m_keyChain |
| 218 | // .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)), |
| 219 | // time::fromUnixTimestamp(seconds(2147483648)), {}); |
| 220 | // if (parentCert.empty()) { |
| 221 | // m_keyChain.selfSign(*kskCert); |
| 222 | // } |
| 223 | // else { |
| 224 | // m_keyChain.sign(*kskCert, parentCert); |
| 225 | // } |
| 226 | // m_keyChain.addCertificate(*kskCert); |
| 227 | |
| 228 | // Name dskName = m_keyChain.generateRsaKeyPair(zone, false); |
| 229 | // auto dskCert = m_keyChain |
| 230 | // .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)), |
| 231 | // time::fromUnixTimestamp(seconds(2147483648)), {}); |
| 232 | // m_keyChain.sign(*dskCert, kskCert->getName()); |
| 233 | // m_keyChain.addCertificate(*dskCert); |
| 234 | |
| 235 | // return dskCert->getName(); |
| 236 | // }; |
| 237 | |
| 238 | // Name rootDsk = generateCerts(ROOT_ZONE); |
| 239 | // generateCerts("/ndns-test", rootDsk); |
| 240 | |
| 241 | // copyDir(TEST_CONFIG_PATH "/tests/unit/mgmt/.ndn", "/tmp/.ndn"); |
| 242 | // std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl; |
| 243 | // } |
| 244 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 245 | BOOST_AUTO_TEST_CASE(CreateDeleteRootFixture) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 246 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 247 | m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(4600), time::seconds(4600), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 248 | rootKsk, rootDsk); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 249 | |
| 250 | Zone zone(ROOT_ZONE); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 251 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
| 252 | BOOST_REQUIRE_NO_THROW(findIdCert(zone, rootDsk)); |
| 253 | BOOST_CHECK_EQUAL(findIdCert(zone, rootDsk).getName(), rootDsk); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 254 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 255 | BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE)); |
| 256 | BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 259 | BOOST_AUTO_TEST_CASE(CreateDeleteChildFixture) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 260 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 261 | Name parentZoneName("/ndns-test"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 262 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 263 | |
| 264 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), false); |
| 265 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 266 | // will generate keys automatically |
| 267 | m_tool.createZone(zoneName, parentZoneName); |
| 268 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 269 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 270 | std::vector<Name>&& certs = getCerts(zoneName); |
| 271 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
| 272 | std::sort(certs.begin(), certs.end()); |
| 273 | |
| 274 | // Name& ksk = certs[0]; |
| 275 | Name& dsk = certs[1]; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 276 | |
| 277 | Zone zone(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 278 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
| 279 | BOOST_REQUIRE_NO_THROW(findIdCert(zone, dsk)); |
| 280 | BOOST_CHECK_EQUAL(findIdCert(zone, dsk).getName(), dsk); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 281 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 282 | BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 283 | |
| 284 | BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 285 | BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error); |
| 286 | } |
| 287 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 288 | BOOST_AUTO_TEST_CASE(CreateZoneWithFixture) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 289 | { |
| 290 | Name parentZoneName("/ndns-test"); |
| 291 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 292 | |
| 293 | m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30)); |
| 294 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(zoneName), true); |
| 295 | |
| 296 | std::vector<Name>&& certs = getCerts(zoneName); |
| 297 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
| 298 | std::sort(certs.begin(), certs.end()); |
| 299 | |
| 300 | // Name& ksk = certs[0]; |
| 301 | Name& dsk = certs[1]; |
| 302 | |
| 303 | // Check zone ttl |
| 304 | Zone zone(zoneName); |
| 305 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
| 306 | BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200)); |
| 307 | |
| 308 | // Check dsk rrset ttl |
| 309 | Rrset rrset; |
| 310 | BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE)); |
| 311 | BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200)); |
| 312 | |
| 313 | // Check certificate freshnessPeriod and validity |
| 314 | IdentityCertificate cert; |
| 315 | BOOST_REQUIRE_NO_THROW(cert = findIdCert(zone, dsk)); |
| 316 | BOOST_CHECK_EQUAL(cert.getMetaInfo().getFreshnessPeriod(), time::seconds(4200)); |
| 317 | BOOST_CHECK_EQUAL(cert.getNotAfter() - cert.getNotBefore(), time::days(30)); |
| 318 | |
| 319 | m_tool.deleteZone(zoneName); |
| 320 | } |
| 321 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 322 | BOOST_AUTO_TEST_CASE(ZoneCreatePreconditions) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 323 | { |
| 324 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net")); |
| 325 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error); |
| 326 | |
| 327 | std::vector<Name>&& certs = getCerts("/net/ndnsim"); |
| 328 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
| 329 | std::sort(certs.begin(), certs.end()); |
| 330 | |
| 331 | Name& ksk = certs[0]; |
| 332 | Name& dsk = certs[1]; |
| 333 | |
| 334 | m_tool.deleteZone("/net/ndnsim"); |
| 335 | // identity will still exist after the zone is deleted |
| 336 | |
| 337 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error); |
| 338 | |
| 339 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error); |
| 340 | |
| 341 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 342 | time::seconds(1), time::days(1), ksk, dsk)); |
| 343 | BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2); |
| 344 | m_tool.deleteZone("/net/ndnsim"); |
| 345 | |
Jiewen Tan | 01693fd | 2015-03-25 20:34:45 -0700 | [diff] [blame] | 346 | // no ksk and dsk will be generated |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 347 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 348 | time::seconds(1), time::days(1), Name(), dsk)); |
Jiewen Tan | 01693fd | 2015-03-25 20:34:45 -0700 | [diff] [blame] | 349 | BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 350 | m_tool.deleteZone("/net/ndnsim"); |
| 351 | |
| 352 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 353 | time::seconds(1), time::days(1), ksk, Name())); |
Jiewen Tan | 01693fd | 2015-03-25 20:34:45 -0700 | [diff] [blame] | 354 | BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 3); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 355 | m_tool.deleteZone("/net/ndnsim"); |
| 356 | |
| 357 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 358 | time::seconds(1), time::days(1), "/com/ndnsim"), |
| 359 | ndns::ManagementTool::Error); |
| 360 | |
| 361 | m_keyChain.deleteIdentity("/net/ndnsim"); |
| 362 | Name cert = m_keyChain.createIdentity("/net/ndnsim"); |
| 363 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 364 | time::seconds(1), time::days(1), cert)); |
| 365 | |
| 366 | cert = m_keyChain.createIdentity("/com/ndnsim"); |
| 367 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 368 | time::seconds(1), time::days(1), cert), |
| 369 | ndns::ManagementTool::Error); |
| 370 | |
| 371 | cert = m_keyChain.createIdentity("/net/ndnsim/www"); |
| 372 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 373 | time::seconds(1), time::days(1), cert), |
| 374 | ndns::ManagementTool::Error); |
| 375 | |
| 376 | cert = m_keyChain.createIdentity("/net/ndnsim"); |
| 377 | m_keyChain.deleteKeyPairInTpm(m_keyChain.getCertificate(cert)->getPublicKeyName()); |
| 378 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 379 | time::seconds(1), time::days(1), cert), |
| 380 | ndns::ManagementTool::Error); |
| 381 | |
| 382 | // for root zone special case (requires a valid KSK to be specified) |
| 383 | BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error); |
| 384 | |
| 385 | BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1), |
| 386 | rootKsk)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | class OutputTester |
| 390 | { |
| 391 | public: |
| 392 | OutputTester() |
| 393 | : savedBuf(std::clog.rdbuf()) |
| 394 | { |
| 395 | std::cout.rdbuf(buffer.rdbuf()); |
| 396 | } |
| 397 | |
| 398 | ~OutputTester() |
| 399 | { |
| 400 | std::cout.rdbuf(savedBuf); |
| 401 | } |
| 402 | |
| 403 | public: |
| 404 | std::stringstream buffer; |
| 405 | std::streambuf* savedBuf; |
| 406 | }; |
| 407 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 408 | BOOST_AUTO_TEST_CASE(ExportCertificate) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 409 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 410 | std::string outputFile = TEST_CERTDIR.string() + "/ss.cert"; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 411 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 412 | BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile), |
| 413 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 414 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 415 | BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false); |
| 416 | // doesn't check the zone, export from KeyChain directly |
| 417 | BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile)); |
| 418 | BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 419 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 420 | std::string dskValue = |
| 421 | "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n" |
| 422 | "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n" |
| 423 | "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n" |
| 424 | "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n" |
| 425 | "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n" |
| 426 | "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n" |
| 427 | "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n" |
| 428 | "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n" |
| 429 | "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n" |
| 430 | "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n" |
| 431 | "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n" |
| 432 | "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n" |
| 433 | "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n" |
| 434 | "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n" |
| 435 | "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n" |
| 436 | "8UNqhMpjAZwW6pdvOZADVg==\n"; |
| 437 | |
| 438 | { |
| 439 | std::ifstream ifs(outputFile.c_str()); |
| 440 | std::string actualValue((std::istreambuf_iterator<char>(ifs)), |
| 441 | std::istreambuf_iterator<char>()); |
| 442 | BOOST_CHECK_EQUAL(actualValue, dskValue); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 443 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 444 | boost::filesystem::remove(outputFile); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 445 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 446 | // doesn't check the zone, export from KeyChain directly |
| 447 | BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile)); |
| 448 | boost::filesystem::remove(outputFile); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 449 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 450 | Name zoneName("/ndns-test"); |
| 451 | m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30), |
| 452 | otherKsk, otherDsk); |
| 453 | |
| 454 | m_keyChain.deleteCertificate(otherKsk); |
| 455 | m_keyChain.deleteCertificate(otherDsk); |
| 456 | |
| 457 | // retrieve cert from the zone |
| 458 | BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile)); |
| 459 | { |
| 460 | std::ifstream ifs(outputFile.c_str()); |
| 461 | std::string actualValue((std::istreambuf_iterator<char>(ifs)), |
| 462 | std::istreambuf_iterator<char>()); |
| 463 | BOOST_CHECK_EQUAL(actualValue, dskValue); |
| 464 | } |
| 465 | boost::filesystem::remove(outputFile); |
| 466 | |
| 467 | BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile), |
| 468 | ndns::ManagementTool::Error); |
| 469 | |
| 470 | // output to std::cout |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 471 | std::string acutalOutput; |
| 472 | { |
| 473 | OutputTester tester; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 474 | m_tool.exportCertificate(otherDsk, "-"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 475 | acutalOutput = tester.buffer.str(); |
| 476 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 477 | BOOST_CHECK_EQUAL(acutalOutput, dskValue); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 480 | BOOST_AUTO_TEST_CASE(AddRrset) |
| 481 | { |
| 482 | Name zoneName("/ndns-test"); |
| 483 | Zone zone(zoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 484 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 485 | time::seconds ttl1(4200); |
| 486 | time::seconds ttl2(4500); |
| 487 | m_tool.createZone(zoneName, ROOT_ZONE, ttl1); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 488 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 489 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 490 | rf.checkZoneKey(); |
| 491 | Rrset rrset1 = rf.generateNsRrset("/l1", label::NS_RR_TYPE, 7654, ttl2, Link::DelegationSet()); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 492 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 493 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1)); |
| 494 | Rrset rrset2 = findRrSet(zone, "/l1", label::NS_RR_TYPE); |
| 495 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 496 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 497 | Rrset rrset3 = rf.generateNsRrset("/l1/l2/l3", label::NS_RR_TYPE, 7654, ttl2, Link::DelegationSet()); |
| 498 | BOOST_CHECK_THROW(m_tool.addRrset(rrset3), ndns::ManagementTool::Error); |
| 499 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 500 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 501 | BOOST_AUTO_TEST_CASE(AddMultiLevelLabelRrset) |
| 502 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 503 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 504 | Name zoneName("/ndns-test"); |
| 505 | Zone zone(zoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 506 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 507 | time::seconds ttl(4200); |
| 508 | m_tool.createZone(zoneName, ROOT_ZONE, ttl); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 509 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 510 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 511 | rf.checkZoneKey(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 512 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 513 | auto checkRrset = [&zone, &zoneName, this](Name label, |
| 514 | name::Component type, |
| 515 | NdnsContentType contentType) -> void { |
| 516 | Rrset rr1 = findRrSet(zone, label, type); |
| 517 | BOOST_CHECK_EQUAL(Data(rr1.getData()).getContentType(), contentType); |
| 518 | Response response1; |
| 519 | response1.fromData(zoneName, Data(rr1.getData())); |
| 520 | BOOST_CHECK_EQUAL(response1.getRrLabel(), label); |
| 521 | }; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 522 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 523 | Name labelName("/l1/l2/l3"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 524 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 525 | Rrset rrset1 = rf.generateNsRrset(labelName, label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet()); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 526 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 527 | //add NS NDNS_AUTH and check user-defined ttl |
| 528 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(rrset1, rf, ttl)); |
| 529 | Rrset rrset2 = findRrSet(zone, labelName, label::NS_RR_TYPE); |
| 530 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 531 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 532 | checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 533 | checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 534 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 535 | // insert a same-name rrset with TXT type |
| 536 | Rrset txtRr = rf.generateTxtRrset("/l1/l2/l3", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>()); |
| 537 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(txtRr, rf, ttl)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 538 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 539 | checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 540 | checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 541 | checkRrset("/l1/l2/l3", label::TXT_RR_TYPE, ndns::NDNS_RESP); |
| 542 | // check that there is no confliction |
| 543 | checkRrset("/l1/l2/l3", label::NS_RR_TYPE, ndns::NDNS_LINK); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 544 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 545 | // insert a shorter NS, when there are longer NS or TXT |
| 546 | Rrset shorterNs = rf.generateNsRrset("/l1/l2", label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet()); |
| 547 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(shorterNs, rf, ttl), |
| 548 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 549 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 550 | // insert a longer NS, when there is already a shorter NS |
| 551 | Rrset longerNs = rf.generateNsRrset("/l1/l2/l3/l4", label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet()); |
| 552 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(longerNs, rf, ttl), |
| 553 | ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 554 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 555 | // insert a smaller TXT, when there are longer NS and TXT |
| 556 | Rrset shorterTxt = rf.generateTxtRrset("/l1/l2", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>()); |
| 557 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(shorterTxt, rf, ttl)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 558 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 559 | // insert a smaller NS, when there is long TXT |
| 560 | Rrset longTxt = rf.generateTxtRrset("/k1/k2/k3", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>()); |
| 561 | Rrset smallerNs = rf.generateNsRrset("/k1/k2", label::NS_RR_TYPE, 7654, ttl, Link::DelegationSet()); |
| 562 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longTxt, rf, ttl)); |
| 563 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(smallerNs, rf, ttl), |
| 564 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 565 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 566 | // inserting a longer TXT, when there is shoter TXT |
| 567 | Rrset longerTxt = rf.generateTxtRrset("/k1/k2/k3/k4", label::TXT_RR_TYPE, 7654, ttl, std::vector<std::string>()); |
| 568 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longerTxt, rf, ttl)); |
| 569 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 570 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 571 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertPreConditon) |
| 572 | { |
| 573 | // check pre-condition |
| 574 | Name zoneName("/ndns-test"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 575 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 576 | // Check: throw if zone not exist |
| 577 | std::string certPath = TEST_CERTDIR.string(); |
| 578 | BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 579 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 580 | m_tool.createZone(zoneName, ROOT_ZONE); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 581 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 582 | // Check: throw if certificate does not match |
| 583 | BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, certPath), ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 584 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 585 | std::string rightCertPath = TEST_CERTDIR.string() + "/ss.cert"; |
| 586 | m_tool.exportCertificate(otherKsk, rightCertPath); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 587 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 588 | BOOST_CHECK_NO_THROW(m_tool.addRrSet(zoneName, rightCertPath)); |
| 589 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 590 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 591 | BOOST_AUTO_TEST_CASE(AddRrSetDskCert) |
| 592 | { |
| 593 | Name parentZoneName("/ndns-test"); |
| 594 | Name zoneName("/ndns-test/child-zone"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 595 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 596 | Zone parentZone(parentZoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 597 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 598 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 599 | m_tool.createZone(zoneName, parentZoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 600 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 601 | std::vector<Name>&& certs = getCerts(zoneName); |
| 602 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
| 603 | std::sort(certs.begin(), certs.end()); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 604 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 605 | Name& ksk = certs[0]; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 606 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 607 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
| 608 | m_tool.exportCertificate(ksk, output); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 609 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 610 | BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output)); |
| 611 | BOOST_CHECK_NO_THROW(findIdCert(parentZone, ksk)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 612 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 613 | // Add KSK ID-CERT with illegal name and convert it |
| 614 | Name iZoneName = Name(parentZoneName).append("illegal"); |
| 615 | Name illegalCertName = m_keyChain.createIdentity(iZoneName); |
| 616 | m_tool.exportCertificate(illegalCertName, output); |
| 617 | BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 618 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 619 | Name legalCertName = Name(parentZoneName).append("KEY") |
| 620 | .append("illegal") |
| 621 | .append(illegalCertName.getSubName(3)); |
| 622 | BOOST_CHECK_NO_THROW(findIdCert(parentZone, legalCertName)); |
| 623 | } |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 624 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 625 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertUserProvidedCert) |
| 626 | { |
| 627 | //check using user provided certificate |
| 628 | Name parentZoneName("/ndns-test"); |
| 629 | Name zoneName("/ndns-test/child-zone"); |
| 630 | |
| 631 | Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false); |
| 632 | shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName); |
| 633 | m_keyChain.addCertificateAsKeyDefault(*dskCert); |
| 634 | |
| 635 | // check addRrSet1 |
| 636 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 637 | m_tool.createZone(zoneName, parentZoneName); |
| 638 | |
| 639 | std::vector<Name>&& certs = getCerts(zoneName); |
| 640 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
| 641 | std::sort(certs.begin(), certs.end()); |
| 642 | |
| 643 | Name& ksk = certs[0]; |
| 644 | // Name& dsk = certs[1]; |
| 645 | |
| 646 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
| 647 | m_tool.exportCertificate(ksk, output); |
| 648 | |
| 649 | BOOST_CHECK_NO_THROW(m_tool.addRrSet(parentZoneName, output, time::seconds(4600), |
| 650 | dskCert->getName())); |
| 651 | } |
| 652 | |
| 653 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertInvalidOutput) |
| 654 | { |
| 655 | //check invalid output |
| 656 | Name parentZoneName("/ndns-test"); |
| 657 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 658 | m_tool.createZone(zoneName, parentZoneName); |
| 659 | |
| 660 | Name content = "invalid data packet"; |
| 661 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
| 662 | ndn::io::save(content, output); |
| 663 | |
| 664 | BOOST_CHECK_THROW(m_tool.addRrSet(zoneName, output), ndns::ManagementTool::Error); |
| 665 | } |
| 666 | |
| 667 | BOOST_AUTO_TEST_CASE(AddRrSetVersionControl) |
| 668 | { |
| 669 | //check version control |
| 670 | time::seconds ttl(4200); |
| 671 | Name parentZoneName("/ndns-test"); |
| 672 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 673 | m_tool.createZone(zoneName, parentZoneName); |
| 674 | |
| 675 | Name label("/label"); |
| 676 | uint64_t version = 110; |
| 677 | |
| 678 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 679 | rf.checkZoneKey(); |
| 680 | |
| 681 | Rrset rrset1 = rf.generateTxtRrset(label, label::NS_RR_TYPE, version, ttl, {}); |
| 682 | |
| 683 | m_tool.addRrset(rrset1); |
| 684 | // throw error when adding duplicated rrset with the same version |
| 685 | BOOST_CHECK_THROW(m_tool.addRrset(rrset1), |
| 686 | ndns::ManagementTool::Error); |
| 687 | version--; |
| 688 | Rrset rrset2 = rf.generateTxtRrset(label, label::NS_RR_TYPE, version, ttl, {}); |
| 689 | // throw error when adding duplicated rrset with older version |
| 690 | BOOST_CHECK_THROW(m_tool.addRrset(rrset2), |
| 691 | ndns::ManagementTool::Error); |
| 692 | |
| 693 | version++; |
| 694 | version++; |
| 695 | Rrset rrset3 = rf.generateTxtRrset(label, label::NS_RR_TYPE, version, ttl, {}); |
| 696 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset3)); |
| 697 | |
| 698 | Zone zone(zoneName); |
| 699 | m_dbMgr.find(zone); |
| 700 | Rrset rrset; |
| 701 | rrset.setZone(&zone); |
| 702 | rrset.setLabel(label); |
| 703 | rrset.setType(label::NS_RR_TYPE); |
| 704 | m_dbMgr.find(rrset); |
| 705 | |
| 706 | BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version)); |
| 707 | } |
| 708 | |
| 709 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertFormat) |
| 710 | { |
| 711 | //check input with different formats |
| 712 | Name parentZoneName("/ndns-test"); |
| 713 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 714 | m_tool.createZone(zoneName, parentZoneName); |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 715 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 716 | std::string output = TEST_CERTDIR.string() + "/a.cert"; |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 717 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 718 | // base64 |
| 719 | Name dskName = m_keyChain.generateRsaKeyPair(zoneName, false); |
| 720 | shared_ptr<IdentityCertificate> dskCert = m_keyChain.selfSign(dskName); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 721 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 722 | ndn::io::save(*dskCert, output, ndn::io::BASE64); |
| 723 | BOOST_CHECK_NO_THROW( |
| 724 | m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64)); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 725 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 726 | // raw |
| 727 | dskName = m_keyChain.generateRsaKeyPair(zoneName, false); |
| 728 | dskCert = m_keyChain.selfSign(dskName); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 729 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 730 | ndn::io::save(*dskCert, output, ndn::io::NO_ENCODING); |
| 731 | BOOST_CHECK_NO_THROW( |
| 732 | m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING)); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 733 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 734 | // hex |
| 735 | dskName = m_keyChain.generateRsaKeyPair(zoneName, false); |
| 736 | dskCert = m_keyChain.selfSign(dskName); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 737 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 738 | ndn::io::save(*dskCert, output, ndn::io::HEX); |
| 739 | BOOST_CHECK_NO_THROW( |
| 740 | m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX)); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 741 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 742 | // incorrect encoding input |
| 743 | dskName = m_keyChain.generateRsaKeyPair(zoneName, false); |
| 744 | dskCert = m_keyChain.selfSign(dskName); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 745 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 746 | ndn::io::save(*dskCert, output, ndn::io::HEX); |
| 747 | BOOST_CHECK_THROW( |
| 748 | m_tool.addRrSet(zoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, |
| 749 | static_cast<ndn::io::IoEncoding>(127)), |
| 750 | ndns::ManagementTool::Error); |
| 751 | } |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 752 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 753 | BOOST_AUTO_TEST_CASE(ListAllZones) |
| 754 | { |
| 755 | m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk); |
| 756 | m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 757 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 758 | std::string expectedValue = |
| 759 | "/ ; default-ttl=1 default-key=/dsk-1416974006466 " |
| 760 | "default-certificate=/KEY/dsk-1416974006466/ID-CERT/%FD%00%00%01I%EA%3By%28\n" |
| 761 | "/ndns-test ; default-ttl=10 default-key=/ndns-test/dsk-1416974006659 " |
| 762 | "default-certificate=/ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n"; |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 763 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 764 | output_test_stream testOutput; |
| 765 | m_tool.listAllZones(testOutput); |
| 766 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 767 | } |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 768 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 769 | BOOST_AUTO_TEST_CASE(ListZone) |
| 770 | { |
| 771 | m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 772 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 773 | RrsetFactory rf(TEST_DATABASE, "/ndns-test", m_keyChain, DEFAULT_CERT); |
| 774 | rf.checkZoneKey(); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 775 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 776 | // Add NS with NDNS_RESP |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 777 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 778 | Link::DelegationSet ds = {std::pair<uint32_t, Name>(10,"/get/link")}; |
| 779 | Rrset rrset1 = rf.generateNsRrset("/label1", label::NS_RR_TYPE, 100, DEFAULT_RR_TTL, ds); |
| 780 | m_tool.addRrset(rrset1); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 781 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 782 | // Add NS with NDNS_AUTH |
| 783 | Rrset rrset2 = rf.generateAuthRrset("/label2", label::NS_RR_TYPE, 100000, DEFAULT_RR_TTL); |
| 784 | m_tool.addRrset(rrset2); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 785 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 786 | // Add TXT from file |
| 787 | std::string output = TEST_CERTDIR.string() + "/a.rrset"; |
| 788 | Response re1; |
| 789 | re1.setZone("/ndns-test"); |
| 790 | re1.setQueryType(label::NDNS_ITERATIVE_QUERY); |
| 791 | re1.setRrLabel("/label2"); |
| 792 | re1.setRrType(label::TXT_RR_TYPE); |
| 793 | re1.setContentType(NDNS_RESP); |
| 794 | re1.setVersion(name::Component::fromVersion(654321)); |
| 795 | re1.addRr("First RR"); |
| 796 | re1.addRr("Second RR"); |
| 797 | re1.addRr("Last RR"); |
| 798 | shared_ptr<Data> data1 = re1.toData(); |
| 799 | m_keyChain.sign(*data1, otherDsk); |
| 800 | ndn::io::save(*data1, output); |
| 801 | m_tool.addRrSet("/ndns-test", output); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 802 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 803 | // Add TXT in normal way |
| 804 | Rrset rrset3 = rf.generateTxtRrset("/label3", label::TXT_RR_TYPE, 3333, DEFAULT_RR_TTL, {"Hello", "World"}); |
| 805 | m_tool.addRrset(rrset3); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 806 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 807 | output_test_stream testOutput; |
| 808 | m_tool.listZone("/ndns-test", testOutput, true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 809 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 810 | std::string expectedValue = |
| 811 | R"VALUE(; Zone /ndns-test |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 812 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 813 | ; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT |
| 814 | /label1 10 NS 10,/get/link; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 815 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 816 | ; rrset=/label2 type=NS version=%FD%00%01%86%A0 signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT |
| 817 | /label2 10 NS NDNS-Auth |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 818 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 819 | ; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT |
| 820 | /label2 10 TXT First RR |
| 821 | /label2 10 TXT Second RR |
| 822 | /label2 10 TXT Last RR |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 823 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 824 | ; rrset=/label3 type=TXT version=%FD%0D%05 signed-by=/ndns-test/KEY/dsk-1416974006659/ID-CERT |
| 825 | /label3 10 TXT Hello |
| 826 | /label3 10 TXT World |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 827 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 828 | /dsk-1416974006659 10 ID-CERT ; content-type=KEY version=%FD%00%00%01I%EA%3Bz%0E signed-by=/ndns-test/KEY/ksk-1416974006577/ID-CERT |
| 829 | ; Certificate name: |
| 830 | ; /ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E |
| 831 | ; Validity: |
| 832 | ; NotBefore: 19700101T000000 |
| 833 | ; NotAfter: 20380119T031408 |
| 834 | ; Subject Description: |
| 835 | ; 2.5.4.41: /ndns-test |
| 836 | ; Public key bits: (RSA) |
| 837 | ; MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAyBVC+xc/JpscSE/JdxbV |
| 838 | ; pvgrh/fokNFI/2t9D5inuIFr7cc4W+LyJ4GG1xr9olMx7MHamJU1Xg3VunjhSjL8 |
| 839 | ; mOaeXlbS6gxWexBCtNK6U4euPB4wks/gMIKdp24mAAFb4T+mBfjcRgR+NdrjyO5C |
| 840 | ; 2OqM8qbDZmD/iuEmE6GPXnuMS0o6s13yzMj9YfDh3Df2jZnHESZcmG5Qpgg22T58 |
| 841 | ; 7t7bRx8Ha2EC3hb29AeYKwgEKDx8JH8ZBJ80AQP321HbyjXWshJLomzy5SJZo9nA |
| 842 | ; bZOYlZPCQkomz92Zc9+kpLNQwDvtRLwkZ46B+b2JpKTFARbnvugONCEBuG6zNgoi |
| 843 | ; EQIB |
| 844 | ; Signature Information: |
| 845 | ; Signature Type: Unknown Signature Type |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 846 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 847 | )VALUE"; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 848 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 849 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 850 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 851 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 852 | BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture) |
| 853 | { |
| 854 | Name zoneName("/ndns-test"); |
| 855 | m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 856 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 857 | rf.checkZoneKey(); |
| 858 | Rrset rrset1 = rf.generateTxtRrset("/label", label::TXT_RR_TYPE, 100, DEFAULT_RR_TTL, {"Value1", "Value2"}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 859 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 860 | m_tool.addRrset(rrset1); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 861 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 862 | std::string expectedValue = |
| 863 | R"VALUE(Bv0BeAchCAluZG5zLXRlc3QIBE5ETlMIBWxhYmVsCANUWFQIAv1kFAgYAgQ/GQID |
| 864 | 6BUQvwZWYWx1ZTG/BlZhbHVlMhYzGwEBHC4HLAgJbmRucy10ZXN0CANLRVkIEWRz |
| 865 | ay0xNDE2OTc0MDA2NjU5CAdJRC1DRVJUF/0BAL7Phidi+mM5cWM6alaV38qpEd+D |
| 866 | kV1bHEO1BT7jsjfxW8INS7OJVUbr5ducBDTjzCp9dYjKncKv0f3hcZIX7fl9/msL |
| 867 | 6FuCKqrYgEZIgSD3q6DFzh04FUjrMJvqZp1D3LBh1yIKARA9TI0C6TKrlOT40iuY |
| 868 | wvifmpSna7gOuh1k+qvKvx+/Y6csCw9WVLxnW12/AJdlfv3PPPnDlKkN7DozUV+s |
| 869 | c7Jf+hhhZDntij+fMYBVgk0Ub/udOJrznlcZKW6C7YK57wq806kO3430gLQBEkGC |
| 870 | NuOojYCk2k4Skp830cvIdy1Ld5lY1qrBZOIKR38KIy8jchP9+MEB88jvXrY= |
| 871 | )VALUE"; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 872 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 873 | output_test_stream testOutput; |
| 874 | m_tool.getRrSet(zoneName, "/label",label::TXT_RR_TYPE, testOutput); |
| 875 | BOOST_CHECK(testOutput.check_length(expectedValue.length(), false)); |
| 876 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 877 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 878 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 879 | BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture) |
| 880 | { |
| 881 | Name zoneName("/ndns-test"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 882 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 883 | m_tool.createZone(zoneName, ROOT_ZONE); |
| 884 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 885 | rf.checkZoneKey(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 886 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 887 | Rrset rrset1 = rf.generateTxtRrset("/label", label::NS_RR_TYPE, 100, DEFAULT_RR_TTL, {}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 888 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 889 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 890 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 891 | Zone zone(zoneName); |
| 892 | BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 893 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 894 | BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 895 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame^] | 896 | BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error); |
| 897 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 898 | |
| 899 | BOOST_AUTO_TEST_SUITE_END() |
| 900 | |
| 901 | } // namespace tests |
| 902 | } // namespace ndns |
| 903 | } // namespace ndn |