mgmt: NfdManagerBase::makeAuthorization uses CommandAuthenticator
This commit also eliminates Forwarder in Mgmt/TestFaceManager/CreateFace test suite
and uses FaceTable directly.
refs #2063
Change-Id: I596e8c2a12dad64ee75082f384955f30d574f53e
diff --git a/core/manager-base.cpp b/core/manager-base.cpp
index 02190a2..3aeec6f 100644
--- a/core/manager-base.cpp
+++ b/core/manager-base.cpp
@@ -33,7 +33,7 @@
ManagerBase::ManagerBase(Dispatcher& dispatcher,
const std::string& module)
: m_dispatcher(dispatcher)
- , m_mgmtModuleName(module)
+ , m_module(module)
{
}
diff --git a/core/manager-base.hpp b/core/manager-base.hpp
index 8ace6bb..cb90541 100644
--- a/core/manager-base.hpp
+++ b/core/manager-base.hpp
@@ -62,6 +62,12 @@
ManagerBase(Dispatcher& dispatcher,
const std::string& module);
+ const std::string&
+ getModule() const
+ {
+ return m_module;
+ }
+
PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
// difference from mgmt::ControlCommand: accepts nfd::ControlParameters
@@ -134,14 +140,14 @@
makeRelPrefix(const std::string& verb);
private:
- Dispatcher& m_dispatcher;
- std::string m_mgmtModuleName;
+ Dispatcher& m_dispatcher;
+ std::string m_module;
};
inline PartialName
ManagerBase::makeRelPrefix(const std::string& verb)
{
- return PartialName(m_mgmtModuleName).append(verb);
+ return PartialName(m_module).append(verb);
}
template<typename Command>
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index e3e0cb8..8b7057c 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -52,8 +52,8 @@
NFD_LOG_INIT("FaceManager");
-FaceManager::FaceManager(FaceTable& faceTable, Dispatcher& dispatcher, CommandValidator& validator)
- : NfdManagerBase(dispatcher, validator, "faces")
+FaceManager::FaceManager(FaceTable& faceTable, Dispatcher& dispatcher, CommandAuthenticator& authenticator)
+ : NfdManagerBase(dispatcher, authenticator, "faces")
, m_faceTable(faceTable)
{
registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index ec0af92..f31f04b 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -46,7 +46,7 @@
public:
FaceManager(FaceTable& faceTable,
Dispatcher& dispatcher,
- CommandValidator& validator);
+ CommandAuthenticator& authenticator);
/**
* @brief Subscribe to face_system section for the config file
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index 1c15ebf..9992789 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -34,8 +34,8 @@
FibManager::FibManager(Fib& fib,
const FaceTable& faceTable,
Dispatcher& dispatcher,
- CommandValidator& validator)
- : NfdManagerBase(dispatcher, validator, "fib")
+ CommandAuthenticator& authenticator)
+ : NfdManagerBase(dispatcher, authenticator, "fib")
, m_fib(fib)
, m_faceTable(faceTable)
{
diff --git a/daemon/mgmt/fib-manager.hpp b/daemon/mgmt/fib-manager.hpp
index 9599a01..b5c6984 100644
--- a/daemon/mgmt/fib-manager.hpp
+++ b/daemon/mgmt/fib-manager.hpp
@@ -42,18 +42,10 @@
class FibManager : public NfdManagerBase
{
public:
- /**
- * @brief construct a FibManger
- *
- * @param fib the managed FIB
- * @param faceTable FaceTable for querying available faces
- * @param dispatcher the management dispatcher
- * @param validator the command validator
- */
FibManager(Fib& fib,
const FaceTable& faceTable,
Dispatcher& dispatcher,
- CommandValidator& validator);
+ CommandAuthenticator& authenticator);
private:
void
diff --git a/daemon/mgmt/nfd-manager-base.cpp b/daemon/mgmt/nfd-manager-base.cpp
index b30eca7..b417934 100644
--- a/daemon/mgmt/nfd-manager-base.cpp
+++ b/daemon/mgmt/nfd-manager-base.cpp
@@ -28,28 +28,17 @@
namespace nfd {
NfdManagerBase::NfdManagerBase(Dispatcher& dispatcher,
- CommandValidator& validator,
+ CommandAuthenticator& authenticator,
const std::string& module)
: ManagerBase(dispatcher, module)
- , m_validator(validator)
+ , m_authenticator(authenticator)
{
- m_validator.addSupportedPrivilege(module);
}
ndn::mgmt::Authorization
NfdManagerBase::makeAuthorization(const std::string& verb)
{
- return [this] (const Name& prefix, const Interest& interest,
- const ndn::mgmt::ControlParameters* params,
- const ndn::mgmt::AcceptContinuation& accept,
- const ndn::mgmt::RejectContinuation& reject) {
- BOOST_ASSERT(params != nullptr);
- BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
-
- m_validator.validate(interest,
- bind([&interest, this, accept] { extractRequester(interest, accept); }),
- bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
- };
+ return m_authenticator.makeAuthorization(this->getModule(), verb);
}
} // namespace nfd
diff --git a/daemon/mgmt/nfd-manager-base.hpp b/daemon/mgmt/nfd-manager-base.hpp
index 49a3ea2..27c3392 100644
--- a/daemon/mgmt/nfd-manager-base.hpp
+++ b/daemon/mgmt/nfd-manager-base.hpp
@@ -26,14 +26,8 @@
#ifndef NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
#define NFD_DAEMON_MGMT_NFD_MANAGER_BASE_HPP
-#include "core/common.hpp"
-#include "command-validator.hpp"
#include "core/manager-base.hpp"
-
-#include <ndn-cxx/mgmt/dispatcher.hpp>
-#include <ndn-cxx/management/nfd-control-command.hpp>
-#include <ndn-cxx/management/nfd-control-response.hpp>
-#include <ndn-cxx/management/nfd-control-parameters.hpp>
+#include "command-authenticator.hpp"
namespace nfd {
@@ -48,7 +42,7 @@
{
public:
NfdManagerBase(Dispatcher& dispatcher,
- CommandValidator& validator,
+ CommandAuthenticator& authenticator,
const std::string& module);
PUBLIC_WITH_TESTS_ELSE_PRIVATE: // command validation
@@ -56,7 +50,7 @@
makeAuthorization(const std::string& verb) override;
private:
- CommandValidator& m_validator;
+ CommandAuthenticator& m_authenticator;
};
} // namespace nfd
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index 1f0c208..312a35c 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -33,8 +33,8 @@
StrategyChoiceManager::StrategyChoiceManager(StrategyChoice& strategyChoice,
Dispatcher& dispatcher,
- CommandValidator& validator)
- : NfdManagerBase(dispatcher, validator, "strategy-choice")
+ CommandAuthenticator& authenticator)
+ : NfdManagerBase(dispatcher, authenticator, "strategy-choice")
, m_table(strategyChoice)
{
registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>("set",
diff --git a/daemon/mgmt/strategy-choice-manager.hpp b/daemon/mgmt/strategy-choice-manager.hpp
index 9fd4ad3..5520790 100644
--- a/daemon/mgmt/strategy-choice-manager.hpp
+++ b/daemon/mgmt/strategy-choice-manager.hpp
@@ -43,7 +43,7 @@
public:
StrategyChoiceManager(strategy_choice::StrategyChoice& table,
Dispatcher& dispatcher,
- CommandValidator& validator);
+ CommandAuthenticator& authenticator);
private:
void
diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp
index 35fc941..5d6bec7 100644
--- a/daemon/nfd.cpp
+++ b/daemon/nfd.cpp
@@ -38,9 +38,6 @@
#include "mgmt/forwarder-status-manager.hpp"
#include "mgmt/general-config-section.hpp"
#include "mgmt/tables-config-section.hpp"
-#include "mgmt/command-validator.hpp"
-
-#include <ndn-cxx/mgmt/dispatcher.hpp>
namespace nfd {
@@ -74,12 +71,10 @@
{
}
-Nfd::~Nfd()
-{
- // It is necessary to explicitly define the destructor, because some member variables (e.g.,
- // unique_ptr<Forwarder>) are forward-declared, but implicitly declared destructor requires
- // complete types for all members when instantiated.
-}
+// It is necessary to explicitly define the destructor, because some member variables (e.g.,
+// unique_ptr<Forwarder>) are forward-declared, but implicitly declared destructor requires
+// complete types for all members when instantiated.
+Nfd::~Nfd() = default;
void
Nfd::initialize()
@@ -125,7 +120,6 @@
}
}
-
static inline void
ignoreRibAndLogSections(const std::string& filename, const std::string& sectionName,
const ConfigSection& section, bool isDryRun)
@@ -146,24 +140,17 @@
{
std::tie(m_internalFace, m_internalClientFace) = face::makeInternalFace(m_keyChain);
m_forwarder->getFaceTable().addReserved(m_internalFace, face::FACEID_INTERNAL_FACE);
+
m_dispatcher.reset(new ndn::mgmt::Dispatcher(*m_internalClientFace, m_keyChain));
-
- m_validator.reset(new CommandValidator());
-
- m_fibManager.reset(new FibManager(m_forwarder->getFib(),
- m_forwarder->getFaceTable(),
- *m_dispatcher,
- *m_validator));
-
- m_faceManager.reset(new FaceManager(m_forwarder->getFaceTable(),
- *m_dispatcher,
- *m_validator));
-
- m_strategyChoiceManager.reset(new StrategyChoiceManager(m_forwarder->getStrategyChoice(),
- *m_dispatcher,
- *m_validator));
+ m_authenticator = CommandAuthenticator::create();
m_forwarderStatusManager.reset(new ForwarderStatusManager(*m_forwarder, *m_dispatcher));
+ m_faceManager.reset(new FaceManager(m_forwarder->getFaceTable(),
+ *m_dispatcher, *m_authenticator));
+ m_fibManager.reset(new FibManager(m_forwarder->getFib(), m_forwarder->getFaceTable(),
+ *m_dispatcher, *m_authenticator));
+ m_strategyChoiceManager.reset(new StrategyChoiceManager(m_forwarder->getStrategyChoice(),
+ *m_dispatcher, *m_authenticator));
ConfigFile config(&ignoreRibAndLogSections);
general::setConfigFile(config);
@@ -176,8 +163,7 @@
m_forwarder->getNetworkRegionTable());
tablesConfig.setConfigFile(config);
- m_validator->setConfigFile(config);
-
+ m_authenticator->setConfigFile(config);
m_faceManager->setConfigFile(config);
// parse config file
@@ -216,10 +202,9 @@
m_forwarder->getStrategyChoice(),
m_forwarder->getMeasurements(),
m_forwarder->getNetworkRegionTable());
-
tablesConfig.setConfigFile(config);
- m_validator->setConfigFile(config);
+ m_authenticator->setConfigFile(config);
m_faceManager->setConfigFile(config);
if (!m_configFile.empty()) {
diff --git a/daemon/nfd.hpp b/daemon/nfd.hpp
index d8fd12e..f98d3b6 100644
--- a/daemon/nfd.hpp
+++ b/daemon/nfd.hpp
@@ -42,11 +42,11 @@
namespace nfd {
class Forwarder;
+class CommandAuthenticator;
class FibManager;
class FaceManager;
class StrategyChoiceManager;
class ForwarderStatusManager;
-class CommandValidator;
namespace face {
class Face;
@@ -107,19 +107,18 @@
unique_ptr<Forwarder> m_forwarder;
- ndn::KeyChain& m_keyChain;
- shared_ptr<face::Face> m_internalFace;
- shared_ptr<ndn::Face> m_internalClientFace;
- unique_ptr<CommandValidator> m_validator;
-
- unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
- unique_ptr<FibManager> m_fibManager;
- unique_ptr<FaceManager> m_faceManager;
- unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
+ ndn::KeyChain& m_keyChain;
+ shared_ptr<face::Face> m_internalFace;
+ shared_ptr<ndn::Face> m_internalClientFace;
+ unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
+ shared_ptr<CommandAuthenticator> m_authenticator;
unique_ptr<ForwarderStatusManager> m_forwarderStatusManager;
+ unique_ptr<FaceManager> m_faceManager;
+ unique_ptr<FibManager> m_fibManager;
+ unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
unique_ptr<ndn::util::NetworkMonitor> m_networkMonitor;
- scheduler::ScopedEventId m_reloadConfigEvent;
+ scheduler::ScopedEventId m_reloadConfigEvent;
};
} // namespace nfd
diff --git a/tests/daemon/mgmt/face-manager-create-face.t.cpp b/tests/daemon/mgmt/face-manager-create-face.t.cpp
index 8c67b3a..ef59037 100644
--- a/tests/daemon/mgmt/face-manager-create-face.t.cpp
+++ b/tests/daemon/mgmt/face-manager-create-face.t.cpp
@@ -24,7 +24,7 @@
*/
#include "mgmt/face-manager.hpp"
-#include "fw/forwarder.hpp"
+#include "fw/face-table.hpp"
#include <ndn-cxx/mgmt/dispatcher.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -46,10 +46,10 @@
{
public:
FaceManagerNode(ndn::KeyChain& keyChain, const std::string& port = "6363")
- : faceTable(forwarder.getFaceTable())
- , face(getGlobalIoService(), keyChain, {true, true})
+ : face(getGlobalIoService(), keyChain, {true, true})
, dispatcher(face, keyChain, ndn::security::SigningInfo())
- , manager(faceTable, dispatcher, validator)
+ , authenticator(CommandAuthenticator::create())
+ , manager(faceTable, dispatcher, *authenticator)
{
dispatcher.addTopPrefix("/localhost/nfd");
@@ -88,7 +88,7 @@
ConfigFile config;
manager.setConfigFile(config);
- validator.setConfigFile(config);
+ authenticator->setConfigFile(config);
config.parse(configSection, false, "dummy-config");
}
@@ -96,24 +96,21 @@
closeFaces()
{
std::vector<std::reference_wrapper<Face>> facesToClose;
- std::copy(forwarder.getFaceTable().begin(), forwarder.getFaceTable().end(),
- std::back_inserter(facesToClose));
+ std::copy(faceTable.begin(), faceTable.end(), std::back_inserter(facesToClose));
for (Face& face : facesToClose) {
face.close();
}
}
public:
- Forwarder forwarder;
- FaceTable& faceTable;
+ FaceTable faceTable;
ndn::util::DummyClientFace face;
ndn::mgmt::Dispatcher dispatcher;
- CommandValidator validator;
+ shared_ptr<CommandAuthenticator> authenticator;
FaceManager manager;
};
-class FaceManagerFixture : public UnitTestTimeFixture
- , public IdentityManagementFixture
+class FaceManagerFixture : public IdentityManagementTimeFixture
{
public:
FaceManagerFixture()
@@ -401,7 +398,7 @@
BOOST_REQUIRE_EQUAL(controlResponse.getText(), "OK");
BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 200);
uint64_t faceId = ControlParameters(controlResponse.getBody()).getFaceId();
- auto face = this->node2.forwarder.getFace(static_cast<FaceId>(faceId));
+ auto face = this->node2.faceTable.get(static_cast<FaceId>(faceId));
// to force creation of on-demand face
auto dummyInterest = make_shared<Interest>("/hello/world");
diff --git a/tests/daemon/mgmt/face-manager-process-config.t.cpp b/tests/daemon/mgmt/face-manager-process-config.t.cpp
index 6296fc8..16996b8 100644
--- a/tests/daemon/mgmt/face-manager-process-config.t.cpp
+++ b/tests/daemon/mgmt/face-manager-process-config.t.cpp
@@ -42,7 +42,7 @@
{
public:
FaceManagerProcessConfigFixture()
- : m_manager(m_forwarder.getFaceTable(), m_dispatcher, m_validator)
+ : m_manager(m_forwarder.getFaceTable(), m_dispatcher, *m_authenticator)
{
m_manager.setConfigFile(m_config);
}
diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp
index 851a785..95f82b9 100644
--- a/tests/daemon/mgmt/face-manager.t.cpp
+++ b/tests/daemon/mgmt/face-manager.t.cpp
@@ -44,8 +44,9 @@
public:
FaceManagerFixture()
: m_faceTable(m_forwarder.getFaceTable())
- , m_manager(m_faceTable, m_dispatcher, m_validator)
+ , m_manager(m_faceTable, m_dispatcher, *m_authenticator)
{
+ setTopPrefix();
setPrivilege("faces");
}
diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp
index 3e5ee0e..f03b7b9 100644
--- a/tests/daemon/mgmt/fib-manager.t.cpp
+++ b/tests/daemon/mgmt/fib-manager.t.cpp
@@ -38,8 +38,9 @@
FibManagerFixture()
: m_fib(m_forwarder.getFib())
, m_faceTable(m_forwarder.getFaceTable())
- , m_manager(m_fib, m_faceTable, m_dispatcher, m_validator)
+ , m_manager(m_fib, m_faceTable, m_dispatcher, *m_authenticator)
{
+ setTopPrefix();
setPrivilege("fib");
}
diff --git a/tests/daemon/mgmt/forwarder-status-manager.t.cpp b/tests/daemon/mgmt/forwarder-status-manager.t.cpp
index c267943..3bd8127 100644
--- a/tests/daemon/mgmt/forwarder-status-manager.t.cpp
+++ b/tests/daemon/mgmt/forwarder-status-manager.t.cpp
@@ -40,7 +40,7 @@
: manager(m_forwarder, m_dispatcher)
, startTime(time::system_clock::now())
{
- setPrivilege("status");
+ setTopPrefix();
}
protected:
diff --git a/tests/daemon/mgmt/nfd-manager-base.t.cpp b/tests/daemon/mgmt/nfd-manager-base.t.cpp
deleted file mode 100644
index 340c9ec..0000000
--- a/tests/daemon/mgmt/nfd-manager-base.t.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, 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 "mgmt/nfd-manager-base.hpp"
-#include "manager-common-fixture.hpp"
-
-#include <ndn-cxx/security/key-chain.hpp>
-#include <ndn-cxx/management/nfd-control-command.hpp>
-
-namespace nfd {
-namespace tests {
-
-class NfdManagerBaseFixture : public ManagerCommonFixture
-{
-public:
- NfdManagerBaseFixture()
- : m_manager(m_dispatcher, m_validator, "test-module")
- {
- }
-
-protected:
- CommandValidator m_validator;
- NfdManagerBase m_manager;
-};
-
-BOOST_AUTO_TEST_SUITE(Mgmt)
-BOOST_FIXTURE_TEST_SUITE(TestNfdManagerBase, NfdManagerBaseFixture)
-
-BOOST_AUTO_TEST_CASE(AddSupportedPrivilegeInConstructor)
-{
- BOOST_CHECK_NO_THROW(m_validator.addSupportedPrivilege("other-module"));
- // test-module has already been added by the constructor of ManagerBase
- BOOST_CHECK_THROW(m_validator.addSupportedPrivilege("test-module"), CommandValidator::Error);
-}
-
-BOOST_AUTO_TEST_CASE(CommandAuthorization)
-{
- ndn::mgmt::Authorization authorize = m_manager.makeAuthorization("test-verb");
-
- bool didAcceptCallbackFire = false;
- bool didRejectCallbackFire = false;
- auto testAuthorization = [&] {
- didAcceptCallbackFire = false;
- didRejectCallbackFire = false;
-
- auto command = makeControlCommandRequest("/localhost/nfd/test-module/test-verb",
- ControlParameters());
- ndn::nfd::ControlParameters params;
- authorize("/top/prefix", *command, ¶ms,
- bind([&] { didAcceptCallbackFire = true; }),
- bind([&] { didRejectCallbackFire = true; }));
- };
-
- testAuthorization();
- BOOST_CHECK(!didAcceptCallbackFire);
- BOOST_CHECK(didRejectCallbackFire);
-
- m_validator.addInterestRule("^<localhost><nfd><test-module>", *m_certificate);
- testAuthorization();
- BOOST_CHECK(didAcceptCallbackFire);
- BOOST_CHECK(!didRejectCallbackFire);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestNfdManagerBase
-BOOST_AUTO_TEST_SUITE_END() // Mgmt
-
-} // namespace tests
-} // namespace nfd
diff --git a/tests/daemon/mgmt/nfd-manager-common-fixture.cpp b/tests/daemon/mgmt/nfd-manager-common-fixture.cpp
new file mode 100644
index 0000000..47a1655
--- /dev/null
+++ b/tests/daemon/mgmt/nfd-manager-common-fixture.cpp
@@ -0,0 +1,67 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2016, 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 "nfd-manager-common-fixture.hpp"
+
+namespace nfd {
+namespace tests {
+
+NfdManagerCommonFixture::NfdManagerCommonFixture()
+ : m_authenticator(CommandAuthenticator::create())
+{
+}
+
+void
+NfdManagerCommonFixture::setTopPrefix()
+{
+ this->ManagerCommonFixture::setTopPrefix("/localhost/nfd");
+}
+
+void
+NfdManagerCommonFixture::setPrivilege(const std::string& privilege)
+{
+ this->saveIdentityCertificate(m_identityName, "ManagerCommonFixture.ndncert");
+
+ const std::string& config = R"CONFIG(
+ authorizations
+ {
+ authorize
+ {
+ certfile "ManagerCommonFixture.ndncert"
+ privileges
+ {
+ )CONFIG" + privilege + R"CONFIG(
+ }
+ }
+ }
+ )CONFIG";
+
+ ConfigFile cf;
+ m_authenticator->setConfigFile(cf);
+ cf.parse(config, false, "ManagerCommonFixture.authenticator.conf");
+}
+
+} // namespace tests
+} // namespace nfd
diff --git a/tests/daemon/mgmt/nfd-manager-common-fixture.hpp b/tests/daemon/mgmt/nfd-manager-common-fixture.hpp
index ba06839..32650ce 100644
--- a/tests/daemon/mgmt/nfd-manager-common-fixture.hpp
+++ b/tests/daemon/mgmt/nfd-manager-common-fixture.hpp
@@ -23,54 +23,39 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_TESTS_NFD_MGMT_NFD_MANAGER_COMMON_HPP
-#define NFD_TESTS_NFD_MGMT_NFD_MANAGER_COMMON_HPP
+#ifndef NFD_TESTS_NFD_MGMT_NFD_MANAGER_COMMON_FIXTURE_HPP
+#define NFD_TESTS_NFD_MGMT_NFD_MANAGER_COMMON_FIXTURE_HPP
#include "manager-common-fixture.hpp"
#include "fw/forwarder.hpp"
-#include "mgmt/command-validator.hpp"
+#include "mgmt/command-authenticator.hpp"
namespace nfd {
namespace tests {
-/**
- * @brief a base class shared by all NFD manager's testing fixtures.
+/** \brief base fixture for testing an NFD Manager
*/
class NfdManagerCommonFixture : public ManagerCommonFixture
{
public:
- NfdManagerCommonFixture()
- : m_topPrefix("/localhost/nfd")
- {
- }
+ NfdManagerCommonFixture();
- /**
- * @brief configure an interest rule for the module.
- *
- * set top prefix before set privilege.
- *
- * @param privilege the module name
+ /** \brief add /localhost/nfd as a top prefix to the dispatcher
*/
void
- setPrivilege(const std::string& privilege)
- {
- setTopPrefix(m_topPrefix);
+ setTopPrefix();
- std::string regex("^");
- for (auto component : m_topPrefix) {
- regex += "<" + component.toUri() + ">";
- }
-
- m_validator.addInterestRule(regex + "<" + privilege + ">", *m_certificate);
- }
+ /** \brief grant m_identityName privilege to sign commands for the management module
+ */
+ void
+ setPrivilege(const std::string& privilege);
protected:
Forwarder m_forwarder;
- CommandValidator m_validator;
- Name m_topPrefix;
+ shared_ptr<CommandAuthenticator> m_authenticator;
};
} // namespace tests
} // namespace nfd
-#endif // NFD_TESTS_NFD_MGMT_NFD_MANAGER_COMMON_HPP
+#endif // NFD_TESTS_NFD_MGMT_NFD_MANAGER_COMMON_FIXTURE_HPP
diff --git a/tests/daemon/mgmt/strategy-choice-manager.t.cpp b/tests/daemon/mgmt/strategy-choice-manager.t.cpp
index 5915e3e..bc4ae70 100644
--- a/tests/daemon/mgmt/strategy-choice-manager.t.cpp
+++ b/tests/daemon/mgmt/strategy-choice-manager.t.cpp
@@ -47,8 +47,9 @@
public:
StrategyChoiceManagerFixture()
: m_strategyChoice(m_forwarder.getStrategyChoice())
- , m_manager(m_strategyChoice, m_dispatcher, m_validator)
+ , m_manager(m_strategyChoice, m_dispatcher, *m_authenticator)
{
+ setTopPrefix();
setPrivilege("strategy-choice");
}
diff --git a/tests/manager-common-fixture.cpp b/tests/manager-common-fixture.cpp
index a491296..88db7e1 100644
--- a/tests/manager-common-fixture.cpp
+++ b/tests/manager-common-fixture.cpp
@@ -24,6 +24,7 @@
*/
#include "manager-common-fixture.hpp"
+#include <ndn-cxx/security/signing-helpers.hpp>
namespace nfd {
namespace tests {
@@ -33,8 +34,8 @@
, m_dispatcher(m_face, m_keyChain, ndn::security::SigningInfo())
, m_responses(m_face.sentData)
, m_identityName("/unit-test/ManagerCommonFixture/identity")
- , m_certificate(m_keyChain.getCertificate(m_keyChain.createIdentity(m_identityName)))
{
+ BOOST_REQUIRE(this->addIdentity(m_identityName));
}
void
@@ -55,8 +56,7 @@
beforeSigning(command);
}
- m_keyChain.sign(*command, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
- m_identityName));
+ m_keyChain.sign(*command, ndn::security::signingByIdentity(m_identityName));
return command;
}
diff --git a/tests/manager-common-fixture.hpp b/tests/manager-common-fixture.hpp
index a29c441..b829476 100644
--- a/tests/manager-common-fixture.hpp
+++ b/tests/manager-common-fixture.hpp
@@ -39,8 +39,7 @@
/**
* @brief a collection of common functions shared by all manager's testing fixtures.
*/
-class ManagerCommonFixture : public UnitTestTimeFixture
- , public IdentityManagementFixture
+class ManagerCommonFixture : public IdentityManagementTimeFixture
{
public: // initialize
ManagerCommonFixture();
@@ -146,8 +145,7 @@
ndn::util::DummyClientFace m_face;
ndn::mgmt::Dispatcher m_dispatcher;
std::vector<Data>& m_responses; ///< a reference of m_face->sentData
- Name m_identityName; ///< the identity used to sign request
- shared_ptr<ndn::IdentityCertificate> m_certificate; ///< the certificate used to sign request
+ Name m_identityName; ///< the identity to sign requests
};
std::ostream&