tests: IdentityManagementFixture no longer derives from BaseFixture
Also rename it to KeyChainFixture
Refs: #4528
Change-Id: Id86f4affc9c4c9ae159912430cc3e78557bf1ac2
diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp
index 13d9476..00b6517 100644
--- a/tests/daemon/face/generic-link-service.t.cpp
+++ b/tests/daemon/face/generic-link-service.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,7 @@
#include "face/face.hpp"
#include "dummy-transport.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include "tests/test-common.hpp"
#include <ndn-cxx/lp/empty-value.hpp>
@@ -45,7 +45,7 @@
using nfd::Face;
-class GenericLinkServiceFixture : public IdentityManagementTimeFixture
+class GenericLinkServiceFixture : public UnitTestTimeFixture, public KeyChainFixture
{
protected:
GenericLinkServiceFixture()
diff --git a/tests/daemon/face/internal-face.t.cpp b/tests/daemon/face/internal-face.t.cpp
index 4371317..dfb9888 100644
--- a/tests/daemon/face/internal-face.t.cpp
+++ b/tests/daemon/face/internal-face.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,7 @@
#include "face/internal-face.hpp"
#include "transport-test-common.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
namespace nfd {
namespace face {
@@ -36,8 +36,7 @@
BOOST_AUTO_TEST_SUITE(Face)
-class InternalFaceFixture : public UnitTestTimeFixture
- , public IdentityManagementFixture
+class InternalFaceFixture : public UnitTestTimeFixture, public KeyChainFixture
{
public:
InternalFaceFixture()
diff --git a/tests/daemon/mgmt/manager-common-fixture.hpp b/tests/daemon/mgmt/manager-common-fixture.hpp
index 8725680..a12d671 100644
--- a/tests/daemon/mgmt/manager-common-fixture.hpp
+++ b/tests/daemon/mgmt/manager-common-fixture.hpp
@@ -29,7 +29,7 @@
#include "mgmt/manager-base.hpp"
#include "fw/forwarder.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/security/command-interest-signer.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -39,7 +39,7 @@
/** \brief A fixture that provides a CommandInterestSigner.
*/
-class CommandInterestSignerFixture : public IdentityManagementTimeFixture
+class CommandInterestSignerFixture : public UnitTestTimeFixture, public KeyChainFixture
{
protected:
CommandInterestSignerFixture();
diff --git a/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp b/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
index ea3ca10..6310ced 100644
--- a/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
+++ b/tests/daemon/mgmt/rib-manager-sl-announce.t.cpp
@@ -26,7 +26,7 @@
#include "mgmt/rib-manager.hpp"
#include "rib/fib-updater.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -35,7 +35,7 @@
using rib::Route;
-class RibManagerSlAnnounceFixture : public IdentityManagementTimeFixture
+class RibManagerSlAnnounceFixture : public UnitTestTimeFixture, public KeyChainFixture
{
public:
using SlAnnounceResult = RibManager::SlAnnounceResult;
diff --git a/tests/daemon/rib/fib-updates-common.hpp b/tests/daemon/rib/fib-updates-common.hpp
index 4668af5..7a123d3 100644
--- a/tests/daemon/rib/fib-updates-common.hpp
+++ b/tests/daemon/rib/fib-updates-common.hpp
@@ -28,7 +28,7 @@
#include "rib/fib-updater.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include "tests/daemon/rib/create-route.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -60,7 +60,7 @@
return false;
}
-class FibUpdatesFixture : public nfd::tests::IdentityManagementFixture
+class FibUpdatesFixture : public nfd::tests::BaseFixture, public nfd::tests::KeyChainFixture
{
public:
FibUpdatesFixture()
diff --git a/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp b/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
index c455065..aaff73e 100644
--- a/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
+++ b/tests/daemon/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
@@ -25,7 +25,7 @@
#include "rib/readvertise/host-to-gateway-readvertise-policy.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/security/signing-helpers.hpp>
@@ -35,7 +35,7 @@
using namespace nfd::tests;
-class HostToGatewayReadvertisePolicyFixture : public IdentityManagementFixture
+class HostToGatewayReadvertisePolicyFixture : public BaseFixture, public KeyChainFixture
{
public:
static RibRouteRef
diff --git a/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp b/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
index e3afcbf..6787769 100644
--- a/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
+++ b/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
@@ -25,7 +25,7 @@
#include "rib/readvertise/nfd-rib-readvertise-destination.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include "tests/test-common.hpp"
#include <ndn-cxx/security/signing-info.hpp>
@@ -37,7 +37,7 @@
using namespace nfd::tests;
-class NfdRibReadvertiseDestinationFixture : public IdentityManagementTimeFixture
+class NfdRibReadvertiseDestinationFixture : public UnitTestTimeFixture, public KeyChainFixture
{
public:
NfdRibReadvertiseDestinationFixture()
diff --git a/tests/daemon/rib/readvertise/readvertise.t.cpp b/tests/daemon/rib/readvertise/readvertise.t.cpp
index d2d8bb2..15cc105 100644
--- a/tests/daemon/rib/readvertise/readvertise.t.cpp
+++ b/tests/daemon/rib/readvertise/readvertise.t.cpp
@@ -25,9 +25,10 @@
#include "rib/readvertise/readvertise.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
+
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/copy.hpp>
@@ -110,7 +111,7 @@
std::vector<HistoryEntry> withdrawHistory;
};
-class ReadvertiseFixture : public IdentityManagementTimeFixture
+class ReadvertiseFixture : public UnitTestTimeFixture, public KeyChainFixture
{
public:
ReadvertiseFixture()
diff --git a/tests/identity-management-fixture.cpp b/tests/key-chain-fixture.cpp
similarity index 79%
rename from tests/identity-management-fixture.cpp
rename to tests/key-chain-fixture.cpp
index e9b2762..acefabe 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/key-chain-fixture.cpp
@@ -23,25 +23,27 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
+
#include <ndn-cxx/security/pib/identity.hpp>
#include <ndn-cxx/security/pib/key.hpp>
#include <ndn-cxx/security/pib/pib.hpp>
#include <ndn-cxx/security/transform.hpp>
#include <ndn-cxx/security/v2/certificate.hpp>
#include <ndn-cxx/util/io.hpp>
+
#include <boost/filesystem.hpp>
namespace nfd {
namespace tests {
-IdentityManagementFixture::IdentityManagementFixture()
+KeyChainFixture::KeyChainFixture()
: m_keyChain("pib-memory:", "tpm-memory:")
{
m_keyChain.createIdentity("/DEFAULT");
}
-IdentityManagementFixture::~IdentityManagementFixture()
+KeyChainFixture::~KeyChainFixture()
{
boost::system::error_code ec;
for (const auto& certFile : m_certFiles) {
@@ -50,7 +52,7 @@
}
bool
-IdentityManagementFixture::addIdentity(const Name& identity, const ndn::KeyParams& params)
+KeyChainFixture::addIdentity(const Name& identity, const ndn::KeyParams& params)
{
try {
m_keyChain.createIdentity(identity, params);
@@ -62,15 +64,15 @@
}
bool
-IdentityManagementFixture::saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd)
+KeyChainFixture::saveIdentityCertificate(const Name& identity, const std::string& filename, bool allowAdd)
{
ndn::security::v2::Certificate cert;
try {
cert = m_keyChain.getPib().getIdentity(identity).getDefaultKey().getDefaultCertificate();
}
catch (const ndn::security::Pib::Error&) {
- if (wantAdd && this->addIdentity(identity)) {
- return this->saveIdentityCertificate(identity, filename, false);
+ if (allowAdd && addIdentity(identity)) {
+ return saveIdentityCertificate(identity, filename, false);
}
return false;
}
@@ -86,24 +88,24 @@
}
std::string
-IdentityManagementFixture::getIdentityCertificateBase64(const Name& identity, bool wantAdd)
+KeyChainFixture::getIdentityCertificateBase64(const Name& identity, bool allowAdd)
{
ndn::security::v2::Certificate cert;
try {
cert = m_keyChain.getPib().getIdentity(identity).getDefaultKey().getDefaultCertificate();
}
catch (const ndn::security::Pib::Error&) {
- if (!wantAdd) {
+ if (!allowAdd) {
NDN_THROW_NESTED(std::runtime_error("Identity does not exist"));
}
cert = m_keyChain.createIdentity(identity).getDefaultKey().getDefaultCertificate();
}
- Block wire = cert.wireEncode();
+ const auto& block = cert.wireEncode();
- std::ostringstream oss;
namespace tr = ndn::security::transform;
- tr::bufferSource(wire.wire(), wire.size()) >> tr::base64Encode(false) >> tr::streamSink(oss);
+ std::ostringstream oss;
+ tr::bufferSource(block.wire(), block.size()) >> tr::base64Encode(false) >> tr::streamSink(oss);
return oss.str();
}
diff --git a/tests/identity-management-fixture.hpp b/tests/key-chain-fixture.hpp
similarity index 66%
rename from tests/identity-management-fixture.hpp
rename to tests/key-chain-fixture.hpp
index 0dbf333..810dab8 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/key-chain-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,26 +23,21 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
-#define NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
+#ifndef NFD_TESTS_KEY_CHAIN_FIXTURE_HPP
+#define NFD_TESTS_KEY_CHAIN_FIXTURE_HPP
#include "tests/test-common.hpp"
+
#include <ndn-cxx/security/key-chain.hpp>
namespace nfd {
namespace tests {
-/** \brief a fixture providing an in-memory KeyChain
+/** \brief A fixture providing an in-memory KeyChain.
*/
-class IdentityManagementFixture : public virtual BaseFixture
+class KeyChainFixture
{
public:
- IdentityManagementFixture();
-
- /** \brief deletes saved certificate files
- */
- ~IdentityManagementFixture();
-
/** \brief add identity
* \return whether successful
*/
@@ -52,20 +47,27 @@
/** \brief save identity certificate to a file
* \param identity identity name
- * \param filename file name, should be writable
- * \param wantAdd if true, add new identity when necessary
+ * \param filename file name, must be writable
+ * \param allowAdd if true, add new identity when necessary
* \return whether successful
*/
bool
- saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false);
+ saveIdentityCertificate(const Name& identity, const std::string& filename, bool allowAdd = false);
/** \brief retrieve identity certificate as base64 string
* \param identity identity name
- * \param wantAdd if true, add new identity when necessary
- * \throw std::runtime_error identity does not exist and wantAdd is false
+ * \param allowAdd if true, add new identity when necessary
+ * \throw std::runtime_error identity does not exist and \p allowAdd is false
*/
std::string
- getIdentityCertificateBase64(const Name& identity, bool wantAdd = false);
+ getIdentityCertificateBase64(const Name& identity, bool allowAdd = false);
+
+protected:
+ KeyChainFixture();
+
+ /** \brief deletes saved certificate files
+ */
+ ~KeyChainFixture();
protected:
ndn::KeyChain m_keyChain;
@@ -74,15 +76,7 @@
std::vector<std::string> m_certFiles;
};
-/** \brief convenience base class for inheriting from both UnitTestTimeFixture
- * and IdentityManagementFixture
- */
-class IdentityManagementTimeFixture : public UnitTestTimeFixture
- , public IdentityManagementFixture
-{
-};
-
} // namespace tests
} // namespace nfd
-#endif // NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
+#endif // NFD_TESTS_KEY_CHAIN_FIXTURE_HPP
diff --git a/tests/tools/mock-nfd-mgmt-fixture.hpp b/tests/tools/mock-nfd-mgmt-fixture.hpp
index 0a67326..9e8bd53 100644
--- a/tests/tools/mock-nfd-mgmt-fixture.hpp
+++ b/tests/tools/mock-nfd-mgmt-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,7 @@
#define NFD_TESTS_TOOLS_MOCK_NFD_MGMT_FIXTURE_HPP
#include "tests/test-common.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
#include <ndn-cxx/mgmt/nfd/control-response.hpp>
@@ -42,7 +42,7 @@
/** \brief fixture to emulate NFD management
*/
-class MockNfdMgmtFixture : public IdentityManagementTimeFixture
+class MockNfdMgmtFixture : public UnitTestTimeFixture, public KeyChainFixture
{
protected:
MockNfdMgmtFixture()
diff --git a/tests/tools/ndn-autoconfig-server/program.t.cpp b/tests/tools/ndn-autoconfig-server/program.t.cpp
index 1b928b0..b8209b0 100644
--- a/tests/tools/ndn-autoconfig-server/program.t.cpp
+++ b/tests/tools/ndn-autoconfig-server/program.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -25,7 +25,7 @@
#include "ndn-autoconfig-server/program.hpp"
-#include "tests/identity-management-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/encoding/buffer.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -35,9 +35,7 @@
namespace autoconfig_server {
namespace tests {
-using namespace ::nfd::tests;
-
-class AutoconfigServerFixture : public IdentityManagementFixture
+class AutoconfigServerFixture : public ::nfd::tests::KeyChainFixture
{
public:
AutoconfigServerFixture()
diff --git a/tests/tools/nfdc/status-report.t.cpp b/tests/tools/nfdc/status-report.t.cpp
index d15b901..6b1cd20 100644
--- a/tests/tools/nfdc/status-report.t.cpp
+++ b/tests/tools/nfdc/status-report.t.cpp
@@ -120,7 +120,7 @@
std::function<void()> processEventsFunc;
};
-class StatusReportModulesFixture : public IdentityManagementTimeFixture
+class StatusReportModulesFixture : public UnitTestTimeFixture, public KeyChainFixture
{
protected:
StatusReportModulesFixture()