blob: caa59d32a50fb0f4cbe7bb446c38d1ec4c8f4040 [file] [log] [blame]
Teng Liang04d5ce62018-08-06 10:20:24 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento3dade002019-03-19 11:29:56 -06003 * Copyright (c) 2014-2019, 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
Teng Liang04d5ce62018-08-06 10:20:24 +080035namespace nfd {
36namespace rib {
37namespace tests {
38
Davide Pesavento14e71f02019-03-28 17:35:25 -040039using namespace nfd::tests;
40
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
59BOOST_FIXTURE_TEST_SUITE(TestService, RibServiceFixture)
Teng Liang04d5ce62018-08-06 10:20:24 +080060
61BOOST_AUTO_TEST_CASE(Basic)
62{
Wenkai Zheng6598fb02019-09-08 18:03:46 -070063 auto section = makeSection("");
Teng Liang04d5ce62018-08-06 10:20:24 +080064
65 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070066 BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
Teng Liang04d5ce62018-08-06 10:20:24 +080067
68 runOnRibIoService([&] {
69 {
70 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070071 Service ribService(section, m_ribKeyChain);
Teng Liang04d5ce62018-08-06 10:20:24 +080072 BOOST_CHECK_EQUAL(&ribService, &Service::get());
73 }
74 BOOST_CHECK_THROW(Service::get(), std::logic_error);
Wenkai Zheng6598fb02019-09-08 18:03:46 -070075 Service ribService(section, m_ribKeyChain);
76 BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
Teng Liang04d5ce62018-08-06 10:20:24 +080077 });
Wenkai Zheng6598fb02019-09-08 18:03:46 -070078 poll();
Teng Liang04d5ce62018-08-06 10:20:24 +080079}
80
Wenkai Zheng6598fb02019-09-08 18:03:46 -070081BOOST_AUTO_TEST_SUITE(ProcessConfig)
82
Teng Liang18c2b292019-10-18 14:31:04 -070083BOOST_AUTO_TEST_CASE(EmptyLocalhostSecurity)
84{
85 const std::string CONFIG = R"CONFIG(
86 rib
87 {
88 localhost_security
89 }
90 )CONFIG";
91
92 runOnRibIoService([&] {
93 BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
94 });
95 poll();
96}
97
98BOOST_AUTO_TEST_CASE(EmptyPrefixAnnouncementValidation)
99{
100 const std::string CONFIG = R"CONFIG(
101 rib
102 {
103 prefix_announcement_validation
104 }
105 )CONFIG";
106
107 runOnRibIoService([&] {
108 BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
109 });
110 poll();
111}
112
Wenkai Zheng6598fb02019-09-08 18:03:46 -0700113BOOST_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
136 runOnRibIoService([&] {
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
146BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
147
148BOOST_AUTO_TEST_SUITE_END() // TestService
Teng Liang04d5ce62018-08-06 10:20:24 +0800149
150} // namespace tests
151} // namespace rib
152} // namespace nfd