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 | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, 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 | |
| 59 | BOOST_FIXTURE_TEST_SUITE(TestService, RibServiceFixture) |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 60 | |
| 61 | BOOST_AUTO_TEST_CASE(Basic) |
| 62 | { |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 63 | auto section = makeSection(""); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 64 | |
| 65 | BOOST_CHECK_THROW(Service::get(), std::logic_error); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 66 | BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 67 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 68 | boost::asio::post(getRibIoService(), [&] { |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 69 | { |
| 70 | BOOST_CHECK_THROW(Service::get(), std::logic_error); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 71 | Service ribService(section, m_ribKeyChain); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(&ribService, &Service::get()); |
| 73 | } |
| 74 | BOOST_CHECK_THROW(Service::get(), std::logic_error); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 75 | Service ribService(section, m_ribKeyChain); |
| 76 | BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 77 | }); |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 78 | poll(); |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 79 | } |
| 80 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 81 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
| 82 | |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 83 | BOOST_AUTO_TEST_CASE(EmptyLocalhostSecurity) |
| 84 | { |
| 85 | const std::string CONFIG = R"CONFIG( |
| 86 | rib |
| 87 | { |
| 88 | localhost_security |
| 89 | } |
| 90 | )CONFIG"; |
| 91 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 92 | boost::asio::post(getRibIoService(), [&] { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 93 | BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain)); |
| 94 | }); |
| 95 | poll(); |
| 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_CASE(EmptyPrefixAnnouncementValidation) |
| 99 | { |
| 100 | const std::string CONFIG = R"CONFIG( |
| 101 | rib |
| 102 | { |
| 103 | prefix_announcement_validation |
| 104 | } |
| 105 | )CONFIG"; |
| 106 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 107 | boost::asio::post(getRibIoService(), [&] { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 108 | BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain)); |
| 109 | }); |
| 110 | poll(); |
| 111 | } |
| 112 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 113 | BOOST_AUTO_TEST_CASE(LocalhopAndPropagate) |
| 114 | { |
| 115 | const std::string CONFIG = R"CONFIG( |
| 116 | rib |
| 117 | { |
| 118 | localhost_security |
| 119 | { |
| 120 | trust-anchor |
| 121 | { |
| 122 | type any |
| 123 | } |
| 124 | } |
| 125 | localhop_security |
| 126 | { |
| 127 | trust-anchor |
| 128 | { |
| 129 | type any |
| 130 | } |
| 131 | } |
| 132 | auto_prefix_propagate |
| 133 | } |
| 134 | )CONFIG"; |
| 135 | |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 136 | boost::asio::post(getRibIoService(), [&] { |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame] | 137 | BOOST_CHECK_EXCEPTION(Service(makeSection(CONFIG), m_ribKeyChain), ConfigFile::Error, |
| 138 | [] (const auto& e) { |
| 139 | return e.what() == "localhop_security and auto_prefix_propagate " |
| 140 | "cannot be enabled at the same time"s; |
| 141 | }); |
| 142 | }); |
| 143 | poll(); |
| 144 | } |
| 145 | |
| 146 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 147 | |
| 148 | BOOST_AUTO_TEST_SUITE_END() // TestService |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 149 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 150 | } // namespace nfd::tests |