Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 4 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 7 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 8 | * ndn-tools 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. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 11 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 12 | * ndn-tools 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. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 15 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 18 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 19 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "tools/pib/cert-publisher.hpp" |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 23 | |
| 24 | #include "tests/identity-management-fixture.hpp" |
| 25 | |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 26 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 27 | #include <boost/filesystem.hpp> |
| 28 | |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 29 | namespace ndn { |
| 30 | namespace pib { |
| 31 | namespace tests { |
| 32 | |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 33 | class CertPublisherFixture : public ndn::tests::IdentityManagementTimeFixture |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 34 | { |
| 35 | public: |
| 36 | CertPublisherFixture() |
| 37 | : tmpPath(boost::filesystem::path(TMP_TESTS_PATH) / "DbTest") |
| 38 | , db(tmpPath.c_str()) |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 39 | , face(io, m_keyChain, {true, true}) |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | ~CertPublisherFixture() |
| 44 | { |
| 45 | boost::filesystem::remove_all(tmpPath); |
| 46 | } |
| 47 | |
| 48 | boost::asio::io_service io; |
| 49 | boost::filesystem::path tmpPath; |
| 50 | PibDb db; |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 51 | util::DummyClientFace face; |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 54 | BOOST_AUTO_TEST_SUITE(Pib) |
| 55 | BOOST_FIXTURE_TEST_SUITE(TestCertPublisher, CertPublisherFixture) |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 56 | |
| 57 | BOOST_AUTO_TEST_CASE(Basic) |
| 58 | { |
| 59 | // Initialize id1 |
| 60 | Name id1("/test/identity"); |
| 61 | addIdentity(id1); |
| 62 | Name certName111 = m_keyChain.getDefaultCertificateNameForIdentity(id1); |
| 63 | shared_ptr<IdentityCertificate> cert111 = m_keyChain.getCertificate(certName111); |
| 64 | Name keyName11 = cert111->getPublicKeyName(); |
| 65 | |
| 66 | advanceClocks(io, time::milliseconds(100)); |
| 67 | shared_ptr<IdentityCertificate> cert112 = m_keyChain.selfSign(keyName11); |
| 68 | Name certName112 = cert112->getName(); |
| 69 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 70 | CertPublisher certPublisher(face, db); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 71 | |
| 72 | // Add a certificate |
| 73 | db.addCertificate(*cert111); |
| 74 | advanceClocks(io, time::milliseconds(2), 50); |
| 75 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 76 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 0); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 77 | auto interest111 = make_shared<Interest>(cert111->getName().getPrefix(-1)); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 78 | face.receive(*interest111); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 79 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 80 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
| 81 | BOOST_CHECK(face.sentData[0].wireEncode() == cert111->wireEncode()); |
| 82 | face.sentData.clear(); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 83 | |
| 84 | // Add another certificate |
| 85 | db.addCertificate(*cert112); |
| 86 | advanceClocks(io, time::milliseconds(2), 50); |
| 87 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 88 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 0); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 89 | auto interest112 = make_shared<Interest>(cert112->getName().getPrefix(-1)); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 90 | face.receive(*interest112); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 91 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 92 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
| 93 | BOOST_CHECK(face.sentData[0].wireEncode() == cert111->wireEncode()); |
| 94 | face.sentData.clear(); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 95 | |
| 96 | Exclude exclude; |
| 97 | exclude.excludeOne(cert111->getName().get(-1)); |
| 98 | interest112->setExclude(exclude); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 99 | face.receive(*interest112); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 100 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 101 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
| 102 | BOOST_CHECK(face.sentData[0].wireEncode() == cert112->wireEncode()); |
| 103 | face.sentData.clear(); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 104 | |
| 105 | // delete a certificate |
| 106 | db.deleteCertificate(certName112); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 107 | face.receive(*interest112); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 108 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 109 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 0); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 111 | face.receive(*interest111); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 112 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 113 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
| 114 | BOOST_CHECK(face.sentData[0].wireEncode() == cert111->wireEncode()); |
| 115 | face.sentData.clear(); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 116 | |
| 117 | // delete another certificate |
| 118 | db.deleteCertificate(certName111); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 119 | face.receive(*interest112); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 120 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 121 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 0); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 122 | |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 123 | face.receive(*interest111); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 124 | advanceClocks(io, time::milliseconds(2), 50); |
Junxiao Shi | aa1b3c9 | 2016-07-14 14:56:53 +0000 | [diff] [blame] | 125 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 0); |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Davide Pesavento | 013de9b | 2016-09-01 12:06:56 +0000 | [diff] [blame] | 128 | BOOST_AUTO_TEST_SUITE_END() // TestPibPublisher |
| 129 | BOOST_AUTO_TEST_SUITE_END() // Pib |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 130 | |
| 131 | } // namespace tests |
| 132 | } // namespace pib |
| 133 | } // namespace ndn |