blob: b8d615711caba7eb7bc652e73ab17f0ad9be24a1 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yu9a335352014-01-31 11:57:46 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Yingdi Yu9a335352014-01-31 11:57:46 -080020 */
21
Yingdi Yu9a335352014-01-31 11:57:46 -080022#include "security/validator-null.hpp"
23#include "security/key-chain.hpp"
24#include "util/time.hpp"
25
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070026#include "boost-test.hpp"
Yingdi Yu9a335352014-01-31 11:57:46 -080027
28using namespace std;
29
30namespace ndn {
31
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070032BOOST_AUTO_TEST_SUITE(SecurityTestValidator)
Yingdi Yu9a335352014-01-31 11:57:46 -080033
34void
35onValidated(const shared_ptr<const Data>& data)
Alexander Afanasyev24b75c82014-05-31 15:59:31 +030036{
37 BOOST_CHECK(true);
38}
Yingdi Yu9a335352014-01-31 11:57:46 -080039
40void
Yingdi Yu40587c02014-02-21 16:40:48 -080041onValidationFailed(const shared_ptr<const Data>& data, const string& failureInfo)
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070042{
43 BOOST_CHECK(false);
Yingdi Yu40587c02014-02-21 16:40:48 -080044}
Yingdi Yu9a335352014-01-31 11:57:46 -080045
Yingdi Yuf56c68f2014-04-24 21:50:13 -070046BOOST_AUTO_TEST_CASE(Null)
Yingdi Yu9a335352014-01-31 11:57:46 -080047{
Yingdi Yuf56c68f2014-04-24 21:50:13 -070048 BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
49 KeyChain keyChain("sqlite3", "file");
Yingdi Yube4150e2014-02-18 13:02:46 -080050
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070051 Name identity("/TestValidator/Null");
52 identity.appendVersion();
53
Yingdi Yu2e57a582014-02-20 23:34:43 -080054 BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080055
56 Name dataName = identity;
57 dataName.append("1");
58 shared_ptr<Data> data = make_shared<Data>(dataName);
59
Yingdi Yu2e57a582014-02-20 23:34:43 -080060 BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070061
Yingdi Yu9a335352014-01-31 11:57:46 -080062 ValidatorNull validator;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080063
64 // data must be a shared pointer
65 validator.validate(*data,
Yingdi Yu96e64062014-04-15 19:57:33 -070066 bind(&onValidated, _1),
67 bind(&onValidationFailed, _1, _2));
Yingdi Yu9a335352014-01-31 11:57:46 -080068
69 keyChain.deleteIdentity(identity);
70}
71
72BOOST_AUTO_TEST_SUITE_END()
73
74} // namespace ndn