Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | */ |
| 5 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | #include "sync-validator.h" |
| 8 | |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame^] | 9 | #include <boost/lexical_cast.hpp> |
| 10 | #include <boost/asio.hpp> |
| 11 | #include <ndn-cxx/util/scheduler.hpp> |
| 12 | |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 13 | BOOST_AUTO_TEST_SUITE(TestSyncValidator) |
| 14 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 15 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 16 | onValidated(const ndn::shared_ptr<const ndn::Data>& data) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 17 | { |
| 18 | BOOST_CHECK(true); |
| 19 | } |
| 20 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 21 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 22 | onValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, |
| 23 | const std::string& failureInfo) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 24 | { |
| 25 | BOOST_CHECK(false); |
| 26 | } |
| 27 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 28 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 29 | onValidated2(const ndn::shared_ptr<const ndn::Data>& data) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 30 | { |
| 31 | BOOST_CHECK(false); |
| 32 | } |
| 33 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 34 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 35 | onValidationFailed2(const ndn::shared_ptr<const ndn::Data>& data, |
| 36 | const std::string& failureInfo) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 37 | { |
| 38 | BOOST_CHECK(true); |
| 39 | } |
| 40 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 41 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 42 | publishData(const uint8_t* buf, size_t len, int freshness) |
| 43 | { |
| 44 | } |
| 45 | |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 46 | BOOST_AUTO_TEST_CASE (Graph) |
| 47 | { |
| 48 | using namespace Sync; |
| 49 | using namespace ndn; |
| 50 | |
| 51 | Name prefix("/Sync/TestSyncValidator/AddEdge"); |
| 52 | KeyChain keychain; |
| 53 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 54 | Name identity1("/TestSyncValidator/AddEdge-1/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 55 | Name certName1 = keychain.createIdentity(identity1); |
| 56 | shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1); |
| 57 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 58 | Name identity2("/TestSyncValidator/AddEdge-2/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 59 | Name certName2 = keychain.createIdentity(identity2); |
| 60 | shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2); |
| 61 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 62 | Name identity3("/TestSyncValidator/AddEdge-3/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 63 | Name certName3 = keychain.createIdentity(identity3); |
| 64 | shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3); |
| 65 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 66 | Name identity4("/TestSyncValidator/AddEdge-4/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 67 | Name certName4 = keychain.createIdentity(identity4); |
| 68 | shared_ptr<IdentityCertificate> introducer2 = keychain.getCertificate(certName4); |
| 69 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 70 | Name identity5("/TestSyncValidator/AddEdge-5/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 71 | Name certName5 = keychain.createIdentity(identity5); |
| 72 | shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName5); |
| 73 | |
| 74 | shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>(); |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame^] | 75 | shared_ptr<Face> face = make_shared<Face>(ref(*ioService)); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 76 | shared_ptr<SecRuleRelative> rule; |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 77 | SyncValidator validator(prefix, *anchor, *face, |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 78 | bind(&publishData, _1, _2, _3), |
| 79 | rule); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 80 | |
| 81 | validator.addParticipant(*introducer); |
| 82 | BOOST_CHECK(validator.canTrust(certName2)); |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 84 | IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1)); |
| 85 | keychain.sign(introCert, certName2); |
| 86 | validator.addParticipant(introCert); |
| 87 | BOOST_CHECK(validator.canTrust(certName3)); |
| 88 | |
| 89 | IntroCertificate introCert1(prefix, *anchor, certName3.getPrefix(-1)); |
| 90 | keychain.sign(introCert1, certName3); |
| 91 | validator.addParticipant(introCert1); |
| 92 | validator.setAnchor(*introducer); |
| 93 | BOOST_CHECK(validator.canTrust(certName2)); |
| 94 | BOOST_CHECK(validator.canTrust(certName3)); |
| 95 | BOOST_CHECK(validator.canTrust(certName1)); |
| 96 | |
| 97 | IntroCertificate introCert2(prefix, *introducee2, certName4.getPrefix(-1)); |
| 98 | keychain.sign(introCert2, certName4); |
| 99 | validator.addParticipant(introCert2); |
| 100 | BOOST_CHECK(validator.canTrust(certName5) == false); |
| 101 | BOOST_CHECK(validator.canTrust(certName4) == false); |
| 102 | |
| 103 | IntroCertificate introCert3(prefix, *introducee, certName5.getPrefix(-1)); |
| 104 | keychain.sign(introCert3, certName5); |
| 105 | validator.addParticipant(introCert3); |
| 106 | BOOST_CHECK(validator.canTrust(certName5) == false); |
| 107 | BOOST_CHECK(validator.canTrust(certName4) == false); |
| 108 | |
| 109 | validator.setAnchor(*introducee2); |
| 110 | BOOST_CHECK(validator.canTrust(certName1)); |
| 111 | BOOST_CHECK(validator.canTrust(certName2)); |
| 112 | BOOST_CHECK(validator.canTrust(certName3)); |
| 113 | BOOST_CHECK(validator.canTrust(certName4) == false); |
| 114 | BOOST_CHECK(validator.canTrust(certName5)); |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 115 | |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 116 | |
| 117 | keychain.deleteIdentity(identity1); |
| 118 | keychain.deleteIdentity(identity2); |
| 119 | keychain.deleteIdentity(identity3); |
| 120 | keychain.deleteIdentity(identity4); |
| 121 | keychain.deleteIdentity(identity5); |
| 122 | } |
| 123 | |
| 124 | BOOST_AUTO_TEST_CASE (OfflineValidate) |
| 125 | { |
| 126 | using namespace Sync; |
| 127 | using namespace ndn; |
| 128 | |
| 129 | Name prefix("/Sync/TestSyncValidator/OfflineValidate"); |
| 130 | KeyChain keychain; |
| 131 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 132 | Name identity1("/TestSyncValidator/OfflineValidate-1/" |
| 133 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 134 | Name certName1 = keychain.createIdentity(identity1); |
| 135 | shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1); |
| 136 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 137 | Name identity2("/TestSyncValidator/OfflineValidate-2/" |
| 138 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 139 | Name certName2 = keychain.createIdentity(identity2); |
| 140 | shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2); |
| 141 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 142 | Name identity3("/TestSyncValidator/OfflineValidate-3/" |
| 143 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 144 | Name certName3 = keychain.createIdentity(identity3); |
| 145 | shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3); |
| 146 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 147 | Name identity4("/TestSyncValidator/OfflineValidate-4/" |
| 148 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 149 | Name certName4 = keychain.createIdentity(identity4); |
| 150 | shared_ptr<IdentityCertificate> introducer2 = keychain.getCertificate(certName4); |
| 151 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 152 | Name identity5("/TestSyncValidator/OfflineValidate-5/" |
| 153 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 154 | Name certName5 = keychain.createIdentity(identity5); |
| 155 | shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName5); |
| 156 | |
| 157 | shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>(); |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame^] | 158 | shared_ptr<Face> face = make_shared<Face>(ref(*ioService)); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 159 | shared_ptr<SecRuleRelative> rule; |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 160 | SyncValidator validator(prefix, *anchor, *face, |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 161 | bind(&publishData, _1, _2, _3), |
| 162 | rule); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 163 | |
| 164 | validator.addParticipant(*introducer); |
| 165 | BOOST_CHECK(validator.canTrust(certName2)); |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 166 | |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 167 | IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1)); |
| 168 | keychain.sign(introCert, certName2); |
| 169 | validator.addParticipant(introCert); |
| 170 | BOOST_CHECK(validator.canTrust(certName3)); |
| 171 | |
| 172 | IntroCertificate introCert2(prefix, *introducee2, certName4.getPrefix(-1)); |
| 173 | keychain.sign(introCert2, certName4); |
| 174 | validator.addParticipant(introCert2); |
| 175 | BOOST_CHECK(validator.canTrust(certName5) == false); |
| 176 | BOOST_CHECK(validator.canTrust(certName4) == false); |
| 177 | |
| 178 | validator.setAnchor(*introducer2); |
| 179 | BOOST_CHECK(validator.canTrust(certName1) == false); |
| 180 | BOOST_CHECK(validator.canTrust(certName2) == false); |
| 181 | BOOST_CHECK(validator.canTrust(certName3) == false); |
| 182 | BOOST_CHECK(validator.canTrust(certName4)); |
| 183 | BOOST_CHECK(validator.canTrust(certName5)); |
| 184 | |
| 185 | Name dataName1 = prefix; |
| 186 | dataName1.append("data-1"); |
| 187 | shared_ptr<Data> data1 = make_shared<Data>(dataName1); |
| 188 | keychain.sign(*data1, certName5); |
| 189 | |
| 190 | validator.validate(*data1, |
| 191 | bind(&onValidated, _1), |
| 192 | bind(&onValidationFailed, _1, _2)); |
| 193 | |
| 194 | Name dataName2 = prefix; |
| 195 | dataName2.append("data-2"); |
| 196 | shared_ptr<Data> data2 = make_shared<Data>(dataName2); |
| 197 | keychain.sign(*data2, certName1); |
| 198 | |
| 199 | validator.validate(*data2, |
| 200 | bind(&onValidated2, _1), |
| 201 | bind(&onValidationFailed2, _1, _2)); |
| 202 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 203 | // ioService->run(); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 204 | |
| 205 | keychain.deleteIdentity(identity1); |
| 206 | keychain.deleteIdentity(identity2); |
| 207 | keychain.deleteIdentity(identity3); |
| 208 | keychain.deleteIdentity(identity4); |
| 209 | keychain.deleteIdentity(identity5); |
| 210 | } |
| 211 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 212 | struct FacesFixture |
| 213 | { |
| 214 | FacesFixture() |
| 215 | : regPrefixId(0) |
| 216 | , regPrefixId2(0) |
| 217 | {} |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 218 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 219 | void |
| 220 | onInterest(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data) |
| 221 | { |
| 222 | face->put(*data); |
| 223 | face->unsetInterestFilter(regPrefixId); |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | onInterest2(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data) |
| 228 | { |
| 229 | face->put(*data); |
| 230 | face->unsetInterestFilter(regPrefixId2); |
| 231 | } |
| 232 | |
| 233 | void |
| 234 | onRegFailed() |
| 235 | {} |
| 236 | |
| 237 | void |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 238 | validate(ndn::shared_ptr<Sync::SyncValidator> validator, ndn::shared_ptr<ndn::Data> data, |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 239 | const ndn::Name& certName3, const ndn::Name& certName4) |
| 240 | { |
| 241 | validator->validate(*data, |
| 242 | bind(&onValidated, _1), |
| 243 | bind(&onValidationFailed, _1, _2)); |
| 244 | |
| 245 | |
| 246 | BOOST_CHECK(validator->canTrust(certName3)); |
| 247 | BOOST_CHECK(validator->canTrust(certName4)); |
| 248 | } |
| 249 | |
| 250 | void |
| 251 | terminate(ndn::shared_ptr<ndn::Face> face) |
| 252 | { |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame^] | 253 | face->getIoService().stop(); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | const ndn::RegisteredPrefixId* regPrefixId; |
| 257 | const ndn::RegisteredPrefixId* regPrefixId2; |
| 258 | }; |
| 259 | |
| 260 | BOOST_FIXTURE_TEST_CASE(OnlineValidate, FacesFixture) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 261 | { |
| 262 | using namespace Sync; |
| 263 | using namespace ndn; |
| 264 | |
| 265 | Name prefix("/Sync/TestSyncValidator/OnlineValidate"); |
| 266 | KeyChain keychain; |
| 267 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 268 | Name identity1("/TestSyncValidator/OnlineValidate-1/" |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 269 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 270 | Name certName1 = keychain.createIdentity(identity1); |
| 271 | shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1); |
| 272 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 273 | Name identity2("/TestSyncValidator/OnlineValidate-2/" |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 274 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 275 | Name certName2 = keychain.createIdentity(identity2); |
| 276 | shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2); |
| 277 | |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 278 | Name identity3("/TestSyncValidator/OnlineValidate-3/" |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 279 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 280 | Name certName3 = keychain.createIdentity(identity3); |
| 281 | shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3); |
| 282 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 283 | Name identity4("/TestSyncValidator/OnlineValidate-4/" |
| 284 | + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 285 | Name certName4 = keychain.createIdentity(identity4); |
| 286 | shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName4); |
| 287 | |
| 288 | shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>(); |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame^] | 289 | shared_ptr<Face> face = make_shared<Face>(ref(*ioService)); |
| 290 | shared_ptr<Face> face2 = make_shared<Face>(ref(*ioService)); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 291 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 292 | shared_ptr<SecRuleRelative> rule; |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 293 | shared_ptr<SyncValidator> validator = shared_ptr<SyncValidator> |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 294 | (new SyncValidator(prefix, *anchor, *face2, bind(&publishData, _1, _2, _3), rule)); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 295 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 296 | validator->addParticipant(*introducer); |
| 297 | BOOST_CHECK(validator->canTrust(certName2)); |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 298 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 299 | shared_ptr<IntroCertificate> introCert = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee, certName2.getPrefix(-1))); |
| 300 | keychain.sign(*introCert, certName2); |
| 301 | BOOST_CHECK(validator->canTrust(certName3) == false); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 302 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 303 | shared_ptr<IntroCertificate> introCert2 = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee2, certName3.getPrefix(-1))); |
| 304 | keychain.sign(*introCert2, certName3); |
| 305 | BOOST_CHECK(validator->canTrust(certName4) == false); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 306 | |
| 307 | Name dataName1 = prefix; |
| 308 | dataName1.append("data-1"); |
| 309 | shared_ptr<Data> data1 = make_shared<Data>(dataName1); |
| 310 | keychain.sign(*data1, certName4); |
| 311 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 312 | ndn::Scheduler scheduler(*ioService); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 313 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 314 | scheduler.scheduleEvent(time::seconds(1), |
| 315 | bind(&FacesFixture::terminate, this, face)); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 316 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 317 | regPrefixId = face->setInterestFilter(introCert->getName().getPrefix(-1), |
| 318 | bind(&FacesFixture::onInterest, this, face, introCert), |
| 319 | bind(&FacesFixture::onRegFailed, this)); |
Yingdi Yu | a873d64 | 2014-04-15 21:31:33 -0700 | [diff] [blame] | 320 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 321 | regPrefixId2 = face->setInterestFilter(introCert2->getName().getPrefix(-1), |
| 322 | bind(&FacesFixture::onInterest2, this, face, introCert2), |
| 323 | bind(&FacesFixture::onRegFailed, this)); |
| 324 | |
| 325 | scheduler.scheduleEvent(time::milliseconds(200), |
| 326 | bind(&FacesFixture::validate, this, |
| 327 | validator, data1, certName3, certName4)); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 328 | |
| 329 | keychain.deleteIdentity(identity1); |
| 330 | keychain.deleteIdentity(identity2); |
| 331 | keychain.deleteIdentity(identity3); |
| 332 | keychain.deleteIdentity(identity4); |
| 333 | } |
| 334 | |
| 335 | BOOST_AUTO_TEST_SUITE_END() |