blob: 9923efc6724e6e4337c497cb705fbe9a9a1a4d47 [file] [log] [blame]
Teng Liang04d5ce62018-08-06 10:20:24 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventocaa60cc2024-02-18 18:18:37 -05003 * Copyright (c) 2014-2024, 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
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -040032#include <boost/asio/post.hpp>
Wenkai Zheng6598fb02019-09-08 18:03:46 -070033#include <boost/property_tree/info_parser.hpp>
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -040034
Wenkai Zheng6598fb02019-09-08 18:03:46 -070035#include <sstream>
36
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040037namespace nfd::tests {
Teng Liang04d5ce62018-08-06 10:20:24 +080038
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040039using rib::Service;
Davide Pesavento14e71f02019-03-28 17:35:25 -040040
Wenkai Zheng6598fb02019-09-08 18:03:46 -070041class RibServiceFixture : public RibIoFixture
42{
43protected:
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
55protected:
56 ndn::KeyChain m_ribKeyChain;
57};
58
Davide Pesaventocaa60cc2024-02-18 18:18:37 -050059BOOST_AUTO_TEST_SUITE(Rib)
Wenkai Zheng6598fb02019-09-08 18:03:46 -070060BOOST_FIXTURE_TEST_SUITE(TestService, RibServiceFixture)
Teng Liang04d5ce62018-08-06 10:20:24 +080061
62BOOST_AUTO_TEST_CASE(Basic)
63{
Wenkai Zheng6598fb02019-09-08 18:03:46 -070064 auto section = makeSection("");
Teng Liang04d5ce62018-08-06 10:20:24 +080065
66 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070067 BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
Teng Liang04d5ce62018-08-06 10:20:24 +080068
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -040069 boost::asio::post(getRibIoService(), [&] {
Teng Liang04d5ce62018-08-06 10:20:24 +080070 {
71 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070072 Service ribService(section, m_ribKeyChain);
Teng Liang04d5ce62018-08-06 10:20:24 +080073 BOOST_CHECK_EQUAL(&ribService, &Service::get());
74 }
75 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070076 Service ribService(section, m_ribKeyChain);
77 BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
Teng Liang04d5ce62018-08-06 10:20:24 +080078 });
Wenkai Zheng6598fb02019-09-08 18:03:46 -070079 poll();
Teng Liang04d5ce62018-08-06 10:20:24 +080080}
81
Wenkai Zheng6598fb02019-09-08 18:03:46 -070082BOOST_AUTO_TEST_SUITE(ProcessConfig)
83
Teng Liang18c2b292019-10-18 14:31:04 -070084BOOST_AUTO_TEST_CASE(EmptyLocalhostSecurity)
85{
86 const std::string CONFIG = R"CONFIG(
87 rib
88 {
89 localhost_security
90 }
91 )CONFIG";
92
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -040093 boost::asio::post(getRibIoService(), [&] {
Teng Liang18c2b292019-10-18 14:31:04 -070094 BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
95 });
96 poll();
97}
98
99BOOST_AUTO_TEST_CASE(EmptyPrefixAnnouncementValidation)
100{
101 const std::string CONFIG = R"CONFIG(
102 rib
103 {
104 prefix_announcement_validation
105 }
106 )CONFIG";
107
Davide Pesaventoa9e1ab22023-10-02 22:10:45 -0400108 boost::asio::post(getRibIoService(), [&] {
Teng Liang18c2b292019-10-18 14:31:04 -0700109 BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
110 });
111 poll();
112}
113
Wenkai Zheng6598fb02019-09-08 18:03:46 -0700114BOOST_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 Pesaventoa9e1ab22023-10-02 22:10:45 -0400137 boost::asio::post(getRibIoService(), [&] {
Wenkai Zheng6598fb02019-09-08 18:03:46 -0700138 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
147BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
148
149BOOST_AUTO_TEST_SUITE_END() // TestService
Davide Pesaventocaa60cc2024-02-18 18:18:37 -0500150BOOST_AUTO_TEST_SUITE_END() // Rib
Teng Liang04d5ce62018-08-06 10:20:24 +0800151
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400152} // namespace nfd::tests