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 | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
Wenkai Zheng | 6598fb0 | 2019-09-08 18:03:46 -0700 | [diff] [blame^] | 32 | #include <boost/property_tree/info_parser.hpp> |
| 33 | #include <sstream> |
| 34 | |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 35 | namespace nfd { |
| 36 | namespace rib { |
| 37 | namespace tests { |
| 38 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 39 | using namespace nfd::tests; |
| 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 | |
| 68 | runOnRibIoService([&] { |
| 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 | |
| 83 | BOOST_AUTO_TEST_CASE(LocalhopAndPropagate) |
| 84 | { |
| 85 | const std::string CONFIG = R"CONFIG( |
| 86 | rib |
| 87 | { |
| 88 | localhost_security |
| 89 | { |
| 90 | trust-anchor |
| 91 | { |
| 92 | type any |
| 93 | } |
| 94 | } |
| 95 | localhop_security |
| 96 | { |
| 97 | trust-anchor |
| 98 | { |
| 99 | type any |
| 100 | } |
| 101 | } |
| 102 | auto_prefix_propagate |
| 103 | } |
| 104 | )CONFIG"; |
| 105 | |
| 106 | runOnRibIoService([&] { |
| 107 | BOOST_CHECK_EXCEPTION(Service(makeSection(CONFIG), m_ribKeyChain), ConfigFile::Error, |
| 108 | [] (const auto& e) { |
| 109 | return e.what() == "localhop_security and auto_prefix_propagate " |
| 110 | "cannot be enabled at the same time"s; |
| 111 | }); |
| 112 | }); |
| 113 | poll(); |
| 114 | } |
| 115 | |
| 116 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 117 | |
| 118 | BOOST_AUTO_TEST_SUITE_END() // TestService |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 119 | |
| 120 | } // namespace tests |
| 121 | } // namespace rib |
| 122 | } // namespace nfd |