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/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");
}