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 | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2021 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 | |
| 27 | namespace ndn { |
| 28 | namespace security { |
| 29 | namespace tests { |
| 30 | |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 31 | using std::bind; |
| 32 | |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(Security) |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 34 | BOOST_FIXTURE_TEST_SUITE(TestValidatorNull, ndn::tests::KeyChainFixture) |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 35 | |
| 36 | BOOST_AUTO_TEST_CASE(ValidateData) |
| 37 | { |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 38 | auto identity = m_keyChain.createIdentity("/TestValidator/Null"); |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 39 | 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 | |
| 48 | BOOST_AUTO_TEST_CASE(ValidateInterest) |
| 49 | { |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 50 | auto identity = m_keyChain.createIdentity("/TestValidator/Null"); |
Alexander Afanasyev | 6dfeffe | 2017-01-30 22:40:32 -0800 | [diff] [blame] | 51 | 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 | |
| 60 | BOOST_AUTO_TEST_SUITE_END() // TestValidatorNull |
| 61 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 62 | |
| 63 | } // namespace tests |
| 64 | } // namespace security |
| 65 | } // namespace ndn |