blob: 6e9ce4c36cea935da138a2c2849f9642b829ee2c [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
Yingdi Yu9a335352014-01-31 11:57:46 -08007#include "security/validator-null.hpp"
8#include "security/key-chain.hpp"
9#include "util/time.hpp"
10
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070011#include "boost-test.hpp"
Yingdi Yu9a335352014-01-31 11:57:46 -080012
13using namespace std;
14
15namespace ndn {
16
17BOOST_AUTO_TEST_SUITE(TestValidator)
18
19void
20onValidated(const shared_ptr<const Data>& data)
21{ BOOST_CHECK(true); }
22
23void
Yingdi Yu40587c02014-02-21 16:40:48 -080024onValidationFailed(const shared_ptr<const Data>& data, const string& failureInfo)
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025{
26 BOOST_CHECK(false);
Yingdi Yu40587c02014-02-21 16:40:48 -080027}
Yingdi Yu9a335352014-01-31 11:57:46 -080028
29BOOST_AUTO_TEST_CASE (Null)
30{
31 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
Yingdi Yube4150e2014-02-18 13:02:46 -080032
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070033 Name identity("/TestValidator/Null");
34 identity.appendVersion();
35
Yingdi Yu2e57a582014-02-20 23:34:43 -080036 BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080037
38 Name dataName = identity;
39 dataName.append("1");
40 shared_ptr<Data> data = make_shared<Data>(dataName);
41
Yingdi Yu2e57a582014-02-20 23:34:43 -080042 BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070043
Yingdi Yu9a335352014-01-31 11:57:46 -080044 ValidatorNull validator;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080045
46 // data must be a shared pointer
47 validator.validate(*data,
Yingdi Yu9a335352014-01-31 11:57:46 -080048 bind(&onValidated, _1),
Yingdi Yu40587c02014-02-21 16:40:48 -080049 bind(&onValidationFailed, _1, _2));
Yingdi Yu9a335352014-01-31 11:57:46 -080050
51 keyChain.deleteIdentity(identity);
52}
53
54BOOST_AUTO_TEST_SUITE_END()
55
56} // namespace ndn