blob: 4832afd898924404839d01063b9f78387e35b0e8 [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
83BOOST_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
116BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
117
118BOOST_AUTO_TEST_SUITE_END() // TestService
Teng Liang04d5ce62018-08-06 10:20:24 +0800119
120} // namespace tests
121} // namespace rib
122} // namespace nfd