tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 2 | /* |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2017-2022, Regents of the University of California. |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 21 | #include "name-assignment/assignment-email.hpp" |
Zhiyi Zhang | c2c4ed2 | 2020-10-14 17:16:28 -0700 | [diff] [blame] | 22 | #include "name-assignment/assignment-random.hpp" |
| 23 | #include "name-assignment/assignment-param.hpp" |
| 24 | #include "name-assignment/assignment-hash.hpp" |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 25 | |
Davide Pesavento | 829aff6 | 2022-05-15 20:30:34 -0400 | [diff] [blame] | 26 | #include "tests/boost-test.hpp" |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 27 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 28 | namespace ndncert::tests { |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TestNameAssignment) |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 31 | |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 32 | BOOST_AUTO_TEST_CASE(NameAssignmentRandom) |
| 33 | { |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame] | 34 | AssignmentRandom assignment; |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 35 | BOOST_CHECK_EQUAL(assignment.assignName(std::multimap<std::string, std::string>()).size(), 1); |
| 36 | BOOST_CHECK_EQUAL(assignment.assignName(std::multimap<std::string, std::string>()).begin()->size(), 1); |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(NameAssignmentParam) |
| 40 | { |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame] | 41 | AssignmentParam assignment("/abc/xyz"); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 42 | std::multimap<std::string, std::string> params; |
| 43 | params.emplace("abc", "123"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 45 | params.emplace("xyz", "789"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 47 | BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/123/789")); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 48 | params.emplace("fake", "456"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 49 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 50 | BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/123/789")); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 51 | params.find("xyz")->second = ""; |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 53 | |
| 54 | AssignmentParam assignment2("/\"guest\"/email"); |
| 55 | params.emplace("email", "1@1.com"); |
| 56 | BOOST_CHECK_EQUAL(assignment2.assignName(params).size(), 1); |
| 57 | BOOST_CHECK_EQUAL(assignment2.assignName(params).begin()->toUri(), Name("/guest/1@1.com").toUri()); |
| 58 | |
| 59 | AssignmentParam assignment3("/\"/email"); |
| 60 | BOOST_CHECK_EQUAL(assignment3.assignName(params).size(), 0); |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(NameAssignmentHash) |
| 64 | { |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 65 | AssignmentHash assignment("/abc/xyz"); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 66 | std::multimap<std::string, std::string> params; |
| 67 | params.emplace("abc", "123"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 69 | params.emplace("xyz", "789"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 71 | BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 72 | params.emplace("fake", "456"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 74 | BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2); |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 75 | params.find("xyz")->second = ""; |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 77 | BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2); |
tylerliu | bcd8348 | 2020-10-07 14:45:28 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 80 | BOOST_AUTO_TEST_CASE(NameAssignmentEmail) |
| 81 | { |
| 82 | AssignmentEmail assignment("/edu/ucla"); |
| 83 | std::multimap<std::string, std::string> params; |
| 84 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
| 85 | params.emplace("email", "das@math.ucla.edu"); |
| 86 | BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/math/das")); |
| 87 | |
| 88 | params.clear(); |
| 89 | params.emplace("email", "d/~.^as@6666=.9!"); |
| 90 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 91 | BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/9!/6666%3D/d%2F~.%5Eas")); |
| 92 | } |
| 93 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 94 | BOOST_AUTO_TEST_SUITE_END() // TestNameAssignment |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 95 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 96 | } // namespace ndncert::tests |