blob: 3d76f623ba05e2fa8217348dbdacab7a0631c41e [file] [log] [blame]
Alexander Afanasyev8afba422020-06-11 17:56:21 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento2acce252022-09-08 22:03:03 -04003 * Copyright (c) 2013-2022 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
27namespace ndn {
28namespace security {
29inline namespace v2 {
30namespace tests {
31
Alexander Afanasyev8afba422020-06-11 17:56:21 -040032BOOST_AUTO_TEST_SUITE(Security)
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050033BOOST_FIXTURE_TEST_SUITE(TestValidationPolicy, ndn::tests::KeyChainFixture)
Alexander Afanasyev8afba422020-06-11 17:56:21 -040034
35BOOST_AUTO_TEST_CASE(ExtractIdentityNameFromKeyLocator)
36{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050037 auto id = m_keyChain.createIdentity("/random/identity");
Alexander Afanasyev8afba422020-06-11 17:56:21 -040038 auto keyName = id.getDefaultKey().getName();
39 auto certName = id.getDefaultKey().getDefaultCertificate().getName();
Davide Pesavento2acce252022-09-08 22:03:03 -040040 auto partialCertName = certName.getPrefix(-1);
Alexander Afanasyev8afba422020-06-11 17:56:21 -040041
42 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(keyName), "/random/identity");
43 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(certName), "/random/identity");
44 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(partialCertName), "/random/identity");
Davide Pesavento2acce252022-09-08 22:03:03 -040045 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator("/KEY"), "/");
Alexander Afanasyev8afba422020-06-11 17:56:21 -040046
Davide Pesavento2acce252022-09-08 22:03:03 -040047 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/short/name")),
48 KeyLocator::Error);
49 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/without/key/component")),
50 KeyLocator::Error);
51 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/with/KEY/but/in/a/wrong/place")),
52 KeyLocator::Error);
Alexander Afanasyev8afba422020-06-11 17:56:21 -040053}
54
55BOOST_AUTO_TEST_SUITE_END() // TestValidationPolicy
56BOOST_AUTO_TEST_SUITE_END() // Security
57
58} // namespace tests
59} // inline namespace v2
60} // namespace security
61} // namespace ndn