Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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" |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 22 | #include "util/cert-helper.hpp" |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 23 | #include "ndns-enum.hpp" |
| 24 | #include "ndns-label.hpp" |
| 25 | #include "ndns-tlv.hpp" |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 26 | |
| 27 | #include "boost-test.hpp" |
| 28 | #include "key-chain-fixture.hpp" |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 29 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 30 | #include <random> |
| 31 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 32 | #include <boost/algorithm/string/replace.hpp> |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 33 | #include <boost/range/adaptors.hpp> |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 34 | #if BOOST_VERSION >= 105900 |
| 35 | #include <boost/test/tools/output_test_stream.hpp> |
| 36 | #else |
| 37 | #include <boost/test/output_test_stream.hpp> |
| 38 | #endif |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 39 | |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 40 | #include <ndn-cxx/security/transform.hpp> |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 41 | #include <ndn-cxx/util/io.hpp> |
| 42 | #include <ndn-cxx/util/regex.hpp> |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 43 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 44 | namespace ndn { |
| 45 | namespace ndns { |
| 46 | namespace tests { |
| 47 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 48 | using boost::test_tools::output_test_stream; |
| 49 | |
| 50 | const auto TEST_DATABASE = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "management_tool.db"; |
| 51 | const auto TEST_CERTDIR = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "management_tool_certs"; |
| 52 | const Name FAKE_ROOT("/fake-root/123456789"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 54 | /** |
| 55 | * @brief Recursive copy a directory using Boost Filesystem |
| 56 | * |
| 57 | * Based on from http://stackoverflow.com/q/8593608/2150331 |
| 58 | */ |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 59 | static void |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 60 | copyDir(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 { |
Eric Newberry | 9edaf26 | 2018-06-07 23:44:57 -0700 | [diff] [blame] | 71 | copy_file(current, destination / current.filename()); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | class TestHome : boost::noncopyable |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 77 | { |
| 78 | public: |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 79 | TestHome() |
| 80 | { |
| 81 | if (std::getenv("HOME")) |
| 82 | m_origHome = std::getenv("HOME"); |
| 83 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 84 | auto p = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "tests" / "unit" / "mgmt"; |
| 85 | setenv("HOME", p.c_str(), 1); |
| 86 | boost::filesystem::remove_all(p); |
| 87 | boost::filesystem::create_directories(p); |
| 88 | copyDir("tests/unit/mgmt/.ndn", p / ".ndn"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | ~TestHome() |
| 92 | { |
| 93 | if (!m_origHome.empty()) |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 94 | setenv("HOME", m_origHome.data(), 1); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 95 | else |
| 96 | unsetenv("HOME"); |
| 97 | } |
| 98 | |
| 99 | protected: |
| 100 | std::string m_origHome; |
| 101 | }; |
| 102 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 103 | class ManagementToolFixture : public TestHome, public KeyChainFixture |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 104 | { |
| 105 | public: |
| 106 | class Error : public std::runtime_error |
| 107 | { |
| 108 | public: |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 109 | using std::runtime_error::runtime_error; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | class PreviousStateCleaner |
| 113 | { |
| 114 | public: |
| 115 | PreviousStateCleaner() |
| 116 | { |
| 117 | boost::filesystem::remove(TEST_DATABASE); |
| 118 | boost::filesystem::remove_all(TEST_CERTDIR); |
| 119 | } |
| 120 | }; |
| 121 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 122 | ManagementToolFixture() |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 123 | : m_tool(TEST_DATABASE.string().c_str(), m_keyChain) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 124 | , m_dbMgr(TEST_DATABASE.string().c_str()) |
| 125 | { |
| 126 | boost::filesystem::create_directory(TEST_CERTDIR); |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 127 | Identity root = m_keyChain.createIdentity("NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 128 | Key ksk = root.getDefaultKey(); |
| 129 | m_keyChain.deleteCertificate(ksk, ksk.getDefaultCertificate().getName()); |
| 130 | Certificate kskCert = CertHelper::createCertificate(m_keyChain, ksk, ksk, "CERT"); |
| 131 | m_keyChain.addCertificate(ksk, kskCert); |
| 132 | rootKsk = kskCert.getName(); |
| 133 | |
| 134 | Key dsk = m_keyChain.createKey(root); |
| 135 | // replace rootDsk's default cert with ksk-signing cert |
| 136 | m_keyChain.deleteCertificate(dsk, dsk.getDefaultCertificate().getName()); |
| 137 | Certificate dskCert = CertHelper::createCertificate(m_keyChain, dsk, ksk, "CERT"); |
| 138 | m_keyChain.addCertificate(dsk, dskCert); |
| 139 | rootDsk = dskCert.getName(); |
| 140 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 141 | Identity other = m_keyChain.createIdentity("/ndns-test/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 142 | Key otherKskKey = other.getDefaultKey(); |
| 143 | m_keyChain.deleteCertificate(otherKskKey, otherKskKey.getDefaultCertificate().getName()); |
| 144 | Certificate otherKskCert = CertHelper::createCertificate(m_keyChain, otherKskKey, otherKskKey, "CERT"); |
| 145 | m_keyChain.addCertificate(otherKskKey, otherKskCert); |
| 146 | otherKsk = otherKskCert.getName(); |
| 147 | |
| 148 | // replace rootDsk's default cert with ksk-signing cert |
| 149 | Key otherDskKey = m_keyChain.createKey(other); |
| 150 | m_keyChain.deleteCertificate(otherDskKey, otherDskKey.getDefaultCertificate().getName()); |
| 151 | Certificate otherDskCert = CertHelper::createCertificate(m_keyChain, otherDskKey, otherKskKey, "CERT"); |
| 152 | m_keyChain.addCertificate(otherDskKey, otherDskCert); |
| 153 | otherDsk = otherDskCert.getName(); |
| 154 | |
| 155 | Certificate rootDkeyCert = CertHelper::createCertificate(m_keyChain, otherDskKey, otherKskKey, "CERT"); |
| 156 | m_keyChain.addCertificate(otherDskKey, rootDkeyCert); |
| 157 | rootDkey = rootDkeyCert.getName(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | ~ManagementToolFixture() |
| 161 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 164 | std::vector<Certificate> |
| 165 | getCerts(const Name& zoneName) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 166 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 167 | Zone zone(zoneName); |
| 168 | std::vector<Certificate> certs; |
| 169 | std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone); |
| 170 | // ksk are always the first key |
| 171 | certs.push_back(Certificate(zoneInfo["ksk"])); |
| 172 | certs.push_back(Certificate(zoneInfo["dsk"])); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 173 | return certs; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 176 | Rrset |
| 177 | findRrSet(Zone& zone, const Name& label, const name::Component& type) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 178 | { |
| 179 | Rrset rrset(&zone); |
| 180 | rrset.setLabel(label); |
| 181 | rrset.setType(type); |
| 182 | |
| 183 | if (!m_dbMgr.find(rrset)) |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 184 | BOOST_THROW_EXCEPTION(Error("Record not found")); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 185 | else |
| 186 | return rrset; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 189 | Name |
| 190 | getLabel(const Zone& zone, const Name& fullName) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 191 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 192 | size_t zoneNameSize = zone.getName().size(); |
| 193 | return fullName.getSubName(zoneNameSize + 1, fullName.size() - zoneNameSize - 3); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 196 | Certificate |
| 197 | findCertFromIdentity(const Name& identityName, const Name& certName) |
| 198 | { |
| 199 | Certificate rtn; |
| 200 | Identity identity = CertHelper::getIdentity(m_keyChain, identityName); |
| 201 | for (const auto& key : identity.getKeys()) { |
| 202 | for (const auto& cert : key.getCertificates()) { |
| 203 | if (cert.getName() == certName) { |
| 204 | rtn = cert; |
| 205 | return rtn; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | BOOST_THROW_EXCEPTION(Error("Certificate not found in keyChain")); |
| 210 | return rtn; |
| 211 | } |
| 212 | |
| 213 | Certificate |
| 214 | findCertFromDb(Zone& zone, const Name& fullName) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 215 | { |
| 216 | Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 217 | Certificate cert; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 218 | cert.wireDecode(rrset.getData()); |
| 219 | return cert; |
| 220 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 221 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 222 | Certificate |
| 223 | findDkeyFromDb(const Name& zoneName) |
| 224 | { |
| 225 | Zone zone(zoneName); |
| 226 | std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone); |
| 227 | return Certificate(zoneInfo["dkey"]); |
| 228 | } |
| 229 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 230 | Response |
| 231 | findResponse(Zone& zone, const Name& label, const name::Component& type) |
| 232 | { |
| 233 | Rrset rrset = findRrSet(zone, label, type); |
| 234 | Data data(rrset.getData()); |
| 235 | Response resp; |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 236 | resp.fromData(zone.getName(), data); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 237 | return resp; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | public: |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 241 | PreviousStateCleaner cleaner; // must be first variable |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 242 | ndns::ManagementTool m_tool; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 243 | ndns::DbMgr m_dbMgr; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 244 | |
| 245 | // Names of pre-created certificates |
| 246 | // Uncomment and run InitPreconfiguredKeys test case and then update names in the |
| 247 | // constructor. |
| 248 | Name rootKsk; |
| 249 | Name rootDsk; |
| 250 | Name otherKsk; |
| 251 | Name otherDsk; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 252 | Name rootDkey; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 253 | }; |
| 254 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 255 | BOOST_FIXTURE_TEST_SUITE(ManagementTool, ManagementToolFixture) |
| 256 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 257 | // BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture) |
| 258 | // { |
| 259 | // using time::seconds; |
| 260 | |
| 261 | // auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name { |
| 262 | // // to re-generate certificates, uncomment and then update rootKsk/rootDsk names |
| 263 | // Name kskName = m_keyChain.generateRsaKeyPair(zone, true); |
| 264 | // auto kskCert = m_keyChain |
| 265 | // .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)), |
| 266 | // time::fromUnixTimestamp(seconds(2147483648)), {}); |
| 267 | // if (parentCert.empty()) { |
| 268 | // m_keyChain.selfSign(*kskCert); |
| 269 | // } |
| 270 | // else { |
| 271 | // m_keyChain.sign(*kskCert, parentCert); |
| 272 | // } |
| 273 | // m_keyChain.addCertificate(*kskCert); |
| 274 | |
| 275 | // Name dskName = m_keyChain.generateRsaKeyPair(zone, false); |
| 276 | // auto dskCert = m_keyChain |
| 277 | // .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)), |
| 278 | // time::fromUnixTimestamp(seconds(2147483648)), {}); |
| 279 | // m_keyChain.sign(*dskCert, kskCert->getName()); |
| 280 | // m_keyChain.addCertificate(*dskCert); |
| 281 | |
| 282 | // return dskCert->getName(); |
| 283 | // }; |
| 284 | |
| 285 | // Name rootDsk = generateCerts(ROOT_ZONE); |
| 286 | // generateCerts("/ndns-test", rootDsk); |
| 287 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 288 | // copyDir(UNIT_TESTS_TMPDIR "/tests/unit/mgmt/.ndn", "/tmp/.ndn"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 289 | // std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl; |
| 290 | // } |
| 291 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 292 | BOOST_AUTO_TEST_CASE(SqliteLabelOrder) |
| 293 | { |
| 294 | // the correctness of our DoE design rely on the ordering of SQLite |
| 295 | // this unit test make sure that our label::isSmallerInLabelOrder |
| 296 | // is the same as the ordering of BLOB in SQLite |
| 297 | |
| 298 | std::random_device seed; |
| 299 | std::mt19937 gen(seed()); |
| 300 | |
| 301 | auto genRandomString = [&] (int length) -> std::string { |
| 302 | std::string charset = |
| 303 | "0123456789" |
| 304 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 305 | "abcdefghijklmnopqrstuvwxyz"; |
| 306 | std::uniform_int_distribution<size_t> dist(0, charset.size() - 1); |
| 307 | |
| 308 | std::string str(length, 0); |
| 309 | std::generate_n(str.begin(), length, [&] { return charset[dist(gen)];} ); |
| 310 | return str; |
| 311 | }; |
| 312 | |
| 313 | auto genRandomLabel = [&]() -> Name { |
| 314 | std::uniform_int_distribution<size_t> numberOfLabelsDist(1, 5); |
| 315 | std::uniform_int_distribution<size_t> labelSizeDist(1, 10); |
| 316 | Name nm; |
| 317 | size_t length = numberOfLabelsDist(gen); |
| 318 | for (size_t i = 0; i < length; i++) { |
| 319 | nm.append(genRandomString(labelSizeDist(gen))); |
| 320 | } |
| 321 | return nm; |
| 322 | }; |
| 323 | |
| 324 | const size_t NGENERATED_LABELS = 10; |
| 325 | |
| 326 | Zone zone = m_tool.createZone("/net/ndnsim", "/net"); |
| 327 | RrsetFactory rrsetFactory(TEST_DATABASE.string(), zone.getName(), |
| 328 | m_keyChain, DEFAULT_CERT); |
| 329 | rrsetFactory.checkZoneKey(); |
| 330 | std::vector<Rrset> rrsets; |
| 331 | std::vector<Name> names; |
| 332 | for (size_t i = 0; i < NGENERATED_LABELS; i++) { |
| 333 | Name randomLabel = genRandomLabel(); |
| 334 | Rrset randomTxt = rrsetFactory.generateTxtRrset(randomLabel, |
| 335 | VERSION_USE_UNIX_TIMESTAMP, |
| 336 | DEFAULT_CACHE_TTL, |
| 337 | {}); |
| 338 | |
| 339 | rrsets.push_back(randomTxt); |
| 340 | m_dbMgr.insert(randomTxt); |
| 341 | names.push_back(randomLabel); |
| 342 | } |
| 343 | |
| 344 | std::sort(rrsets.begin(), rrsets.end()); |
| 345 | |
| 346 | using boost::adaptors::filtered; |
| 347 | using boost::adaptors::transformed; |
| 348 | |
| 349 | std::vector<Rrset> rrsetsFromDb = m_dbMgr.findRrsets(zone); |
| 350 | auto fromDbFiltered = rrsetsFromDb | filtered([] (const Rrset& rrset) { |
| 351 | return rrset.getType() == label::TXT_RR_TYPE; |
| 352 | }); |
| 353 | |
| 354 | auto extractLabel = [] (const Rrset& rr) { |
| 355 | return rr.getLabel(); |
| 356 | }; |
| 357 | auto expected = rrsets | transformed(extractLabel); |
| 358 | auto actual = fromDbFiltered | transformed(extractLabel); |
| 359 | |
| 360 | BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), |
| 361 | actual.begin(), actual.end()); |
| 362 | } |
| 363 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 364 | BOOST_AUTO_TEST_CASE(CreateDeleteRootFixture) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 365 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 366 | // creating root_zone need a rootDkey |
| 367 | BOOST_CHECK_THROW(m_tool.createZone(ROOT_ZONE, ROOT_ZONE, |
| 368 | time::seconds(4600), |
| 369 | time::seconds(4600), |
| 370 | rootKsk, rootDsk), ndns::ManagementTool::Error); |
| 371 | |
| 372 | m_tool.createZone(ROOT_ZONE, ROOT_ZONE, |
| 373 | time::seconds(4600), |
| 374 | time::seconds(4600), |
| 375 | rootKsk, rootDsk, rootDkey); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 376 | |
| 377 | Zone zone(ROOT_ZONE); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 378 | Name zoneIdentityName = Name(ROOT_ZONE).append("NDNS"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 379 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 380 | BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, rootDsk)); |
| 381 | BOOST_CHECK_EQUAL(findCertFromDb(zone, rootDsk).getName(), rootDsk); |
| 382 | BOOST_CHECK_EQUAL(findCertFromDb(zone, rootKsk).getName(), rootKsk); |
| 383 | BOOST_CHECK_EQUAL(findDkeyFromDb(ROOT_ZONE).getName(), rootDkey); |
| 384 | |
| 385 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootDsk).getName(), rootDsk); |
| 386 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootKsk).getName(), rootKsk); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 387 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 388 | BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE)); |
| 389 | BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 392 | BOOST_AUTO_TEST_CASE(CreateDeleteChildFixture) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 393 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 394 | Name parentZoneName("/ndns-test"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 395 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 396 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 397 | Zone zone1(zoneName); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 398 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 399 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone1), false); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 400 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 401 | // will generate keys automatically |
| 402 | m_tool.createZone(zoneName, parentZoneName); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 404 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 405 | std::vector<Certificate>&& certs = getCerts(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 406 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 407 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 408 | const Name& ksk = certs[0].getName(); |
| 409 | const Name& dsk = certs[1].getName(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 410 | |
| 411 | Zone zone(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 412 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 413 | BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, dsk)); |
| 414 | BOOST_CHECK_EQUAL(findCertFromDb(zone, dsk).getName(), dsk); |
| 415 | BOOST_CHECK_EQUAL(findCertFromDb(zone, ksk).getName(), ksk); |
| 416 | |
| 417 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, dsk), findCertFromDb(zone, dsk)); |
| 418 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, ksk), findCertFromDb(zone, ksk)); |
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 | BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 421 | |
| 422 | BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 423 | BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error); |
| 424 | } |
| 425 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 426 | BOOST_AUTO_TEST_CASE(CreateZoneWithFixture) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 427 | { |
| 428 | Name parentZoneName("/ndns-test"); |
| 429 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 430 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 431 | |
| 432 | m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30)); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 433 | BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 434 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 435 | std::vector<Certificate>&& certs = getCerts(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 436 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 437 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 438 | const Name& dsk = certs[1].getName(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 439 | |
| 440 | // Check zone ttl |
| 441 | Zone zone(zoneName); |
| 442 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
| 443 | BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200)); |
| 444 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 445 | // check dkey name |
| 446 | Name dkeyName = Name(parentZoneName).append("NDNS").append(zoneName.getSubName(parentZoneName.size())); |
| 447 | Certificate dkey = findDkeyFromDb(zoneName); |
| 448 | BOOST_CHECK(dkeyName.isPrefixOf(dkey.getName())); |
| 449 | |
| 450 | // TODO: check signing hierarchy |
| 451 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 452 | // Check dsk rrset ttl |
| 453 | Rrset rrset; |
| 454 | BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE)); |
| 455 | BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200)); |
| 456 | |
| 457 | // Check certificate freshnessPeriod and validity |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 458 | Certificate cert = CertHelper::getCertificate(m_keyChain, zoneIdentityName, dsk); |
| 459 | time::system_clock::TimePoint beg,end; |
| 460 | std::tie(beg, end) = cert.getValidityPeriod().getPeriod(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 461 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 462 | BOOST_REQUIRE_NO_THROW(cert = findCertFromDb(zone, dsk)); |
| 463 | BOOST_CHECK_EQUAL(cert.getFreshnessPeriod(), time::seconds(4200)); |
| 464 | BOOST_CHECK_EQUAL(end - beg, time::days(30)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 465 | m_tool.deleteZone(zoneName); |
| 466 | } |
| 467 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 468 | BOOST_AUTO_TEST_CASE(ZoneCreatePreconditions) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 469 | { |
| 470 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net")); |
| 471 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error); |
| 472 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 473 | std::vector<Certificate>&& certs = getCerts("/net/ndnsim"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 474 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 475 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 476 | const Name& ksk = certs[0].getName(); |
| 477 | const Name& dsk = certs[1].getName(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 478 | |
| 479 | m_tool.deleteZone("/net/ndnsim"); |
| 480 | // identity will still exist after the zone is deleted |
| 481 | |
| 482 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error); |
| 483 | |
| 484 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error); |
| 485 | |
| 486 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 487 | time::seconds(1), time::days(1), ksk, dsk)); |
| 488 | BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2); |
| 489 | m_tool.deleteZone("/net/ndnsim"); |
| 490 | |
| 491 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 492 | time::seconds(1), time::days(1), Name(), dsk)); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 493 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 494 | m_tool.deleteZone("/net/ndnsim"); |
| 495 | |
| 496 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 497 | time::seconds(1), time::days(1), ksk, Name())); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 498 | m_tool.deleteZone("/net/ndnsim"); |
| 499 | |
| 500 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 501 | time::seconds(1), time::days(1), "/com/ndnsim"), |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 502 | ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 503 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 504 | Identity id = m_keyChain.createIdentity("/net/ndnsim/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 505 | Certificate cert = id.getDefaultKey().getDefaultCertificate(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 506 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 507 | time::seconds(1), time::days(1), cert.getName())); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 508 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 509 | id = m_keyChain.createIdentity("/com/ndnsim/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 510 | cert = id.getDefaultKey().getDefaultCertificate(); |
| 511 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 512 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 513 | time::seconds(1), time::days(1), cert.getName()), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 514 | ndns::ManagementTool::Error); |
| 515 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 516 | id = m_keyChain.createIdentity("/net/ndnsim/www/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 517 | cert = id.getDefaultKey().getDefaultCertificate(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 518 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 519 | time::seconds(1), time::days(1), cert.getName()), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 520 | ndns::ManagementTool::Error); |
| 521 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame^] | 522 | id = m_keyChain.createIdentity("/net/ndnsim/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 523 | cert = id.getDefaultKey().getDefaultCertificate(); |
| 524 | m_keyChain.deleteCertificate(id.getDefaultKey(), cert.getName()); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 525 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 526 | time::seconds(1), time::days(1), cert.getName()), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 527 | ndns::ManagementTool::Error); |
| 528 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 529 | // for root zone special case (requires a valid DKEY to be specified) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 530 | BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error); |
| 531 | |
| 532 | BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1), |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 533 | DEFAULT_CERT, DEFAULT_CERT, rootDkey)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | class OutputTester |
| 537 | { |
| 538 | public: |
| 539 | OutputTester() |
| 540 | : savedBuf(std::clog.rdbuf()) |
| 541 | { |
| 542 | std::cout.rdbuf(buffer.rdbuf()); |
| 543 | } |
| 544 | |
| 545 | ~OutputTester() |
| 546 | { |
| 547 | std::cout.rdbuf(savedBuf); |
| 548 | } |
| 549 | |
| 550 | public: |
| 551 | std::stringstream buffer; |
| 552 | std::streambuf* savedBuf; |
| 553 | }; |
| 554 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 555 | // BOOST_AUTO_TEST_CASE(ExportCertificate) |
| 556 | // { |
| 557 | // std::string outputFile = TEST_CERTDIR.string() + "/ss.cert"; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 558 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 559 | // BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile), |
| 560 | // ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 561 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 562 | // BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false); |
| 563 | // // doesn't check the zone, export from KeyChain directly |
| 564 | // BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile)); |
| 565 | // BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 566 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 567 | // std::string dskValue = |
| 568 | // "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n" |
| 569 | // "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n" |
| 570 | // "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n" |
| 571 | // "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n" |
| 572 | // "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n" |
| 573 | // "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n" |
| 574 | // "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n" |
| 575 | // "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n" |
| 576 | // "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n" |
| 577 | // "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n" |
| 578 | // "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n" |
| 579 | // "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n" |
| 580 | // "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n" |
| 581 | // "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n" |
| 582 | // "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n" |
| 583 | // "8UNqhMpjAZwW6pdvOZADVg==\n"; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 584 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 585 | // { |
| 586 | // std::ifstream ifs(outputFile.c_str()); |
| 587 | // std::string actualValue((std::istreambuf_iterator<char>(ifs)), |
| 588 | // std::istreambuf_iterator<char>()); |
| 589 | // BOOST_CHECK_EQUAL(actualValue, dskValue); |
| 590 | // } |
| 591 | // boost::filesystem::remove(outputFile); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 592 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 593 | // // doesn't check the zone, export from KeyChain directly |
| 594 | // BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile)); |
| 595 | // boost::filesystem::remove(outputFile); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 596 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 597 | // Name zoneName("/ndns-test"); |
| 598 | // m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30), |
| 599 | // otherKsk, otherDsk); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 600 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 601 | // m_keyChain.deleteCertificate(otherKsk); |
| 602 | // m_keyChain.deleteCertificate(otherDsk); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 603 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 604 | // // retrieve cert from the zone |
| 605 | // BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile)); |
| 606 | // { |
| 607 | // std::ifstream ifs(outputFile.c_str()); |
| 608 | // std::string actualValue((std::istreambuf_iterator<char>(ifs)), |
| 609 | // std::istreambuf_iterator<char>()); |
| 610 | // BOOST_CHECK_EQUAL(actualValue, dskValue); |
| 611 | // } |
| 612 | // boost::filesystem::remove(outputFile); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 613 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 614 | // BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile), |
| 615 | // ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 616 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 617 | // // output to std::cout |
| 618 | // std::string acutalOutput; |
| 619 | // { |
| 620 | // OutputTester tester; |
| 621 | // m_tool.exportCertificate(otherDsk, "-"); |
| 622 | // acutalOutput = tester.buffer.str(); |
| 623 | // } |
| 624 | // BOOST_CHECK_EQUAL(acutalOutput, dskValue); |
| 625 | // } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 626 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 627 | BOOST_AUTO_TEST_CASE(AddRrset) |
| 628 | { |
| 629 | Name zoneName("/ndns-test"); |
| 630 | Zone zone(zoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 631 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 632 | time::seconds ttl1(4200); |
| 633 | time::seconds ttl2(4500); |
| 634 | m_tool.createZone(zoneName, ROOT_ZONE, ttl1); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 635 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 636 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 637 | rf.checkZoneKey(); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 638 | Rrset rrset1 = rf.generateNsRrset("/l1", 7654, ttl2, DelegationList()); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 639 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 640 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1)); |
| 641 | Rrset rrset2 = findRrSet(zone, "/l1", label::NS_RR_TYPE); |
| 642 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 643 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 644 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 645 | BOOST_AUTO_TEST_CASE(AddMultiLevelLabelRrset) |
| 646 | { |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 647 | Name zoneName("/ndns-test"); |
| 648 | Zone zone(zoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 649 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 650 | time::seconds ttl(4200); |
| 651 | m_tool.createZone(zoneName, ROOT_ZONE, ttl); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 652 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 653 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 654 | rf.checkZoneKey(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 655 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 656 | auto checkRrset = [&zone, &zoneName, this](Name label, |
| 657 | name::Component type, |
| 658 | NdnsContentType contentType) -> void { |
| 659 | Rrset rr1 = findRrSet(zone, label, type); |
| 660 | BOOST_CHECK_EQUAL(Data(rr1.getData()).getContentType(), contentType); |
| 661 | Response response1; |
| 662 | response1.fromData(zoneName, Data(rr1.getData())); |
| 663 | BOOST_CHECK_EQUAL(response1.getRrLabel(), label); |
| 664 | }; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 665 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 666 | Name labelName("/l1/l2/l3"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 667 | |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 668 | Rrset rrset1 = rf.generateNsRrset(labelName, 7654, ttl, DelegationList()); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 669 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 670 | //add NS NDNS_AUTH and check user-defined ttl |
| 671 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(rrset1, rf, ttl)); |
| 672 | Rrset rrset2 = findRrSet(zone, labelName, label::NS_RR_TYPE); |
| 673 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 674 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 675 | checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 676 | checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 677 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 678 | // insert a same-name rrset with TXT type |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 679 | Rrset txtRr = rf.generateTxtRrset("/l1/l2/l3", 7654, ttl, std::vector<std::string>()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 680 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(txtRr, rf, ttl)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 681 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 682 | checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 683 | checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 684 | checkRrset("/l1/l2/l3", label::TXT_RR_TYPE, ndns::NDNS_RESP); |
| 685 | // check that there is no confliction |
| 686 | checkRrset("/l1/l2/l3", label::NS_RR_TYPE, ndns::NDNS_LINK); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 687 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 688 | // insert a shorter NS, when there are longer NS or TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 689 | Rrset shorterNs = rf.generateNsRrset("/l1/l2", 7654, ttl, DelegationList()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 690 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(shorterNs, rf, ttl), |
| 691 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 692 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 693 | // insert a longer NS, when there is already a shorter NS |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 694 | Rrset longerNs = rf.generateNsRrset("/l1/l2/l3/l4", 7654, ttl, DelegationList()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 695 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(longerNs, rf, ttl), |
| 696 | ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 697 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 698 | // insert a smaller TXT, when there are longer NS and TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 699 | Rrset shorterTxt = rf.generateTxtRrset("/l1/l2", 7654, ttl, std::vector<std::string>()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 700 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(shorterTxt, rf, ttl)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 701 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 702 | // insert a smaller NS, when there is long TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 703 | Rrset longTxt = rf.generateTxtRrset("/k1/k2/k3", 7654, ttl, std::vector<std::string>()); |
| 704 | Rrset smallerNs = rf.generateNsRrset("/k1/k2", 7654, ttl, DelegationList()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 705 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longTxt, rf, ttl)); |
| 706 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(smallerNs, rf, ttl), |
| 707 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 708 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 709 | // inserting a longer TXT, when there is shoter TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 710 | Rrset longerTxt = rf.generateTxtRrset("/k1/k2/k3/k4", 7654, ttl, std::vector<std::string>()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 711 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longerTxt, rf, ttl)); |
| 712 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 713 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 714 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertPreConditon) |
| 715 | { |
| 716 | // check pre-condition |
| 717 | Name zoneName("/ndns-test"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 718 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 719 | // Check: throw if zone not exist |
| 720 | std::string certPath = TEST_CERTDIR.string(); |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 721 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 722 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 723 | m_tool.createZone(zoneName, ROOT_ZONE); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 724 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 725 | // Check: throw if certificate does not match |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 726 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 727 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 728 | std::string rightCertPath = TEST_CERTDIR.string() + "/ss.cert"; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 729 | std::vector<Certificate>&& certs = getCerts(zoneName); |
| 730 | const Name& ksk = certs[0].getName(); |
| 731 | m_tool.exportCertificate(ksk, rightCertPath); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 732 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 733 | // Check: throw if it's a duplicated certificate |
| 734 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, rightCertPath), ndns::ManagementTool::Error); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 735 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 736 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 737 | BOOST_AUTO_TEST_CASE(AddRrSetDskCert) |
| 738 | { |
| 739 | Name parentZoneName("/ndns-test"); |
| 740 | Name zoneName("/ndns-test/child-zone"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 741 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 742 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 743 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 744 | m_tool.createZone(zoneName, parentZoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 745 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 746 | Zone zone(zoneName); |
| 747 | Zone parentZone(parentZoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 748 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 749 | Certificate dkey(findDkeyFromDb(zone.getName())); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 750 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 751 | ndn::io::save(dkey, output); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 752 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 753 | BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output)); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 754 | // Check if child zone's d-key could be inserted correctly |
| 755 | BOOST_CHECK_NO_THROW(findRrSet(parentZone, getLabel(parentZone, dkey.getName()), label::CERT_RR_TYPE)); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 756 | } |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 757 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 758 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertUserProvidedCert) |
| 759 | { |
| 760 | //check using user provided certificate |
| 761 | Name parentZoneName("/ndns-test"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 762 | Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 763 | Name zoneName("/ndns-test/child-zone"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 764 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 765 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 766 | // Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false); |
| 767 | Identity id = CertHelper::getIdentity(m_keyChain, parentZoneIdentityName); |
| 768 | Key dsk = m_keyChain.createKey(id); |
| 769 | Certificate dskCert = dsk.getDefaultCertificate(); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 770 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 771 | // check addRrsetFromFile1 |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 772 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 773 | m_tool.createZone(zoneName, parentZoneName); |
| 774 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 775 | Certificate dkey(findDkeyFromDb(zoneName)); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 776 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 777 | ndn::io::save(dkey, output); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 778 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 779 | BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output, time::seconds(4600), |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 780 | dskCert.getName())); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertInvalidOutput) |
| 784 | { |
| 785 | //check invalid output |
| 786 | Name parentZoneName("/ndns-test"); |
| 787 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 788 | m_tool.createZone(zoneName, parentZoneName); |
| 789 | |
| 790 | Name content = "invalid data packet"; |
| 791 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
| 792 | ndn::io::save(content, output); |
| 793 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 794 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, output), ndns::ManagementTool::Error); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | BOOST_AUTO_TEST_CASE(AddRrSetVersionControl) |
| 798 | { |
| 799 | //check version control |
| 800 | time::seconds ttl(4200); |
| 801 | Name parentZoneName("/ndns-test"); |
| 802 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 803 | m_tool.createZone(zoneName, parentZoneName); |
| 804 | |
| 805 | Name label("/label"); |
| 806 | uint64_t version = 110; |
| 807 | |
| 808 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 809 | rf.checkZoneKey(); |
| 810 | |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 811 | Rrset rrset1 = rf.generateTxtRrset(label, version, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 812 | |
| 813 | m_tool.addRrset(rrset1); |
| 814 | // throw error when adding duplicated rrset with the same version |
| 815 | BOOST_CHECK_THROW(m_tool.addRrset(rrset1), |
| 816 | ndns::ManagementTool::Error); |
| 817 | version--; |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 818 | Rrset rrset2 = rf.generateTxtRrset(label, version, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 819 | // throw error when adding duplicated rrset with older version |
| 820 | BOOST_CHECK_THROW(m_tool.addRrset(rrset2), |
| 821 | ndns::ManagementTool::Error); |
| 822 | |
| 823 | version++; |
| 824 | version++; |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 825 | Rrset rrset3 = rf.generateTxtRrset(label, version, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 826 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset3)); |
| 827 | |
| 828 | Zone zone(zoneName); |
| 829 | m_dbMgr.find(zone); |
| 830 | Rrset rrset; |
| 831 | rrset.setZone(&zone); |
| 832 | rrset.setLabel(label); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 833 | rrset.setType(label::TXT_RR_TYPE); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 834 | m_dbMgr.find(rrset); |
| 835 | |
| 836 | BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version)); |
| 837 | } |
| 838 | |
| 839 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertFormat) |
| 840 | { |
| 841 | //check input with different formats |
| 842 | Name parentZoneName("/ndns-test"); |
| 843 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 844 | Zone parentZone(parentZoneName); |
| 845 | |
| 846 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 847 | m_tool.createZone(zoneName, parentZoneName); |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 848 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 849 | Certificate cert(findDkeyFromDb(zoneName)); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 850 | std::string output = TEST_CERTDIR.string() + "/a.cert"; |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 851 | |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 852 | Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY); |
| 853 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 854 | // base64 |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 855 | ndn::io::save(cert, output, ndn::io::BASE64); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 856 | BOOST_CHECK_NO_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 857 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64)); |
| 858 | m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 859 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 860 | // raw |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 861 | ndn::io::save(cert, output, ndn::io::NO_ENCODING); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 862 | BOOST_CHECK_NO_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 863 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING)); |
| 864 | m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 865 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 866 | // hex |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 867 | ndn::io::save(cert, output, ndn::io::HEX); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 868 | BOOST_CHECK_NO_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 869 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX)); |
| 870 | m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 871 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 872 | // incorrect encoding input |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 873 | ndn::io::save(cert, output, ndn::io::HEX); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 874 | BOOST_CHECK_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 875 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, |
| 876 | static_cast<ndn::io::IoEncoding>(127)), |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 877 | ndns::ManagementTool::Error); |
| 878 | } |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 879 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 880 | BOOST_AUTO_TEST_CASE(ListAllZones) |
| 881 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 882 | m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk, rootDkey); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 883 | 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] | 884 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 885 | Name rootDskName = CertHelper::getCertificate(m_keyChain, "/NDNS/", rootDsk).getKeyName(); |
| 886 | Name otherDskName = CertHelper::getCertificate(m_keyChain, "/ndns-test/NDNS/", otherDsk).getKeyName(); |
| 887 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 888 | std::string expectedValue = |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 889 | "/ ; default-ttl=1 default-key=" + rootDskName.toUri() + " " |
| 890 | "default-certificate=" + rootDsk.toUri() + "\n" |
| 891 | "/ndns-test ; default-ttl=10 default-key=" + otherDskName.toUri() + " " |
| 892 | "default-certificate=" + otherDsk.toUri() + "\n"; |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 893 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 894 | output_test_stream testOutput; |
| 895 | m_tool.listAllZones(testOutput); |
| 896 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 897 | } |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 898 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 899 | // Test need to fix values of keys, otherwise it produces different values every time |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 900 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 901 | // BOOST_AUTO_TEST_CASE(ListZone) |
| 902 | // { |
| 903 | // 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] | 904 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 905 | // RrsetFactory rf(TEST_DATABASE, "/ndns-test", m_keyChain, DEFAULT_CERT); |
| 906 | // rf.checkZoneKey(); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 907 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 908 | // // Add NS with NDNS_RESP |
| 909 | // Delegation del; |
| 910 | // del.preference = 10; |
| 911 | // del.name = Name("/get/link"); |
| 912 | // DelegationList ds = {del}; |
| 913 | // Rrset rrset1 = rf.generateNsRrset("/label1", 100, DEFAULT_RR_TTL, ds); |
| 914 | // m_tool.addRrset(rrset1); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 915 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 916 | // // Add NS with NDNS_AUTH |
| 917 | // Rrset rrset2 = rf.generateAuthRrset("/label2", 100000, DEFAULT_RR_TTL); |
| 918 | // m_tool.addRrset(rrset2); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 919 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 920 | // // Add TXT from file |
| 921 | // std::string output = TEST_CERTDIR.string() + "/a.rrset"; |
| 922 | // Response re1; |
| 923 | // re1.setZone("/ndns-test"); |
| 924 | // re1.setQueryType(label::NDNS_ITERATIVE_QUERY); |
| 925 | // re1.setRrLabel("/label2"); |
| 926 | // re1.setRrType(label::TXT_RR_TYPE); |
| 927 | // re1.setContentType(NDNS_RESP); |
| 928 | // re1.setVersion(name::Component::fromVersion(654321)); |
| 929 | // re1.addRr("First RR"); |
| 930 | // re1.addRr("Second RR"); |
| 931 | // re1.addRr("Last RR"); |
| 932 | // shared_ptr<Data> data1 = re1.toData(); |
| 933 | // m_keyChain.sign(*data1, security::signingByCertificate(otherDsk)); |
| 934 | // ndn::io::save(*data1, output); |
| 935 | // m_tool.addRrsetFromFile("/ndns-test", output); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 936 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 937 | // // Add TXT in normal way |
| 938 | // Rrset rrset3 = rf.generateTxtRrset("/label3", 3333, DEFAULT_RR_TTL, {"Hello", "World"}); |
| 939 | // m_tool.addRrset(rrset3); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 940 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 941 | // m_tool.listZone("/ndns-test", std::cout, true); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 942 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 943 | // output_test_stream testOutput; |
| 944 | // m_tool.listZone("/ndns-test", testOutput, true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 945 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 946 | // std::string expectedValue = |
| 947 | // R"VALUE(; Zone /ndns-test |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 948 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 949 | // ; rrset=/ type=DOE version=%FD%00%00%01b%26e%AE%99 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 950 | // / 3600 DOE Bw0IBmxhYmVsMwgDVFhU |
| 951 | // / 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 952 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 953 | // /KEY/%12%05t%90%3AjvA 10 CERT ; content-type=KEY version=%FD%00%00%01b%26e%AEY signed-by=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
| 954 | // Certificate name: |
| 955 | // /ndns-test/NDNS/KEY/%12%05t%90%3AjvA/CERT/%FD%00%00%01b%26e%AEY |
| 956 | // Validity: |
| 957 | // NotBefore: 20180314T212340 |
| 958 | // NotAfter: 20180324T212340 |
| 959 | // Public key bits: |
| 960 | // MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA |
| 961 | // AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA//// |
| 962 | // ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd |
| 963 | // NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5 |
| 964 | // RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA |
| 965 | // //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABHU62fbCa6KR7G1iyMr6/NtF |
| 966 | // 5oHrAdzttIgh5pk1VS1YcFO1zhpUnpJS43FlduYHVBLrXwYS6tZ15Ge/D3uy1f4= |
| 967 | // Signature Information: |
| 968 | // Signature Type: SignatureSha256WithEcdsa |
| 969 | // Key Locator: Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 970 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 971 | // ; rrset=/KEY/%12%05t%90%3AjvA/CERT type=DOE version=%FD%00%00%01b%26e%AE%91 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 972 | // /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ= |
| 973 | // /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 974 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 975 | // /KEY/%8D%1Dj%1E%BE%B0%2A%E4 10 CERT ; content-type=KEY version=%FD%00%00%01b%26e%AEX signed-by=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
| 976 | // Certificate name: |
| 977 | // /ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT/%FD%00%00%01b%26e%AEX |
| 978 | // Validity: |
| 979 | // NotBefore: 20180314T212340 |
| 980 | // NotAfter: 20180324T212340 |
| 981 | // Public key bits: |
| 982 | // MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA |
| 983 | // AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA//// |
| 984 | // ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd |
| 985 | // NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5 |
| 986 | // RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA |
| 987 | // //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABMRVD/FUfCQVvjcwQLe9k1aS |
| 988 | // 5pZ/xmFndOHn1+a0OYVzxCV1JcxL1eojcij42tCP5mtocrj9DjYyFBv4Atg1RZE= |
| 989 | // Signature Information: |
| 990 | // Signature Type: SignatureSha256WithEcdsa |
| 991 | // Key Locator: Self-Signed Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 992 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 993 | // ; rrset=/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT type=DOE version=%FD%00%00%01b%26e%AE%93 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 994 | // /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ= |
| 995 | // /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BwwIBmxhYmVsMQgCTlM= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 996 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 997 | // ; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 998 | // /label1 10 NS 10 |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 999 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 1000 | // ; rrset=/label1/NS type=DOE version=%FD%00%00%01b%26e%AE%94 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1001 | // /label1/NS 3600 DOE BwwIBmxhYmVsMQgCTlM= |
| 1002 | // /label1/NS 3600 DOE BwwIBmxhYmVsMggCTlM= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1003 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 1004 | // ; rrset=/label2 type=NS version=%FD%00%01%86%A0 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1005 | // /label2 10 NS NDNS-Auth |
| 1006 | |
| 1007 | // ; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1008 | // /label2 10 TXT First RR |
| 1009 | // /label2 10 TXT Second RR |
| 1010 | // /label2 10 TXT Last RR |
| 1011 | |
| 1012 | // ; rrset=/label2/NS type=DOE version=%FD%00%00%01b%26e%AE%96 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1013 | // /label2/NS 3600 DOE BwwIBmxhYmVsMggCTlM= |
| 1014 | // /label2/NS 3600 DOE Bw0IBmxhYmVsMggDVFhU |
| 1015 | |
| 1016 | // ; rrset=/label2/TXT type=DOE version=%FD%00%00%01b%26e%AE%97 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1017 | // /label2/TXT 3600 DOE Bw0IBmxhYmVsMggDVFhU |
| 1018 | // /label2/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU |
| 1019 | |
| 1020 | // ; rrset=/label3 type=TXT version=%FD%0D%05 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1021 | // /label3 10 TXT Hello |
| 1022 | // /label3 10 TXT World |
| 1023 | |
| 1024 | // ; rrset=/label3/TXT type=DOE version=%FD%00%00%01b%26e%AE%98 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1025 | // /label3/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU |
| 1026 | // /label3/TXT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ= |
| 1027 | |
| 1028 | // )VALUE"; |
| 1029 | |
| 1030 | // BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 1031 | // } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1032 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1033 | BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture) |
| 1034 | { |
| 1035 | Name zoneName("/ndns-test"); |
| 1036 | m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 1037 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 1038 | rf.checkZoneKey(); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 1039 | Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {"Value1", "Value2"}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1040 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1041 | m_tool.addRrset(rrset1); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1042 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 1043 | std::stringstream os; |
| 1044 | |
| 1045 | using security::transform::base64Encode; |
| 1046 | using security::transform::streamSink; |
| 1047 | using security::transform::bufferSource; |
| 1048 | |
| 1049 | bufferSource(rrset1.getData().wire(), rrset1.getData().size()) >> base64Encode() >> streamSink(os); |
| 1050 | |
| 1051 | std::string expectedValue = os.str(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1052 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1053 | output_test_stream testOutput; |
| 1054 | m_tool.getRrSet(zoneName, "/label",label::TXT_RR_TYPE, testOutput); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1055 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 1056 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1057 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1058 | BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture) |
| 1059 | { |
| 1060 | Name zoneName("/ndns-test"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1061 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1062 | m_tool.createZone(zoneName, ROOT_ZONE); |
| 1063 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 1064 | rf.checkZoneKey(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1065 | |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 1066 | Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1067 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1068 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1069 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1070 | Zone zone(zoneName); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 1071 | BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::TXT_RR_TYPE)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1072 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1073 | 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] | 1074 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1075 | BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error); |
| 1076 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1077 | |
| 1078 | BOOST_AUTO_TEST_SUITE_END() |
| 1079 | |
| 1080 | } // namespace tests |
| 1081 | } // namespace ndns |
| 1082 | } // namespace ndn |