Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [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 | |
| 22 | #include "ndn-cxx/security/validation-policy.hpp" |
| 23 | |
| 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 | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 26 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 27 | namespace ndn::tests { |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 28 | |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 29 | BOOST_AUTO_TEST_SUITE(Security) |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 30 | BOOST_FIXTURE_TEST_SUITE(TestValidationPolicy, KeyChainFixture) |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 31 | |
| 32 | BOOST_AUTO_TEST_CASE(ExtractIdentityNameFromKeyLocator) |
| 33 | { |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 34 | using ndn::security::extractIdentityNameFromKeyLocator; |
| 35 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 36 | auto id = m_keyChain.createIdentity("/random/identity"); |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 37 | auto keyName = id.getDefaultKey().getName(); |
| 38 | auto certName = id.getDefaultKey().getDefaultCertificate().getName(); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 39 | auto partialCertName = certName.getPrefix(-1); |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 40 | |
| 41 | BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(keyName), "/random/identity"); |
| 42 | BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(certName), "/random/identity"); |
| 43 | BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(partialCertName), "/random/identity"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator("/KEY"), "/"); |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 45 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 46 | BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/short/name")), |
| 47 | KeyLocator::Error); |
| 48 | BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/without/key/component")), |
| 49 | KeyLocator::Error); |
| 50 | BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/with/KEY/but/in/a/wrong/place")), |
| 51 | KeyLocator::Error); |
Alexander Afanasyev | 8afba42 | 2020-06-11 17:56:21 -0400 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_SUITE_END() // TestValidationPolicy |
| 55 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 56 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 57 | } // namespace ndn::tests |