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 | |
| 7 | #include <boost/test/unit_test.hpp> |
| 8 | |
| 9 | #include "security/validator-null.hpp" |
| 10 | #include "security/key-chain.hpp" |
| 11 | #include "util/time.hpp" |
| 12 | |
| 13 | |
| 14 | using namespace std; |
| 15 | |
| 16 | namespace ndn { |
| 17 | |
| 18 | BOOST_AUTO_TEST_SUITE(TestValidator) |
| 19 | |
| 20 | void |
| 21 | onValidated(const shared_ptr<const Data>& data) |
| 22 | { BOOST_CHECK(true); } |
| 23 | |
| 24 | void |
Yingdi Yu | 40587c0 | 2014-02-21 16:40:48 -0800 | [diff] [blame^] | 25 | onValidationFailed(const shared_ptr<const Data>& data, const string& failureInfo) |
| 26 | { |
| 27 | BOOST_CHECK(false); |
| 28 | } |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 29 | |
| 30 | BOOST_AUTO_TEST_CASE (Null) |
| 31 | { |
| 32 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 33 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 34 | Name identity("/TestValidator/Null/" + boost::lexical_cast<std::string>(time::now())); |
| 35 | BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity)); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 36 | |
| 37 | Name dataName = identity; |
| 38 | dataName.append("1"); |
| 39 | shared_ptr<Data> data = make_shared<Data>(dataName); |
| 40 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 41 | BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity)); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 42 | |
| 43 | ValidatorNull validator; |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 44 | |
| 45 | // data must be a shared pointer |
| 46 | validator.validate(*data, |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 47 | bind(&onValidated, _1), |
Yingdi Yu | 40587c0 | 2014-02-21 16:40:48 -0800 | [diff] [blame^] | 48 | bind(&onValidationFailed, _1, _2)); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 49 | |
| 50 | keyChain.deleteIdentity(identity); |
| 51 | } |
| 52 | |
| 53 | BOOST_AUTO_TEST_SUITE_END() |
| 54 | |
| 55 | } // namespace ndn |