Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 4 | * |
| 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 Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/security/validator-null.hpp" |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 25 | #include "tests/key-chain-fixture.hpp" |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 26 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 27 | namespace ndn::tests { |
| 28 | |
| 29 | using ndn::security::ValidatorNull; |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(Security) |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 32 | BOOST_FIXTURE_TEST_SUITE(TestValidatorNull, KeyChainFixture) |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_CASE(ValidateData) |
| 35 | { |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 36 | auto identity = m_keyChain.createIdentity("/TestValidator/Null"); |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 37 | Data data("/Some/Other/Data/Name"); |
| 38 | m_keyChain.sign(data, signingByIdentity(identity)); |
| 39 | |
| 40 | ValidatorNull validator; |
| 41 | validator.validate(data, |
Davide Pesavento | 2f46d65 | 2023-11-09 23:40:01 -0500 | [diff] [blame] | 42 | [] (auto&&...) { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); }, |
| 43 | [] (auto&&...) { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); }); |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | BOOST_AUTO_TEST_CASE(ValidateInterest) |
| 47 | { |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 48 | auto identity = m_keyChain.createIdentity("/TestValidator/Null"); |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 49 | Interest interest("/Some/Other/Interest/Name"); |
| 50 | m_keyChain.sign(interest, signingByIdentity(identity)); |
| 51 | |
| 52 | ValidatorNull validator; |
| 53 | validator.validate(interest, |
Davide Pesavento | 2f46d65 | 2023-11-09 23:40:01 -0500 | [diff] [blame] | 54 | [] (auto&&...) { BOOST_CHECK_MESSAGE(true, "Validation should succeed"); }, |
| 55 | [] (auto&&...) { BOOST_CHECK_MESSAGE(false, "Validation should not have failed"); }); |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_SUITE_END() // TestValidatorNull |
| 59 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 60 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 61 | } // namespace ndn::tests |