Alexander Afanasyev | 2b4e885 | 2018-06-13 20:32:27 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California |
Alexander Afanasyev | 2b4e885 | 2018-06-13 20:32:27 -0400 | [diff] [blame] | 4 | * |
| 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 Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 22 | #include "tests/boost-test.hpp" |
Alexander Afanasyev | 2b4e885 | 2018-06-13 20:32:27 -0400 | [diff] [blame] | 23 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 24 | namespace ndn::nac::tests { |
Alexander Afanasyev | 2b4e885 | 2018-06-13 20:32:27 -0400 | [diff] [blame] | 25 | |
| 26 | BOOST_AUTO_TEST_SUITE(TestCommon) |
| 27 | |
| 28 | BOOST_AUTO_TEST_CASE(Helpers) |
| 29 | { |
| 30 | bool hasFailed = false; |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 31 | auto onFailed = [&] (auto&&...) { hasFailed = true; }; |
Alexander Afanasyev | 2b4e885 | 2018-06-13 20:32:27 -0400 | [diff] [blame] | 32 | |
| 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 | |
| 61 | BOOST_AUTO_TEST_SUITE_END() |
| 62 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 63 | } // namespace ndn::nac::tests |