Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Yingdi Yu <yingdi0@cs.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 7 | #include "security/validator-null.hpp" |
| 8 | #include "security/key-chain.hpp" |
| 9 | #include "util/time.hpp" |
| 10 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 11 | #include "boost-test.hpp" |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 12 | |
| 13 | using namespace std; |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | BOOST_AUTO_TEST_SUITE(TestValidator) |
| 18 | |
| 19 | void |
| 20 | onValidated(const shared_ptr<const Data>& data) |
| 21 | { BOOST_CHECK(true); } |
| 22 | |
| 23 | void |
Yingdi Yu | 40587c0 | 2014-02-21 16:40:48 -0800 | [diff] [blame] | 24 | onValidationFailed(const shared_ptr<const Data>& data, const string& failureInfo) |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 25 | { |
| 26 | BOOST_CHECK(false); |
Yingdi Yu | 40587c0 | 2014-02-21 16:40:48 -0800 | [diff] [blame] | 27 | } |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 28 | |
| 29 | BOOST_AUTO_TEST_CASE (Null) |
| 30 | { |
| 31 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 33 | Name identity("/TestValidator/Null"); |
| 34 | identity.appendVersion(); |
| 35 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 36 | BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity)); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 37 | |
| 38 | Name dataName = identity; |
| 39 | dataName.append("1"); |
| 40 | shared_ptr<Data> data = make_shared<Data>(dataName); |
| 41 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 42 | BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame^] | 43 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 44 | ValidatorNull validator; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 45 | |
| 46 | // data must be a shared pointer |
| 47 | validator.validate(*data, |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 48 | bind(&onValidated, _1), |
Yingdi Yu | 40587c0 | 2014-02-21 16:40:48 -0800 | [diff] [blame] | 49 | bind(&onValidationFailed, _1, _2)); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 50 | |
| 51 | keyChain.deleteIdentity(identity); |
| 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_SUITE_END() |
| 55 | |
| 56 | } // namespace ndn |