blob: 40e667d863cd0fb1e1b4f51b68cb5f46d25185c8 [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)
36{ BOOST_CHECK(true); }
37
38void
Yingdi Yu40587c02014-02-21 16:40:48 -080039onValidationFailed(const shared_ptr<const Data>& data, const string& failureInfo)
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070040{
41 BOOST_CHECK(false);
Yingdi Yu40587c02014-02-21 16:40:48 -080042}
Yingdi Yu9a335352014-01-31 11:57:46 -080043
Yingdi Yuf56c68f2014-04-24 21:50:13 -070044BOOST_AUTO_TEST_CASE(Null)
Yingdi Yu9a335352014-01-31 11:57:46 -080045{
Yingdi Yuf56c68f2014-04-24 21:50:13 -070046 BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
47 KeyChain keyChain("sqlite3", "file");
Yingdi Yube4150e2014-02-18 13:02:46 -080048
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070049 Name identity("/TestValidator/Null");
50 identity.appendVersion();
51
Yingdi Yu2e57a582014-02-20 23:34:43 -080052 BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080053
54 Name dataName = identity;
55 dataName.append("1");
56 shared_ptr<Data> data = make_shared<Data>(dataName);
57
Yingdi Yu2e57a582014-02-20 23:34:43 -080058 BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070059
Yingdi Yu9a335352014-01-31 11:57:46 -080060 ValidatorNull validator;
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080061
62 // data must be a shared pointer
63 validator.validate(*data,
Yingdi Yu96e64062014-04-15 19:57:33 -070064 bind(&onValidated, _1),
65 bind(&onValidationFailed, _1, _2));
Yingdi Yu9a335352014-01-31 11:57:46 -080066
67 keyChain.deleteIdentity(identity);
68}
69
70BOOST_AUTO_TEST_SUITE_END()
71
72} // namespace ndn