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