blob: 05dd270f03368b537f610140b62e39033b04195b [file] [log] [blame]
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento152ef442023-04-22 02:02:29 -04003 * Copyright (c) 2013-2023 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
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040027namespace ndn::tests {
28
29using ndn::security::ValidatorNull;
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080030
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080031BOOST_AUTO_TEST_SUITE(Security)
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040032BOOST_FIXTURE_TEST_SUITE(TestValidatorNull, 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,
Davide Pesavento2f46d652023-11-09 23:40:01 -050042 [] (auto&&...) { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); },
43 [] (auto&&...) { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); });
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080044}
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,
Davide Pesavento2f46d652023-11-09 23:40:01 -050054 [] (auto&&...) { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); },
55 [] (auto&&...) { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); });
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080056}
57
58BOOST_AUTO_TEST_SUITE_END() // TestValidatorNull
59BOOST_AUTO_TEST_SUITE_END() // Security
60
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040061} // namespace ndn::tests