blob: 41cde4dbbad9a8efd68dafe9749489e6c0d315fc [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"
25#include "tests/identity-management-fixture.hpp"
26
27namespace ndn {
28namespace security {
29inline namespace v2 {
30namespace tests {
31
32using namespace ndn::tests;
33
34BOOST_AUTO_TEST_SUITE(Security)
35BOOST_FIXTURE_TEST_SUITE(TestValidationPolicy, IdentityManagementFixture)
36
37BOOST_AUTO_TEST_CASE(ExtractIdentityNameFromKeyLocator)
38{
39 auto id = addIdentity("/random/identity");
40
41 auto keyName = id.getDefaultKey().getName();
42 auto certName = id.getDefaultKey().getDefaultCertificate().getName();
43 auto partialCertName = id.getDefaultKey().getDefaultCertificate().getName().getPrefix(-1);
44
45 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(keyName), "/random/identity");
46 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(certName), "/random/identity");
47 BOOST_CHECK_EQUAL(extractIdentityNameFromKeyLocator(partialCertName), "/random/identity");
48
49 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/without/key/component")), std::runtime_error);
50 BOOST_CHECK_THROW(extractIdentityNameFromKeyLocator(Name("/name/with/KEY/but/in/a/wrong/place")), std::runtime_error);
51}
52
53BOOST_AUTO_TEST_SUITE_END() // TestValidationPolicy
54BOOST_AUTO_TEST_SUITE_END() // Security
55
56} // namespace tests
57} // inline namespace v2
58} // namespace security
59} // namespace ndn