Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | caa60cc | 2024-02-18 18:18:37 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "rib/service.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/global.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 28 | |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 30 | #include "tests/daemon/rib-io-fixture.hpp" |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 31 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 32 | #include <boost/asio/post.hpp> |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 33 | #include <boost/property_tree/info_parser.hpp> |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 34 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 35 | #include <sstream> |
| 36 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::tests { |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 38 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 39 | using rib::Service; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 40 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 41 | class RibServiceFixture : public RibIoFixture |
| 42 | { |
| 43 | protected: |
| 44 | static ConfigSection |
| 45 | makeSection(const std::string& text, bool wantUnixSocketPath = true) |
| 46 | { |
| 47 | std::istringstream is(text); |
| 48 | ConfigSection section; |
| 49 | boost::property_tree::read_info(is, section); |
| 50 | if (wantUnixSocketPath) |
| 51 | section.put("face_system.unix.path", "/dev/null"); |
| 52 | return section; |
| 53 | } |
| 54 | |
| 55 | protected: |
| 56 | ndn::KeyChain m_ribKeyChain; |
| 57 | }; |
| 58 | |
Davide Pesavento | caa60cc | 2024-02-18 18:18:37 -0500 | [diff] [blame^] | 59 | BOOST_AUTO_TEST_SUITE(Rib) |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 60 | BOOST_FIXTURE_TEST_SUITE(TestService, RibServiceFixture) |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 61 | |
| 62 | BOOST_AUTO_TEST_CASE(Basic) |
| 63 | { |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 64 | auto section = makeSection(""); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 65 | |
| 66 | BOOST_CHECK_THROW(Service::get(), std::logic_error); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 67 | BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 68 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 69 | boost::asio::post(getRibIoService(), [&] { |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 70 | { |
| 71 | BOOST_CHECK_THROW(Service::get(), std::logic_error); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 72 | Service ribService(section, m_ribKeyChain); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(&ribService, &Service::get()); |
| 74 | } |
| 75 | BOOST_CHECK_THROW(Service::get(), std::logic_error); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 76 | Service ribService(section, m_ribKeyChain); |
| 77 | BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 78 | }); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 79 | poll(); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 80 | } |
| 81 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 82 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
| 83 | |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(EmptyLocalhostSecurity) |
| 85 | { |
| 86 | const std::string CONFIG = R"CONFIG( |
| 87 | rib |
| 88 | { |
| 89 | localhost_security |
| 90 | } |
| 91 | )CONFIG"; |
| 92 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 93 | boost::asio::post(getRibIoService(), [&] { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 94 | BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain)); |
| 95 | }); |
| 96 | poll(); |
| 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(EmptyPrefixAnnouncementValidation) |
| 100 | { |
| 101 | const std::string CONFIG = R"CONFIG( |
| 102 | rib |
| 103 | { |
| 104 | prefix_announcement_validation |
| 105 | } |
| 106 | )CONFIG"; |
| 107 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 108 | boost::asio::post(getRibIoService(), [&] { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 109 | BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain)); |
| 110 | }); |
| 111 | poll(); |
| 112 | } |
| 113 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 114 | BOOST_AUTO_TEST_CASE(LocalhopAndPropagate) |
| 115 | { |
| 116 | const std::string CONFIG = R"CONFIG( |
| 117 | rib |
| 118 | { |
| 119 | localhost_security |
| 120 | { |
| 121 | trust-anchor |
| 122 | { |
| 123 | type any |
| 124 | } |
| 125 | } |
| 126 | localhop_security |
| 127 | { |
| 128 | trust-anchor |
| 129 | { |
| 130 | type any |
| 131 | } |
| 132 | } |
| 133 | auto_prefix_propagate |
| 134 | } |
| 135 | )CONFIG"; |
| 136 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 137 | boost::asio::post(getRibIoService(), [&] { |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 138 | BOOST_CHECK_EXCEPTION(Service(makeSection(CONFIG), m_ribKeyChain), ConfigFile::Error, |
| 139 | [] (const auto& e) { |
| 140 | return e.what() == "localhop_security and auto_prefix_propagate " |
| 141 | "cannot be enabled at the same time"s; |
| 142 | }); |
| 143 | }); |
| 144 | poll(); |
| 145 | } |
| 146 | |
| 147 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 148 | |
| 149 | BOOST_AUTO_TEST_SUITE_END() // TestService |
Davide Pesavento | caa60cc | 2024-02-18 18:18:37 -0500 | [diff] [blame^] | 150 | BOOST_AUTO_TEST_SUITE_END() // Rib |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 151 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 152 | } // namespace nfd::tests |