blob: 9d04cb8d45d2af7efeaaadfc9ea2e942c5d6fffc [file] [log] [blame]
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -05003 * Copyright (c) 2013-2020 Regents of the University of California.
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * 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.
20 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/security/validator-null.hpp"
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050025#include "tests/key-chain-fixture.hpp"
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080026
27namespace ndn {
28namespace security {
29namespace tests {
30
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080031BOOST_AUTO_TEST_SUITE(Security)
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050032BOOST_FIXTURE_TEST_SUITE(TestValidatorNull, ndn::tests::KeyChainFixture)
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080033
34BOOST_AUTO_TEST_CASE(ValidateData)
35{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050036 auto identity = m_keyChain.createIdentity("/TestValidator/Null");
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080037 Data data("/Some/Other/Data/Name");
38 m_keyChain.sign(data, signingByIdentity(identity));
39
40 ValidatorNull validator;
41 validator.validate(data,
42 bind([] { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); }),
43 bind([] { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); }));
44}
45
46BOOST_AUTO_TEST_CASE(ValidateInterest)
47{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050048 auto identity = m_keyChain.createIdentity("/TestValidator/Null");
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080049 Interest interest("/Some/Other/Interest/Name");
50 m_keyChain.sign(interest, signingByIdentity(identity));
51
52 ValidatorNull validator;
53 validator.validate(interest,
54 bind([] { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); }),
55 bind([] { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); }));
56}
57
58BOOST_AUTO_TEST_SUITE_END() // TestValidatorNull
59BOOST_AUTO_TEST_SUITE_END() // Security
60
61} // namespace tests
62} // namespace security
63} // namespace ndn