tests: sync common testing infrastructure with ndn-cxx

Change-Id: I6feab5247231abc35b8daa96bca21ad17c9cc4b3
This commit is contained in:
Davide Pesavento committed 2020-11-20 00:43:44 -05:00
1 parent 3dc9fd0b82
commit 2135375d36
23 files changed
+236 -164

No files matched your search

+3 -3
View File
@@ -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-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,13 +24,13 @@
*/
/** \file
* \brief provides unit testing tools to validate runtime type information
* \brief Provides unit testing tools to validate runtime type information.
*/
#ifndef NFD_TESTS_CHECK_TYPEID_HPP
#define NFD_TESTS_CHECK_TYPEID_HPP
#include "boost-test.hpp"
#include "tests/boost-test.hpp"
#include <boost/core/demangle.hpp>
#include <typeinfo>
+3 -12
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,10 +28,9 @@
namespace nfd {
namespace tests {
ClockFixture::ClockFixture(boost::asio::io_service& io)
ClockFixture::ClockFixture()
: m_steadyClock(make_shared<time::UnitTestSteadyClock>())
, m_systemClock(make_shared<time::UnitTestSystemClock>())
, m_io(io)
{
time::setCustomClocks(m_steadyClock, m_systemClock);
}
@@ -53,17 +52,9 @@ ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total)
m_systemClock->advance(t);
total -= t;
pollAfterClockTick();
afterTick();
}
}
void
ClockFixture::pollAfterClockTick()
{
if (m_io.stopped())
m_io.reset();
m_io.poll();
}
} // namespace tests
} // namespace nfd
+11 -11
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -44,10 +44,10 @@ public:
/** \brief Advance steady and system clocks.
*
* Clocks are advanced in increments of \p tick for \p nTicks ticks.
* After each tick, global io_service is polled to process pending I/O events.
* afterTick() is called after each tick.
*
* Exceptions thrown during I/O events are propagated to the caller.
* Clock advancing would stop in case of an exception.
* Clock advancement will stop in the event of an exception.
*/
void
advanceClocks(time::nanoseconds tick, size_t nTicks = 1)
@@ -59,30 +59,30 @@ public:
*
* Clocks are advanced in increments of \p tick for \p total time.
* The last increment might be shorter than \p tick.
* After each tick, global io_service is polled to process pending I/O events.
* afterTick() is called after each tick.
*
* Exceptions thrown during I/O events are propagated to the caller.
* Clock advancing would stop in case of an exception.
* Clock advancement will stop in the event of an exception.
*/
void
advanceClocks(time::nanoseconds tick, time::nanoseconds total);
protected:
explicit
ClockFixture(boost::asio::io_service& io);
ClockFixture();
private:
/** \brief Called by advanceClocks() after each clock advancement (tick).
*
* The base class implementation is a no-op.
*/
virtual void
pollAfterClockTick();
afterTick()
{
}
protected:
shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
shared_ptr<time::UnitTestSystemClock> m_systemClock;
private:
boost::asio::io_service& m_io;
};
} // namespace tests
@@ -34,7 +34,6 @@
#include <ndn-cxx/lp/empty-value.hpp>
#include <ndn-cxx/lp/prefix-announcement-header.hpp>
#include <ndn-cxx/lp/tags.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
namespace nfd {
namespace face {
+4 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -52,9 +52,10 @@ GlobalIoFixture::pollIo()
return g_io.poll();
}
GlobalIoTimeFixture::GlobalIoTimeFixture()
: ClockFixture(g_io)
void
GlobalIoTimeFixture::afterTick()
{
pollIo();
}
} // namespace tests
+5 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -56,10 +56,11 @@ protected:
/** \brief GlobalIoFixture that also overrides steady clock and system clock.
*/
class GlobalIoTimeFixture : public GlobalIoFixture, public ClockFixture
class GlobalIoTimeFixture : public ClockFixture, public GlobalIoFixture
{
protected:
GlobalIoTimeFixture();
private:
void
afterTick() final;
};
} // namespace tests
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -106,9 +106,9 @@ BOOST_AUTO_TEST_CASE(Certs)
Name id0("/localhost/CommandAuthenticator/0");
Name id1("/localhost/CommandAuthenticator/1");
Name id2("/localhost/CommandAuthenticator/2");
BOOST_REQUIRE(addIdentity(id0));
BOOST_REQUIRE(saveIdentityCertificate(id1, "1.ndncert", true));
BOOST_REQUIRE(saveIdentityCertificate(id2, "2.ndncert", true));
BOOST_REQUIRE(m_keyChain.createIdentity(id0));
BOOST_REQUIRE(saveIdentityCert(id1, "1.ndncert", true));
BOOST_REQUIRE(saveIdentityCert(id2, "2.ndncert", true));
makeModules({"module0", "module1", "module2", "module3", "module4", "module5", "module6", "module7"});
const std::string& config = R"CONFIG(
@@ -196,8 +196,8 @@ BOOST_AUTO_TEST_CASE(Requester)
{
Name id0("/localhost/CommandAuthenticator/0");
Name id1("/localhost/CommandAuthenticator/1");
BOOST_REQUIRE(addIdentity(id0));
BOOST_REQUIRE(saveIdentityCertificate(id1, "1.ndncert", true));
BOOST_REQUIRE(m_keyChain.createIdentity(id0));
BOOST_REQUIRE(saveIdentityCert(id1, "1.ndncert", true));
makeModules({"module0", "module1"});
const std::string& config = R"CONFIG(
@@ -241,7 +241,7 @@ protected:
IdentityAuthorizedFixture()
: id1("/localhost/CommandAuthenticator/1")
{
BOOST_REQUIRE(saveIdentityCertificate(id1, "1.ndncert", true));
BOOST_REQUIRE(saveIdentityCert(id1, "1.ndncert", true));
makeModules({"module1"});
const std::string& config = R"CONFIG(
@@ -322,7 +322,7 @@ BOOST_AUTO_TEST_CASE(BadKeyLocator_BadKeyLocatorType)
BOOST_AUTO_TEST_CASE(NotAuthorized)
{
Name id0("/localhost/CommandAuthenticator/0");
BOOST_REQUIRE(addIdentity(id0));
BOOST_REQUIRE(m_keyChain.createIdentity(id0));
BOOST_CHECK_EQUAL(authorize("module1", id0), false);
BOOST_CHECK(lastRejectReply == ndn::mgmt::RejectReply::STATUS403);
@@ -357,7 +357,7 @@ BOOST_AUTO_TEST_CASE(InvalidTimestamp)
BOOST_FIXTURE_TEST_CASE(MissingAuthorizationsSection, CommandAuthenticatorFixture)
{
Name id0("/localhost/CommandAuthenticator/0");
BOOST_REQUIRE(addIdentity(id0));
BOOST_REQUIRE(m_keyChain.createIdentity(id0));
makeModules({"module42"});
loadConfig("");
+3 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -25,8 +25,6 @@
#include "manager-common-fixture.hpp"
#include <ndn-cxx/security/signing-helpers.hpp>
namespace nfd {
namespace tests {
@@ -35,7 +33,7 @@ const Name CommandInterestSignerFixture::DEFAULT_COMMAND_SIGNER_IDENTITY("/Comma
CommandInterestSignerFixture::CommandInterestSignerFixture()
: m_commandInterestSigner(m_keyChain)
{
BOOST_REQUIRE(this->addIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY));
BOOST_REQUIRE(m_keyChain.createIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY));
}
Interest
@@ -196,7 +194,7 @@ operator<<(std::ostream& os, ManagerCommonFixture::CheckResponseResult result)
void
ManagerFixtureWithAuthenticator::setPrivilege(const std::string& privilege)
{
saveIdentityCertificate(DEFAULT_COMMAND_SIGNER_IDENTITY, "ManagerCommonFixture.ndncert");
saveIdentityCert(DEFAULT_COMMAND_SIGNER_IDENTITY, "ManagerCommonFixture.ndncert");
const std::string& config = R"CONFIG(
authorizations
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,6 +30,9 @@
#include "tests/daemon/global-io-fixture.hpp"
#include "tests/daemon/rib/fib-updates-common.hpp"
#include <ndn-cxx/security/transform/base64-encode.hpp>
#include <ndn-cxx/security/transform/buffer-source.hpp>
#include <ndn-cxx/security/transform/stream-sink.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
#include <boost/property_tree/info_parser.hpp>
@@ -137,7 +140,7 @@ public:
/** \brief Lookup a route with PREFIXANN origin.
*/
Route*
findAnnRoute(const Name& name, uint64_t faceId)
findAnnRoute(const Name& name, uint64_t faceId) const
{
Route routeQuery;
routeQuery.faceId = faceId;
@@ -145,6 +148,21 @@ public:
return rib.find(name, routeQuery);
}
/** \brief Retrieve an identity certificate as a base64 string.
*/
std::string
getIdentityCertificateBase64(const Name& identity) const
{
auto cert = m_keyChain.getPib().getIdentity(identity).getDefaultKey().getDefaultCertificate();
const auto& block = cert.wireEncode();
namespace tr = ndn::security::transform;
std::ostringstream oss;
tr::bufferSource(block.wire(), block.size()) >> tr::base64Encode(false) >> tr::streamSink(oss);
return oss.str();
}
private:
void
loadDefaultPaConfig()
@@ -158,7 +176,7 @@ private:
manager->applyPaConfig(makeSection(CONFIG), "default");
}
public:
protected:
rib::Rib rib;
unique_ptr<RibManager> manager;
+3 -4
View File
@@ -31,7 +31,6 @@
#include <ndn-cxx/lp/tags.hpp>
#include <ndn-cxx/mgmt/nfd/face-status.hpp>
#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
#include <boost/property_tree/info_parser.hpp>
@@ -129,8 +128,8 @@ public:
, m_fibUpdater(m_rib, m_nfdController)
, m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher)
{
addIdentity(m_anchorId);
addIdentity(m_derivedId);
m_keyChain.createIdentity(m_anchorId);
m_keyChain.createIdentity(m_derivedId);
m_derivedCert = m_keyChain.getPib().getIdentity(m_derivedId).getDefaultKey().getDefaultCertificate();
ndn::SignatureInfo signatureInfo;
@@ -138,7 +137,7 @@ public:
ndn::security::SigningInfo signingInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
m_anchorId, signatureInfo);
m_keyChain.sign(m_derivedCert, signingInfo);
saveIdentityCertificate(m_anchorId, "signer.ndncert", true);
saveIdentityCert(m_anchorId, "signer.ndncert", true);
if (m_status.isLocalhostConfigured) {
m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test");
+3 -8
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,8 +24,8 @@
*/
#include "tests/daemon/rib-io-fixture.hpp"
#include "tests/test-common.hpp"
#include "common/global.hpp"
#include "tests/boost-test.hpp"
#include <boost/exception/diagnostic_information.hpp>
@@ -122,13 +122,8 @@ RibIoFixture::poll()
} while (nHandlersRun > 0);
}
RibIoTimeFixture::RibIoTimeFixture()
: ClockFixture(g_io)
{
}
void
RibIoTimeFixture::pollAfterClockTick()
RibIoTimeFixture::afterTick()
{
poll();
}
+3 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -79,14 +79,11 @@ private:
/** \brief RibIoFixture that also overrides steady clock and system clock.
*/
class RibIoTimeFixture : public RibIoFixture, public ClockFixture
class RibIoTimeFixture : public ClockFixture, public RibIoFixture
{
protected:
RibIoTimeFixture();
private:
void
pollAfterClockTick() override;
afterTick() final;
};
} // namespace tests
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,8 +29,6 @@
#include "tests/key-chain-fixture.hpp"
#include "tests/daemon/global-io-fixture.hpp"
#include <ndn-cxx/security/signing-helpers.hpp>
namespace nfd {
namespace rib {
namespace tests {
@@ -63,9 +61,9 @@ BOOST_FIXTURE_TEST_SUITE(TestHostToGatewayReadvertisePolicy, HostToGatewayReadve
BOOST_AUTO_TEST_CASE(PrefixToAdvertise)
{
BOOST_REQUIRE(addIdentity("/A"));
BOOST_REQUIRE(addIdentity("/A/B"));
BOOST_REQUIRE(addIdentity("/C/nrd"));
BOOST_REQUIRE(m_keyChain.createIdentity("/A"));
BOOST_REQUIRE(m_keyChain.createIdentity("/A/B"));
BOOST_REQUIRE(m_keyChain.createIdentity("/C/nrd"));
auto test = [this] (Name routeName, optional<ReadvertiseAction> expectedAction) {
auto policy = makePolicy();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -43,7 +43,7 @@ public:
if (envHome)
m_home = envHome;
auto testHome = boost::filesystem::path(UNIT_TEST_CONFIG_PATH) / "test-home";
auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home";
if (::setenv("HOME", testHome.c_str(), 1) != 0)
NDN_THROW(std::runtime_error("setenv() failed"));
+59
View File
@@ -0,0 +1,59 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2020, 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/>.
*/
#ifndef NFD_TESTS_IO_FIXTURE_HPP
#define NFD_TESTS_IO_FIXTURE_HPP
#include "tests/clock-fixture.hpp"
#include <boost/asio/io_service.hpp>
namespace nfd {
namespace tests {
class IoFixture : public ClockFixture
{
private:
void
afterTick() final
{
if (m_io.stopped()) {
#if BOOST_VERSION >= 106600
m_io.restart();
#else
m_io.reset();
#endif
}
m_io.poll();
}
protected:
boost::asio::io_service m_io;
};
} // namespace tests
} // namespace nfd
#endif // NFD_TESTS_IO_FIXTURE_HPP
+50 -40
View File
@@ -25,11 +25,6 @@
#include "tests/key-chain-fixture.hpp"
#include <ndn-cxx/security/certificate.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/util/io.hpp>
#include <boost/filesystem.hpp>
@@ -37,10 +32,11 @@
namespace nfd {
namespace tests {
using namespace ndn::security;
KeyChainFixture::KeyChainFixture()
: m_keyChain("pib-memory:", "tpm-memory:")
{
m_keyChain.createIdentity("/DEFAULT");
}
KeyChainFixture::~KeyChainFixture()
@@ -51,32 +47,33 @@ KeyChainFixture::~KeyChainFixture()
}
}
bool
KeyChainFixture::addIdentity(const Name& identity, const ndn::KeyParams& params)
Certificate
KeyChainFixture::makeCert(const Key& key, const std::string& issuer, const Key& signingKey)
{
try {
m_keyChain.createIdentity(identity, params);
return true;
}
catch (const std::runtime_error&) {
return false;
}
Certificate cert;
cert.setName(Name(key.getName())
.append(issuer)
.appendVersion());
// set metainfo
cert.setContentType(tlv::ContentType_Key);
cert.setFreshnessPeriod(1_h);
// set content
cert.setContent(key.getPublicKey().data(), key.getPublicKey().size());
// set signature info
ndn::SignatureInfo info;
auto now = time::system_clock::now();
info.setValidityPeriod(ValidityPeriod(now - 30_days, now + 30_days));
m_keyChain.sign(cert, signingByKey(signingKey ? signingKey : key).setSignatureInfo(info));
return cert;
}
bool
KeyChainFixture::saveIdentityCertificate(const Name& identity, const std::string& filename, bool allowAdd)
KeyChainFixture::saveCert(const Data& cert, const std::string& filename)
{
ndn::security::Certificate cert;
try {
cert = m_keyChain.getPib().getIdentity(identity).getDefaultKey().getDefaultCertificate();
}
catch (const ndn::security::Pib::Error&) {
if (allowAdd && addIdentity(identity)) {
return saveIdentityCertificate(identity, filename, false);
}
return false;
}
m_certFiles.push_back(filename);
try {
ndn::io::save(cert, filename);
@@ -87,26 +84,39 @@ KeyChainFixture::saveIdentityCertificate(const Name& identity, const std::string
}
}
std::string
KeyChainFixture::getIdentityCertificateBase64(const Name& identity, bool allowAdd)
bool
KeyChainFixture::saveIdentityCert(const Identity& identity, const std::string& filename)
{
ndn::security::Certificate cert;
Certificate cert;
try {
cert = m_keyChain.getPib().getIdentity(identity).getDefaultKey().getDefaultCertificate();
cert = identity.getDefaultKey().getDefaultCertificate();
}
catch (const ndn::security::Pib::Error&) {
if (!allowAdd) {
NDN_THROW_NESTED(std::runtime_error("Identity does not exist"));
catch (const Pib::Error&) {
return false;
}
return saveCert(cert, filename);
}
bool
KeyChainFixture::saveIdentityCert(const Name& identityName, const std::string& filename,
bool allowCreate)
{
Identity id;
try {
id = m_keyChain.getPib().getIdentity(identityName);
}
catch (const Pib::Error&) {
if (allowCreate) {
id = m_keyChain.createIdentity(identityName);
}
cert = m_keyChain.createIdentity(identity).getDefaultKey().getDefaultCertificate();
}
const auto& block = cert.wireEncode();
if (!id) {
return false;
}
namespace tr = ndn::security::transform;
std::ostringstream oss;
tr::bufferSource(block.wire(), block.size()) >> tr::base64Encode(false) >> tr::streamSink(oss);
return oss.str();
return saveIdentityCert(id, filename);
}
} // namespace tests
+39 -20
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,44 +29,63 @@
#include "core/common.hpp"
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
namespace nfd {
namespace tests {
/** \brief A fixture providing an in-memory KeyChain.
/**
* @brief A fixture providing an in-memory KeyChain.
*
* Test cases can use this fixture to create identities. Identities, certificates, and
* saved certificates are automatically removed during test teardown.
*/
class KeyChainFixture
{
protected:
using Certificate = ndn::security::Certificate;
using Identity = ndn::security::Identity;
using Key = ndn::security::Key;
public:
/** \brief add identity
* \return whether successful
/**
* @brief Creates and returns a certificate for a given key
* @param key The key for which to make a certificate
* @param issuer The IssuerId to include in the certificate name
* @param signingKey The key with which to sign the certificate; if not provided, the
* certificate will be self-signed
*/
Certificate
makeCert(const Key& key, const std::string& issuer, const Key& signingKey = Key());
/**
* @brief Saves an NDN certificate to a file
* @return true if successful, false otherwise
*/
bool
addIdentity(const Name& identity,
const ndn::KeyParams& params = ndn::KeyChain::getDefaultKeyParams());
saveCert(const Data& cert, const std::string& filename);
/** \brief save identity certificate to a file
* \param identity identity name
* \param filename file name, must be writable
* \param allowAdd if true, add new identity when necessary
* \return whether successful
/**
* @brief Saves the default certificate of @p identity to a file
* @return true if successful, false otherwise
*/
bool
saveIdentityCertificate(const Name& identity, const std::string& filename, bool allowAdd = false);
saveIdentityCert(const Identity& identity, const std::string& filename);
/** \brief retrieve identity certificate as base64 string
* \param identity identity name
* \param allowAdd if true, add new identity when necessary
* \throw std::runtime_error identity does not exist and \p allowAdd is false
/**
* @brief Saves the default certificate of the identity named @p identityName to a file
* @param identityName Name of the identity
* @param filename File name, must be writable
* @param allowCreate If true, create the identity if it does not exist
* @return true if successful, false otherwise
*/
std::string
getIdentityCertificateBase64(const Name& identity, bool allowAdd = false);
bool
saveIdentityCert(const Name& identityName, const std::string& filename,
bool allowCreate = false);
protected:
KeyChainFixture();
/** \brief deletes saved certificate files
*/
~KeyChainFixture();
protected:
+1 -2
View File
@@ -37,8 +37,7 @@ def build(bld):
bld.program(name=module,
target='../../%s' % module,
source=bld.path.ant_glob('%s*.cpp' % module),
use='daemon-objects tests-common other-tests-%s-main' % module,
defines=['UNIT_TEST_CONFIG_PATH="%s"' % bld.bldnode.make_node('tmp-files')],
use='daemon-objects other-tests-%s-main' % module,
install_path=None)
# face-benchmark does not rely on Boost.Test
+1 -1
View File
@@ -58,7 +58,7 @@ makeInterest(const Name& name, bool canBePrefix = false,
/**
* \brief Create a Data with a null (i.e., empty) signature
*
* If a real signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
* If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
*/
shared_ptr<Data>
makeData(const Name& name);
+4 -8
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,7 @@
#ifndef NFD_TESTS_TOOLS_MOCK_NFD_MGMT_FIXTURE_HPP
#define NFD_TESTS_TOOLS_MOCK_NFD_MGMT_FIXTURE_HPP
#include "tests/clock-fixture.hpp"
#include "tests/io-fixture.hpp"
#include "tests/key-chain-fixture.hpp"
#include "tests/test-common.hpp"
@@ -45,12 +45,11 @@ using ndn::nfd::ControlParameters;
/** \brief Fixture to emulate NFD management.
*/
class MockNfdMgmtFixture : public ClockFixture, public KeyChainFixture
class MockNfdMgmtFixture : public IoFixture, public KeyChainFixture
{
protected:
MockNfdMgmtFixture()
: ClockFixture(m_io)
, face(m_io, m_keyChain,
: face(m_io, m_keyChain,
{true, false, bind(&MockNfdMgmtFixture::processEventsOverride, this, _1)})
{
face.onSendInterest.connect([this] (const Interest& interest) {
@@ -206,9 +205,6 @@ private:
signData(data);
}
private:
boost::asio::io_service m_io;
protected:
ndn::util::DummyClientFace face;
std::function<void(const Interest&)> processInterest;
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,8 +27,6 @@
#include "status-fixture.hpp"
#include <ndn-cxx/security/signing-helpers.hpp>
namespace nfd {
namespace tools {
namespace nfdc {
+4 -10
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -120,12 +120,11 @@ public:
std::function<void()> processEventsFunc;
};
class StatusReportModulesFixture : public ClockFixture, public KeyChainFixture
class StatusReportModulesFixture : public IoFixture, public KeyChainFixture
{
protected:
StatusReportModulesFixture()
: ClockFixture(m_io)
, face(m_io, m_keyChain)
: face(m_io, m_keyChain)
, controller(face, m_keyChain, validator)
, res(0)
{
@@ -141,9 +140,7 @@ protected:
void
collect(time::nanoseconds tick, size_t nTicks)
{
report.processEventsFunc = [=] {
this->advanceClocks(tick, nTicks);
};
report.processEventsFunc = [=] { advanceClocks(tick, nTicks); };
res = report.collect(face, m_keyChain, validator, CommandOptions());
if (res == 0) {
@@ -154,9 +151,6 @@ protected:
}
}
private:
boost::asio::io_service m_io;
protected:
ndn::util::DummyClientFace face;
ValidatorNull validator;
+3 -3
View File
@@ -28,7 +28,7 @@ top = '..'
def build(bld):
# Unit tests
if bld.env.WITH_TESTS:
config_path = 'UNIT_TEST_CONFIG_PATH="%s"' % bld.bldnode.make_node('tmp-files')
tmpdir = 'UNIT_TESTS_TMPDIR="%s"' % bld.bldnode.make_node('tmp-files')
# common test objects
bld.objects(
@@ -37,7 +37,7 @@ def build(bld):
source=bld.path.ant_glob('*.cpp', excl='main.cpp'),
use='core-objects',
headers='../core/common.hpp boost-test.hpp',
defines=[config_path])
defines=[tmpdir])
for module in ['core', 'daemon', 'rib', 'tools']:
# main() for the module
@@ -70,7 +70,7 @@ def build(bld):
target='../unit-tests-%s' % module,
source=src,
use='%s-objects tests-common unit-tests-%s-main' % (objmod, module),
defines=[config_path],
defines=[tmpdir],
install_path=None)
# Other tests (e.g., stress tests and benchmarks that can be enabled even if unit tests are disabled)