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