blob: 5b808ccc9330b97fb02d841cda9a9e7a555ec3af [file] [log] [blame]
Teng Liang04d5ce62018-08-06 10:20:24 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Teng Liang04d5ce62018-08-06 10:20:24 +08004 * 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 Pesavento2cae8ca2019-04-18 20:48:05 -040027#include "common/global.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060028
Teng Liang04d5ce62018-08-06 10:20:24 +080029#include "tests/test-common.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060030#include "tests/daemon/rib-io-fixture.hpp"
Teng Liang04d5ce62018-08-06 10:20:24 +080031
Wenkai Zheng6598fb02019-09-08 18:03:46 -070032#include <boost/property_tree/info_parser.hpp>
33#include <sstream>
34
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040035namespace nfd::tests {
Teng Liang04d5ce62018-08-06 10:20:24 +080036
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040037using rib::Service;
Davide Pesavento14e71f02019-03-28 17:35:25 -040038
Wenkai Zheng6598fb02019-09-08 18:03:46 -070039class RibServiceFixture : public RibIoFixture
40{
41protected:
42 static ConfigSection
43 makeSection(const std::string& text, bool wantUnixSocketPath = true)
44 {
45 std::istringstream is(text);
46 ConfigSection section;
47 boost::property_tree::read_info(is, section);
48 if (wantUnixSocketPath)
49 section.put("face_system.unix.path", "/dev/null");
50 return section;
51 }
52
53protected:
54 ndn::KeyChain m_ribKeyChain;
55};
56
57BOOST_FIXTURE_TEST_SUITE(TestService, RibServiceFixture)
Teng Liang04d5ce62018-08-06 10:20:24 +080058
59BOOST_AUTO_TEST_CASE(Basic)
60{
Wenkai Zheng6598fb02019-09-08 18:03:46 -070061 auto section = makeSection("");
Teng Liang04d5ce62018-08-06 10:20:24 +080062
63 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070064 BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
Teng Liang04d5ce62018-08-06 10:20:24 +080065
66 runOnRibIoService([&] {
67 {
68 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070069 Service ribService(section, m_ribKeyChain);
Teng Liang04d5ce62018-08-06 10:20:24 +080070 BOOST_CHECK_EQUAL(&ribService, &Service::get());
71 }
72 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070073 Service ribService(section, m_ribKeyChain);
74 BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
Teng Liang04d5ce62018-08-06 10:20:24 +080075 });
Wenkai Zheng6598fb02019-09-08 18:03:46 -070076 poll();
Teng Liang04d5ce62018-08-06 10:20:24 +080077}
78
Wenkai Zheng6598fb02019-09-08 18:03:46 -070079BOOST_AUTO_TEST_SUITE(ProcessConfig)
80
Teng Liang18c2b292019-10-18 14:31:04 -070081BOOST_AUTO_TEST_CASE(EmptyLocalhostSecurity)
82{
83 const std::string CONFIG = R"CONFIG(
84 rib
85 {
86 localhost_security
87 }
88 )CONFIG";
89
90 runOnRibIoService([&] {
91 BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
92 });
93 poll();
94}
95
96BOOST_AUTO_TEST_CASE(EmptyPrefixAnnouncementValidation)
97{
98 const std::string CONFIG = R"CONFIG(
99 rib
100 {
101 prefix_announcement_validation
102 }
103 )CONFIG";
104
105 runOnRibIoService([&] {
106 BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
107 });
108 poll();
109}
110
Wenkai Zheng6598fb02019-09-08 18:03:46 -0700111BOOST_AUTO_TEST_CASE(LocalhopAndPropagate)
112{
113 const std::string CONFIG = R"CONFIG(
114 rib
115 {
116 localhost_security
117 {
118 trust-anchor
119 {
120 type any
121 }
122 }
123 localhop_security
124 {
125 trust-anchor
126 {
127 type any
128 }
129 }
130 auto_prefix_propagate
131 }
132 )CONFIG";
133
134 runOnRibIoService([&] {
135 BOOST_CHECK_EXCEPTION(Service(makeSection(CONFIG), m_ribKeyChain), ConfigFile::Error,
136 [] (const auto& e) {
137 return e.what() == "localhop_security and auto_prefix_propagate "
138 "cannot be enabled at the same time"s;
139 });
140 });
141 poll();
142}
143
144BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
145
146BOOST_AUTO_TEST_SUITE_END() // TestService
Teng Liang04d5ce62018-08-06 10:20:24 +0800147
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400148} // namespace nfd::tests