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