blob: 8fc5a5edbe83d0dd6588c6f0c562a72c7f188fed [file] [log] [blame]
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento2e481fc2021-07-02 18:20:03 -04003 * Copyright (c) 2013-2021 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
Davide Pesavento2e481fc2021-07-02 18:20:03 -040031using std::bind;
32
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080033BOOST_AUTO_TEST_SUITE(Security)
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050034BOOST_FIXTURE_TEST_SUITE(TestValidatorNull, ndn::tests::KeyChainFixture)
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080035
36BOOST_AUTO_TEST_CASE(ValidateData)
37{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050038 auto identity = m_keyChain.createIdentity("/TestValidator/Null");
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080039 Data data("/Some/Other/Data/Name");
40 m_keyChain.sign(data, signingByIdentity(identity));
41
42 ValidatorNull validator;
43 validator.validate(data,
44 bind([] { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); }),
45 bind([] { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); }));
46}
47
48BOOST_AUTO_TEST_CASE(ValidateInterest)
49{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050050 auto identity = m_keyChain.createIdentity("/TestValidator/Null");
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080051 Interest interest("/Some/Other/Interest/Name");
52 m_keyChain.sign(interest, signingByIdentity(identity));
53
54 ValidatorNull validator;
55 validator.validate(interest,
56 bind([] { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); }),
57 bind([] { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); }));
58}
59
60BOOST_AUTO_TEST_SUITE_END() // TestValidatorNull
61BOOST_AUTO_TEST_SUITE_END() // Security
62
63} // namespace tests
64} // namespace security
65} // namespace ndn