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