blob: 9923efc6724e6e4337c497cb705fbe9a9a1a4d47 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rib/service.hpp"
#include "common/global.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/rib-io-fixture.hpp"
#include <boost/asio/post.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <sstream>
namespace nfd::tests {
using rib::Service;
class RibServiceFixture : public RibIoFixture
{
protected:
static ConfigSection
makeSection(const std::string& text, bool wantUnixSocketPath = true)
{
std::istringstream is(text);
ConfigSection section;
boost::property_tree::read_info(is, section);
if (wantUnixSocketPath)
section.put("face_system.unix.path", "/dev/null");
return section;
}
protected:
ndn::KeyChain m_ribKeyChain;
};
BOOST_AUTO_TEST_SUITE(Rib)
BOOST_FIXTURE_TEST_SUITE(TestService, RibServiceFixture)
BOOST_AUTO_TEST_CASE(Basic)
{
auto section = makeSection("");
BOOST_CHECK_THROW(Service::get(), std::logic_error);
BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
boost::asio::post(getRibIoService(), [&] {
{
BOOST_CHECK_THROW(Service::get(), std::logic_error);
Service ribService(section, m_ribKeyChain);
BOOST_CHECK_EQUAL(&ribService, &Service::get());
}
BOOST_CHECK_THROW(Service::get(), std::logic_error);
Service ribService(section, m_ribKeyChain);
BOOST_CHECK_THROW(Service(section, m_ribKeyChain), std::logic_error);
});
poll();
}
BOOST_AUTO_TEST_SUITE(ProcessConfig)
BOOST_AUTO_TEST_CASE(EmptyLocalhostSecurity)
{
const std::string CONFIG = R"CONFIG(
rib
{
localhost_security
}
)CONFIG";
boost::asio::post(getRibIoService(), [&] {
BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
});
poll();
}
BOOST_AUTO_TEST_CASE(EmptyPrefixAnnouncementValidation)
{
const std::string CONFIG = R"CONFIG(
rib
{
prefix_announcement_validation
}
)CONFIG";
boost::asio::post(getRibIoService(), [&] {
BOOST_CHECK_NO_THROW(Service(makeSection(CONFIG), m_ribKeyChain));
});
poll();
}
BOOST_AUTO_TEST_CASE(LocalhopAndPropagate)
{
const std::string CONFIG = R"CONFIG(
rib
{
localhost_security
{
trust-anchor
{
type any
}
}
localhop_security
{
trust-anchor
{
type any
}
}
auto_prefix_propagate
}
)CONFIG";
boost::asio::post(getRibIoService(), [&] {
BOOST_CHECK_EXCEPTION(Service(makeSection(CONFIG), m_ribKeyChain), ConfigFile::Error,
[] (const auto& e) {
return e.what() == "localhop_security and auto_prefix_propagate "
"cannot be enabled at the same time"s;
});
});
poll();
}
BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
BOOST_AUTO_TEST_SUITE_END() // TestService
BOOST_AUTO_TEST_SUITE_END() // Rib
} // namespace nfd::tests