blob: c909c0607e83d85deb4048ecfdaa781d19d9a19a [file] [log] [blame]
Yingdi Yu9a335352014-01-31 11:57:46 -08001/**
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
14using namespace std;
15
16namespace ndn {
17
18BOOST_AUTO_TEST_SUITE(TestValidator)
19
20void
21onValidated(const shared_ptr<const Data>& data)
22{ BOOST_CHECK(true); }
23
24void
Yingdi Yu40587c02014-02-21 16:40:48 -080025onValidationFailed(const shared_ptr<const Data>& data, const string& failureInfo)
26{
27 BOOST_CHECK(false);
28}
Yingdi Yu9a335352014-01-31 11:57:46 -080029
30BOOST_AUTO_TEST_CASE (Null)
31{
32 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
Yingdi Yube4150e2014-02-18 13:02:46 -080033
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070034 Name identity("/TestValidator/Null");
35 identity.appendVersion();
36
Yingdi Yu2e57a582014-02-20 23:34:43 -080037 BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080038
39 Name dataName = identity;
40 dataName.append("1");
41 shared_ptr<Data> data = make_shared<Data>(dataName);
42
Yingdi Yu2e57a582014-02-20 23:34:43 -080043 BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080044
45 ValidatorNull validator;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080046
47 // data must be a shared pointer
48 validator.validate(*data,
Yingdi Yu9a335352014-01-31 11:57:46 -080049 bind(&onValidated, _1),
Yingdi Yu40587c02014-02-21 16:40:48 -080050 bind(&onValidationFailed, _1, _2));
Yingdi Yu9a335352014-01-31 11:57:46 -080051
52 keyChain.deleteIdentity(identity);
53}
54
55BOOST_AUTO_TEST_SUITE_END()
56
57} // namespace ndn