Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California. |
| 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 | |
| 20 | #include "daemon/db-mgr.hpp" |
| 21 | #include "daemon/name-server.hpp" |
| 22 | #include "clients/response.hpp" |
| 23 | #include "clients/query.hpp" |
| 24 | #include "logger.hpp" |
| 25 | |
| 26 | #include "../database-test-data.hpp" |
| 27 | #include "../../boost-test.hpp" |
| 28 | |
| 29 | #include <boost/filesystem.hpp> |
| 30 | #include <ndn-cxx/face.hpp> |
| 31 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace ndns { |
| 35 | namespace tests { |
| 36 | |
| 37 | NDNS_LOG_INIT("NameServerTest"); |
| 38 | |
| 39 | class NameServerFixture : public DbTestData |
| 40 | { |
| 41 | public: |
| 42 | NameServerFixture() |
| 43 | : face(ndn::util::makeDummyClientFace({ false, true })) |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 44 | , zone(m_root.getName()) |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 45 | , validator(*face) |
| 46 | , server(zone, m_certName, *face, m_session, m_keyChain, validator) |
| 47 | { |
| 48 | // ensure prefix is registered |
| 49 | run(); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | run() |
| 54 | { |
| 55 | face->getIoService().poll(); |
| 56 | face->getIoService().reset(); |
| 57 | } |
| 58 | |
| 59 | public: |
| 60 | shared_ptr<ndn::util::DummyClientFace> face; |
| 61 | Name hint; |
| 62 | const Name& zone; |
| 63 | Validator validator; |
| 64 | ndns::NameServer server; |
| 65 | }; |
| 66 | |
| 67 | BOOST_FIXTURE_TEST_SUITE(NameServer, NameServerFixture) |
| 68 | |
| 69 | BOOST_AUTO_TEST_CASE(NdnsQuery) |
| 70 | { |
| 71 | Query q(hint, zone, ndns::label::NDNS_ITERATIVE_QUERY); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 72 | q.setRrLabel(Name("net")); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 73 | q.setRrType(ndns::label::NS_RR_TYPE); |
| 74 | |
| 75 | bool hasDataBack = false; |
| 76 | |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 77 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 78 | hasDataBack = true; |
| 79 | NDNS_LOG_TRACE("get Data back"); |
| 80 | BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName()); |
| 81 | |
| 82 | Response resp; |
| 83 | BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data)); |
| 84 | BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 85 | }); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 86 | |
| 87 | face->receive(q.toInterest()); |
| 88 | |
| 89 | run(); |
| 90 | |
| 91 | BOOST_CHECK_EQUAL(hasDataBack, true); |
| 92 | } |
| 93 | |
| 94 | BOOST_AUTO_TEST_CASE(KeyQuery) |
| 95 | { |
| 96 | Query q(hint, zone, ndns::label::NDNS_ITERATIVE_QUERY); |
| 97 | q.setQueryType(ndns::label::NDNS_CERT_QUERY); |
| 98 | q.setRrType(ndns::label::CERT_RR_TYPE); |
| 99 | |
| 100 | size_t nDataBack = 0; |
| 101 | |
| 102 | // will ask for non-existing record |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 103 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 104 | ++nDataBack; |
| 105 | NDNS_LOG_TRACE("get Data back"); |
| 106 | BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName()); |
| 107 | |
| 108 | Response resp; |
| 109 | BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data)); |
| 110 | BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_NACK); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 111 | }); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 112 | |
| 113 | face->receive(q.toInterest()); |
| 114 | run(); |
| 115 | |
| 116 | // will ask for the existing record (will have type NDNS_RAW, as it is certificate) |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 117 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 118 | ++nDataBack; |
| 119 | NDNS_LOG_TRACE("get Data back"); |
| 120 | BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName()); |
| 121 | |
| 122 | Response resp; |
| 123 | BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data)); |
| 124 | BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RAW); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 125 | }); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 126 | |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 127 | q.setRrLabel("dsk-1"); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 128 | |
| 129 | face->receive(q.toInterest()); |
| 130 | run(); |
| 131 | |
| 132 | BOOST_CHECK_EQUAL(nDataBack, 2); |
| 133 | } |
| 134 | |
| 135 | BOOST_AUTO_TEST_CASE(UpdateReplaceRr) |
| 136 | { |
| 137 | Response re; |
| 138 | re.setZone(zone); |
| 139 | re.setQueryType(label::NDNS_ITERATIVE_QUERY); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 140 | re.setRrLabel(Name("net")); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 141 | re.setRrType(label::NS_RR_TYPE); |
| 142 | re.setNdnsType(NDNS_RESP); |
| 143 | |
| 144 | std::string str = "ns1.ndnsim.net"; |
| 145 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 146 | str = "ns2.ndnsim.net"; |
| 147 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 148 | |
| 149 | shared_ptr<Data> data = re.toData(); |
| 150 | m_keyChain.sign(*data, m_certName); |
| 151 | |
| 152 | Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY); |
| 153 | const Block& block = data->wireEncode(); |
| 154 | Name name; |
| 155 | name.append(block); |
| 156 | |
| 157 | q.setRrLabel(name); |
| 158 | q.setRrType(label::NDNS_UPDATE_LABEL); |
| 159 | |
| 160 | bool hasDataBack = false; |
| 161 | |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 162 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 163 | hasDataBack = true; |
| 164 | NDNS_LOG_TRACE("get Data back"); |
| 165 | BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName()); |
| 166 | Response resp; |
| 167 | |
| 168 | BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data)); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 169 | BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough |
| 170 | BOOST_CHECK_GT(resp.getRrs().size(), 0); |
| 171 | Block block = resp.getRrs()[0]; |
| 172 | block.parse(); |
| 173 | int ret = -1; |
| 174 | BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData); |
| 175 | Block::element_const_iterator val = block.elements_begin(); |
| 176 | BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code |
| 177 | ret = readNonNegativeInteger(*val); |
| 178 | BOOST_CHECK_EQUAL(ret, 0); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 179 | }); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 180 | |
| 181 | face->receive(q.toInterest()); |
| 182 | run(); |
| 183 | |
| 184 | BOOST_CHECK_EQUAL(hasDataBack, true); |
| 185 | } |
| 186 | |
| 187 | BOOST_AUTO_TEST_CASE(UpdateInsertNewRr) |
| 188 | { |
| 189 | Response re; |
| 190 | re.setZone(zone); |
| 191 | re.setQueryType(label::NDNS_ITERATIVE_QUERY); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 192 | re.setRrLabel(Name("net-XYZ")); // insert new records |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 193 | re.setRrType(label::NS_RR_TYPE); |
| 194 | re.setNdnsType(NDNS_RESP); |
| 195 | |
| 196 | std::string str = "ns1.ndnsim.net"; |
| 197 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 198 | str = "ns2.ndnsim.net"; |
| 199 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 200 | |
| 201 | shared_ptr<Data> data = re.toData(); |
| 202 | m_keyChain.sign(*data, m_certName); |
| 203 | |
| 204 | Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY); |
| 205 | const Block& block = data->wireEncode(); |
| 206 | Name name; |
| 207 | name.append(block); |
| 208 | |
| 209 | q.setRrLabel(name); |
| 210 | q.setRrType(label::NDNS_UPDATE_LABEL); |
| 211 | |
| 212 | bool hasDataBack = false; |
| 213 | |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 214 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 215 | hasDataBack = true; |
| 216 | NDNS_LOG_TRACE("get Data back"); |
| 217 | BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName()); |
| 218 | Response resp; |
| 219 | |
| 220 | BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data)); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 221 | BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough |
| 222 | BOOST_CHECK_GT(resp.getRrs().size(), 0); |
| 223 | Block block = resp.getRrs()[0]; |
| 224 | block.parse(); |
| 225 | int ret = -1; |
| 226 | BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData); |
| 227 | Block::element_const_iterator val = block.elements_begin(); |
| 228 | BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code |
| 229 | ret = readNonNegativeInteger(*val); |
| 230 | BOOST_CHECK_EQUAL(ret, 0); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 231 | }); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 232 | |
| 233 | face->receive(q.toInterest()); |
| 234 | run(); |
| 235 | |
| 236 | BOOST_CHECK_EQUAL(hasDataBack, true); |
| 237 | } |
| 238 | |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 239 | BOOST_AUTO_TEST_CASE(UpdateValidatorCannotFetchCert) |
| 240 | { |
| 241 | Name dskName = m_keyChain.generateRsaKeyPair(TEST_IDENTITY_NAME, false); |
| 242 | std::vector<CertificateSubjectDescription> desc; |
| 243 | time::system_clock::TimePoint notBefore = time::system_clock::now(); |
| 244 | time::system_clock::TimePoint notAfter = notBefore + time::days(365); |
| 245 | shared_ptr<IdentityCertificate> dskCert = |
| 246 | m_keyChain.prepareUnsignedIdentityCertificate(dskName, m_certName, |
| 247 | notBefore, notAfter, desc); |
| 248 | |
| 249 | m_keyChain.sign(*dskCert, m_certName); |
| 250 | m_keyChain.addCertificateAsKeyDefault(*dskCert); |
| 251 | NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert->getName() << ". KeyLocator: " |
| 252 | << dskCert->getSignature().getKeyLocator().getName()); |
| 253 | |
| 254 | Rrset rrset(&m_root); |
| 255 | Name label = dskCert->getName().getPrefix(-2).getSubName(m_root.getName().size() + 1); |
| 256 | rrset.setLabel(label); |
| 257 | rrset.setType(label::CERT_RR_TYPE); |
| 258 | rrset.setVersion(dskCert->getName().get(-1)); |
| 259 | rrset.setTtl(m_root.getTtl()); |
| 260 | rrset.setData(dskCert->wireEncode()); |
| 261 | m_session.insert(rrset); |
| 262 | NDNS_LOG_TRACE("DB: zone " << m_root << " add a ID-CERT RR with name=" |
| 263 | << dskCert->getName() << " rrLabel=" << label); |
| 264 | |
| 265 | Response re; |
| 266 | re.setZone(zone); |
| 267 | re.setQueryType(label::NDNS_ITERATIVE_QUERY); |
| 268 | re.setRrLabel(Name("ndnsim-XYZ")); // insert new records |
| 269 | re.setRrType(label::NS_RR_TYPE); |
| 270 | re.setNdnsType(NDNS_RESP); |
| 271 | |
| 272 | std::string str = "ns1.ndnsim.net"; |
| 273 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 274 | str = "ns2.ndnsim.net"; |
| 275 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 276 | |
| 277 | shared_ptr<Data> data = re.toData(); |
| 278 | m_keyChain.sign(*data, dskCert->getName()); |
| 279 | |
| 280 | Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY); |
| 281 | const Block& block = data->wireEncode(); |
| 282 | Name name; |
| 283 | name.append(block); |
| 284 | |
| 285 | q.setRrLabel(name); |
| 286 | q.setRrType(label::NDNS_UPDATE_LABEL); |
| 287 | |
| 288 | bool hasDataBack = false; |
| 289 | |
| 290 | // no data back, since the Update cannot pass verification |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 291 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 292 | hasDataBack = true; |
| 293 | BOOST_FAIL("UNEXPECTED"); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 294 | }); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 295 | |
| 296 | face->receive(q.toInterest()); |
| 297 | run(); |
| 298 | |
| 299 | BOOST_CHECK_EQUAL(hasDataBack, false); |
| 300 | } |
| 301 | |
| 302 | class NameServerFixture2 : public DbTestData |
| 303 | { |
| 304 | public: |
| 305 | NameServerFixture2() |
| 306 | : face(ndn::util::makeDummyClientFace(io, { false, true })) |
| 307 | , validatorFace(ndn::util::makeDummyClientFace(io, { false, true })) |
| 308 | , zone(m_root.getName()) |
| 309 | , validator(*validatorFace) // different face for validator |
| 310 | , server(zone, m_certName, *face, m_session, m_keyChain, validator) |
| 311 | { |
| 312 | // ensure prefix is registered |
| 313 | run(); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 314 | validatorFace->onSendInterest.connect([&] (const Interest& interest) { |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 315 | NDNS_LOG_TRACE("validatorFace get Interest: " << interest.getName()); |
| 316 | face->receive(interest); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 317 | }); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void |
| 321 | run() |
| 322 | { |
| 323 | io.poll(); |
| 324 | io.reset(); |
| 325 | } |
| 326 | |
| 327 | public: |
| 328 | boost::asio::io_service io; |
| 329 | shared_ptr<ndn::util::DummyClientFace> face; |
| 330 | shared_ptr<ndn::util::DummyClientFace> validatorFace; |
| 331 | Name hint; |
| 332 | const Name& zone; |
| 333 | Validator validator; |
| 334 | ndns::NameServer server; |
| 335 | }; |
| 336 | |
| 337 | BOOST_FIXTURE_TEST_CASE(UpdateValidatorFetchCert, NameServerFixture2) |
| 338 | { |
| 339 | Name dskName = m_keyChain.generateRsaKeyPair(TEST_IDENTITY_NAME, false); |
| 340 | std::vector<CertificateSubjectDescription> desc; |
| 341 | time::system_clock::TimePoint notBefore = time::system_clock::now(); |
| 342 | time::system_clock::TimePoint notAfter = notBefore + time::days(365); |
| 343 | shared_ptr<IdentityCertificate> dskCert = |
| 344 | m_keyChain.prepareUnsignedIdentityCertificate(dskName, m_certName, |
| 345 | notBefore, notAfter, desc); |
| 346 | |
| 347 | m_keyChain.sign(*dskCert, m_certName); |
| 348 | m_keyChain.addCertificateAsKeyDefault(*dskCert); |
| 349 | NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert->getName() << ". KeyLocator: " |
| 350 | << dskCert->getSignature().getKeyLocator().getName()); |
| 351 | |
| 352 | Rrset rrset(&m_root); |
| 353 | Name label = dskCert->getName().getPrefix(-2).getSubName(m_root.getName().size() + 1); |
| 354 | rrset.setLabel(label); |
| 355 | rrset.setType(label::CERT_RR_TYPE); |
| 356 | rrset.setVersion(dskCert->getName().get(-1)); |
| 357 | rrset.setTtl(m_root.getTtl()); |
| 358 | rrset.setData(dskCert->wireEncode()); |
| 359 | m_session.insert(rrset); |
| 360 | NDNS_LOG_TRACE("DB: zone " << m_root << " add a ID-CERT RR with name=" |
| 361 | << dskCert->getName() << " rrLabel=" << label); |
| 362 | |
| 363 | Response re; |
| 364 | re.setZone(zone); |
| 365 | re.setQueryType(label::NDNS_ITERATIVE_QUERY); |
| 366 | re.setRrLabel(Name("ndnsim-XYZ")); // insert new records |
| 367 | re.setRrType(label::NS_RR_TYPE); |
| 368 | re.setNdnsType(NDNS_RESP); |
| 369 | |
| 370 | std::string str = "ns1.ndnsim.net"; |
| 371 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 372 | str = "ns2.ndnsim.net"; |
| 373 | re.addRr(dataBlock(ndns::tlv::RrData, str.c_str(), str.size())); |
| 374 | |
| 375 | shared_ptr<Data> data = re.toData(); |
| 376 | m_keyChain.sign(*data, dskCert->getName()); |
| 377 | |
| 378 | Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY); |
| 379 | const Block& block = data->wireEncode(); |
| 380 | Name name; |
| 381 | name.append(block); |
| 382 | |
| 383 | q.setRrLabel(name); |
| 384 | q.setRrType(label::NDNS_UPDATE_LABEL); |
| 385 | |
| 386 | bool hasDataBack = false; |
| 387 | |
| 388 | shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<KEY>(<>+)<ID-CERT><>"); |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 389 | face->onSendData.connectSingleShot([&] (const Data& data) { |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 390 | if (regex->match(data.getName())) { |
| 391 | validatorFace->receive(data); // It's data requested by validator |
| 392 | } |
| 393 | else { |
| 394 | // cert is requested by validator |
| 395 | hasDataBack = true; |
| 396 | NDNS_LOG_TRACE("get Data back"); |
| 397 | BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName()); |
| 398 | Response resp; |
| 399 | |
| 400 | BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data)); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 401 | BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough |
| 402 | BOOST_CHECK_GT(resp.getRrs().size(), 0); |
| 403 | Block block = resp.getRrs()[0]; |
| 404 | block.parse(); |
| 405 | int ret = -1; |
| 406 | BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData); |
| 407 | Block::element_const_iterator val = block.elements_begin(); |
| 408 | BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code |
| 409 | ret = readNonNegativeInteger(*val); |
| 410 | BOOST_CHECK_EQUAL(ret, 0); |
| 411 | } |
Junxiao Shi | 8f5be2a | 2015-01-06 10:06:43 -0700 | [diff] [blame^] | 412 | }); |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 413 | |
| 414 | face->receive(q.toInterest()); |
| 415 | run(); |
| 416 | |
| 417 | BOOST_CHECK_EQUAL(hasDataBack, true); |
| 418 | } |
| 419 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 420 | BOOST_AUTO_TEST_SUITE_END() |
| 421 | |
| 422 | } // namespace tests |
| 423 | } // namespace ndns |
| 424 | } // namespace ndn |