tests: IdentityManagementFixture no longer derives from BaseFixture
Also rename it to KeyChainFixture Refs: #4528 Change-Id: Id86f4affc9c4c9ae159912430cc3e78557bf1ac2
This commit is contained in:
@@ -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 @@ BOOST_AUTO_TEST_SUITE(Face)
|
||||
|
||||
using nfd::Face;
|
||||
|
||||
class GenericLinkServiceFixture : public IdentityManagementTimeFixture
|
||||
class GenericLinkServiceFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
protected:
|
||||
GenericLinkServiceFixture()
|
||||
|
||||
@@ -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 @@ using namespace nfd::tests;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Face)
|
||||
|
||||
class InternalFaceFixture : public UnitTestTimeFixture
|
||||
, public IdentityManagementFixture
|
||||
class InternalFaceFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
public:
|
||||
InternalFaceFixture()
|
||||
|
||||
@@ -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 @@ namespace tests {
|
||||
|
||||
/** \brief A fixture that provides a CommandInterestSigner.
|
||||
*/
|
||||
class CommandInterestSignerFixture : public IdentityManagementTimeFixture
|
||||
class CommandInterestSignerFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
protected:
|
||||
CommandInterestSignerFixture();
|
||||
|
||||
@@ -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 @@ namespace tests {
|
||||
|
||||
using rib::Route;
|
||||
|
||||
class RibManagerSlAnnounceFixture : public IdentityManagementTimeFixture
|
||||
class RibManagerSlAnnounceFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
public:
|
||||
using SlAnnounceResult = RibManager::SlAnnounceResult;
|
||||
|
||||
@@ -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 @@ compareNameFaceIdCostAction(const FibUpdate& lhs, const FibUpdate& rhs)
|
||||
return false;
|
||||
}
|
||||
|
||||
class FibUpdatesFixture : public nfd::tests::IdentityManagementFixture
|
||||
class FibUpdatesFixture : public nfd::tests::BaseFixture, public nfd::tests::KeyChainFixture
|
||||
{
|
||||
public:
|
||||
FibUpdatesFixture()
|
||||
|
||||
@@ -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 @@ namespace tests {
|
||||
|
||||
using namespace nfd::tests;
|
||||
|
||||
class HostToGatewayReadvertisePolicyFixture : public IdentityManagementFixture
|
||||
class HostToGatewayReadvertisePolicyFixture : public BaseFixture, public KeyChainFixture
|
||||
{
|
||||
public:
|
||||
static RibRouteRef
|
||||
|
||||
@@ -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 @@ namespace tests {
|
||||
|
||||
using namespace nfd::tests;
|
||||
|
||||
class NfdRibReadvertiseDestinationFixture : public IdentityManagementTimeFixture
|
||||
class NfdRibReadvertiseDestinationFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
public:
|
||||
NfdRibReadvertiseDestinationFixture()
|
||||
|
||||
@@ -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 @@ public:
|
||||
std::vector<HistoryEntry> withdrawHistory;
|
||||
};
|
||||
|
||||
class ReadvertiseFixture : public IdentityManagementTimeFixture
|
||||
class ReadvertiseFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
public:
|
||||
ReadvertiseFixture()
|
||||
|
||||
@@ -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 @@ IdentityManagementFixture::~IdentityManagementFixture()
|
||||
}
|
||||
|
||||
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 @@ IdentityManagementFixture::addIdentity(const Name& identity, const ndn::KeyParam
|
||||
}
|
||||
|
||||
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 @@ IdentityManagementFixture::saveIdentityCertificate(const Name& identity, const s
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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 @@ public:
|
||||
|
||||
/** \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 @@ private:
|
||||
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
|
||||
@@ -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 @@ using ndn::nfd::ControlParameters;
|
||||
|
||||
/** \brief fixture to emulate NFD management
|
||||
*/
|
||||
class MockNfdMgmtFixture : public IdentityManagementTimeFixture
|
||||
class MockNfdMgmtFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
protected:
|
||||
MockNfdMgmtFixture()
|
||||
|
||||
@@ -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 tools {
|
||||
namespace autoconfig_server {
|
||||
namespace tests {
|
||||
|
||||
using namespace ::nfd::tests;
|
||||
|
||||
class AutoconfigServerFixture : public IdentityManagementFixture
|
||||
class AutoconfigServerFixture : public ::nfd::tests::KeyChainFixture
|
||||
{
|
||||
public:
|
||||
AutoconfigServerFixture()
|
||||
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
std::function<void()> processEventsFunc;
|
||||
};
|
||||
|
||||
class StatusReportModulesFixture : public IdentityManagementTimeFixture
|
||||
class StatusReportModulesFixture : public UnitTestTimeFixture, public KeyChainFixture
|
||||
{
|
||||
protected:
|
||||
StatusReportModulesFixture()
|
||||
|
||||
Reference in New Issue
Block a user