blob: 3297cd4220c650161d7f7a26095be279ab303de8 [file] [log] [blame]
Alexander Afanasyev2b4e8852018-06-13 20:32:27 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoba3f6892020-12-08 22:18:35 -05002/*
3 * Copyright (c) 2014-2020, Regents of the University of California
Alexander Afanasyev2b4e8852018-06-13 20:32:27 -04004 *
5 * This file is part of NAC (Name-Based Access Control for NDN).
6 * See AUTHORS.md for complete list of NAC authors and contributors.
7 *
8 * NAC is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "common.hpp"
21
Davide Pesaventoba3f6892020-12-08 22:18:35 -050022#include "tests/boost-test.hpp"
Alexander Afanasyev2b4e8852018-06-13 20:32:27 -040023
24namespace ndn {
25namespace nac {
26namespace tests {
27
28BOOST_AUTO_TEST_SUITE(TestCommon)
29
30BOOST_AUTO_TEST_CASE(Helpers)
31{
32 bool hasFailed = false;
33 auto onFailed = [&] (auto...) { hasFailed = true; };
34
35 auto kdkPrefix = convertKekNameToKdkPrefix(Name("/access/prefix/NAC/dataset/KEK/id"), onFailed);
36
37 BOOST_CHECK(!hasFailed);
38 BOOST_CHECK(kdkPrefix == Name("/access/prefix/NAC/dataset/KDK/id"));
39
40 hasFailed = false;
41 kdkPrefix = convertKekNameToKdkPrefix(Name("/invalid/name"), onFailed);
42 BOOST_CHECK(hasFailed);
43 BOOST_CHECK(kdkPrefix.empty());
44
45 hasFailed = false;
46 Name kdkIdentity, kdkKeyName;
47 std::tie(kdkPrefix, kdkIdentity, kdkKeyName) =
48 extractKdkInfoFromCkName(Name("/ck/prefix/stuff/ENCRYPTED-BY/access/prefix/NAC/dataset/KEK/id"),
49 Name("/ck/prefix/stuff"), onFailed);
50 BOOST_CHECK(!hasFailed);
51 BOOST_CHECK_EQUAL(kdkPrefix, Name("/access/prefix/NAC/dataset/KDK/id"));
52 BOOST_CHECK_EQUAL(kdkIdentity, Name("/access/prefix/NAC/dataset"));
53 BOOST_CHECK_EQUAL(kdkKeyName, Name("/access/prefix/NAC/dataset/KEY/id"));
54
55 hasFailed = false;
56 std::tie(kdkPrefix, kdkIdentity, kdkKeyName) =
57 extractKdkInfoFromCkName(Name("/ck/prefix/ENCRYPTED-BY/access/prefix/NAC/dataset/KEK/id"),
58 Name("/ck/prefix/stuff"), onFailed);
59 BOOST_CHECK(hasFailed);
60 BOOST_CHECK(kdkPrefix.empty());
61}
62
63BOOST_AUTO_TEST_SUITE_END()
64
65} // namespace tests
66} // namespace nac
67} // namespace ndn