blob: e982f726fd82c3835afc525eec2e345c6f2af79a [file] [log] [blame]
Alexander Afanasyev8afba422020-06-11 17:56:21 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2020 Regents of the University of California.
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 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
39 auto keyName = id.getDefaultKey().getName();
40 auto certName = id.getDefaultKey().getDefaultCertificate().getName();
41 auto partialCertName = id.getDefaultKey().getDefaultCertificate().getName().getPrefix(-1);
42
43 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(keyName), "/random/identity");
44 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(certName), "/random/identity");
45 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(partialCertName), "/random/identity");
46
47 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/without/key/component")), std::runtime_error);
48 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/with/KEY/but/in/a/wrong/place")), std::runtime_error);
49}
50
51BOOST_AUTO_TEST_SUITE_END() // TestValidationPolicy
52BOOST_AUTO_TEST_SUITE_END() // Security
53
54} // namespace tests
55} // inline namespace v2
56} // namespace security
57} // namespace ndn