blob: 3ff9fe8ea8745bc85f0bdd2888a05897b0358319 [file] [log] [blame]
Alexander Afanasyev8afba422020-06-11 17:56:21 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento47ce2ee2023-05-09 01:33:33 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Alexander Afanasyev8afba422020-06-11 17:56:21 -04004 *
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 Pesavento4c1ad4c2020-11-16 21:12:02 -050025#include "tests/key-chain-fixture.hpp"
Alexander Afanasyev8afba422020-06-11 17:56:21 -040026
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040027namespace ndn::tests {
Alexander Afanasyev8afba422020-06-11 17:56:21 -040028
Alexander Afanasyev8afba422020-06-11 17:56:21 -040029BOOST_AUTO_TEST_SUITE(Security)
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040030BOOST_FIXTURE_TEST_SUITE(TestValidationPolicy, KeyChainFixture)
Alexander Afanasyev8afba422020-06-11 17:56:21 -040031
32BOOST_AUTO_TEST_CASE(ExtractIdentityNameFromKeyLocator)
33{
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040034 using ndn::security::extractIdentityNameFromKeyLocator;
35
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050036 auto id = m_keyChain.createIdentity("/random/identity");
Alexander Afanasyev8afba422020-06-11 17:56:21 -040037 auto keyName = id.getDefaultKey().getName();
38 auto certName = id.getDefaultKey().getDefaultCertificate().getName();
Davide Pesavento2acce252022-09-08 22:03:03 -040039 auto partialCertName = certName.getPrefix(-1);
Alexander Afanasyev8afba422020-06-11 17:56:21 -040040
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 Pesavento2acce252022-09-08 22:03:03 -040044 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator("/KEY"), "/");
Alexander Afanasyev8afba422020-06-11 17:56:21 -040045
Davide Pesavento2acce252022-09-08 22:03:03 -040046 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 Afanasyev8afba422020-06-11 17:56:21 -040052}
53
54BOOST_AUTO_TEST_SUITE_END() // TestValidationPolicy
55BOOST_AUTO_TEST_SUITE_END() // Security
56
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040057} // namespace ndn::tests