blob: c4d995fe0b5abbec8f9e0d5459a7d37af88053a7 [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/*
Davide Pesaventobde084f2022-04-17 00:21:35 -04003 * Copyright (c) 2014-2022, 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
Davide Pesaventobde084f2022-04-17 00:21:35 -040024namespace ndn::nac::tests {
Alexander Afanasyev2b4e8852018-06-13 20:32:27 -040025
26BOOST_AUTO_TEST_SUITE(TestCommon)
27
28BOOST_AUTO_TEST_CASE(Helpers)
29{
30 bool hasFailed = false;
Davide Pesaventobde084f2022-04-17 00:21:35 -040031 auto onFailed = [&] (auto&&...) { hasFailed = true; };
Alexander Afanasyev2b4e8852018-06-13 20:32:27 -040032
33 auto kdkPrefix = convertKekNameToKdkPrefix(Name("/access/prefix/NAC/dataset/KEK/id"), onFailed);
34
35 BOOST_CHECK(!hasFailed);
36 BOOST_CHECK(kdkPrefix == Name("/access/prefix/NAC/dataset/KDK/id"));
37
38 hasFailed = false;
39 kdkPrefix = convertKekNameToKdkPrefix(Name("/invalid/name"), onFailed);
40 BOOST_CHECK(hasFailed);
41 BOOST_CHECK(kdkPrefix.empty());
42
43 hasFailed = false;
44 Name kdkIdentity, kdkKeyName;
45 std::tie(kdkPrefix, kdkIdentity, kdkKeyName) =
46 extractKdkInfoFromCkName(Name("/ck/prefix/stuff/ENCRYPTED-BY/access/prefix/NAC/dataset/KEK/id"),
47 Name("/ck/prefix/stuff"), onFailed);
48 BOOST_CHECK(!hasFailed);
49 BOOST_CHECK_EQUAL(kdkPrefix, Name("/access/prefix/NAC/dataset/KDK/id"));
50 BOOST_CHECK_EQUAL(kdkIdentity, Name("/access/prefix/NAC/dataset"));
51 BOOST_CHECK_EQUAL(kdkKeyName, Name("/access/prefix/NAC/dataset/KEY/id"));
52
53 hasFailed = false;
54 std::tie(kdkPrefix, kdkIdentity, kdkKeyName) =
55 extractKdkInfoFromCkName(Name("/ck/prefix/ENCRYPTED-BY/access/prefix/NAC/dataset/KEK/id"),
56 Name("/ck/prefix/stuff"), onFailed);
57 BOOST_CHECK(hasFailed);
58 BOOST_CHECK(kdkPrefix.empty());
59}
60
61BOOST_AUTO_TEST_SUITE_END()
62
Davide Pesaventobde084f2022-04-17 00:21:35 -040063} // namespace ndn::nac::tests