tests: use decorators to label test data generators
Also various minor cleanups
Change-Id: Iaee434991b923abdf464293fec35da22d6cb449a
diff --git a/tests/unit/encoding/block.t.cpp b/tests/unit/encoding/block.t.cpp
index b4f2cf8..8c15e51 100644
--- a/tests/unit/encoding/block.t.cpp
+++ b/tests/unit/encoding/block.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -256,7 +256,8 @@
});
}
-BOOST_AUTO_TEST_CASE(FromStreamWhitespace) // Bug 2728
+BOOST_AUTO_TEST_CASE(FromStreamWhitespace,
+ * ut::description("test for bug #2728"))
{
const uint8_t PACKET[] = {
0x06, 0x20, // Data
diff --git a/tests/unit/encoding/buffer-stream.t.cpp b/tests/unit/encoding/buffer-stream.t.cpp
index e505c3d..478bdd8 100644
--- a/tests/unit/encoding/buffer-stream.t.cpp
+++ b/tests/unit/encoding/buffer-stream.t.cpp
@@ -59,7 +59,8 @@
BOOST_CHECK_EQUAL(buf->at(1), 0x22);
}
-BOOST_AUTO_TEST_CASE(Destructor) // Bug 3727
+BOOST_AUTO_TEST_CASE(Destructor,
+ * ut::description("test for bug #3727"))
{
auto os = std::make_unique<OBufferStream>();
auto buf = os->buf();
@@ -70,7 +71,8 @@
BOOST_CHECK_EQUAL(buf->size(), 1);
}
-BOOST_AUTO_TEST_CASE(Close) // Bug 5240
+BOOST_AUTO_TEST_CASE(Close,
+ * ut::description("test for bug #5240"))
{
OBufferStream os;
os << "foo";
diff --git a/tests/unit/encoding/nfd-constants.t.cpp b/tests/unit/encoding/nfd-constants.t.cpp
index 6821c44..fc051c4 100644
--- a/tests/unit/encoding/nfd-constants.t.cpp
+++ b/tests/unit/encoding/nfd-constants.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -73,25 +73,25 @@
BOOST_AUTO_TEST_CASE(ParseRouteOrigin)
{
auto expectSuccess = [] (const std::string& input, RouteOrigin expected) {
- BOOST_TEST_CONTEXT("input = " << std::quoted(input)) {
- std::istringstream is(input);
- RouteOrigin routeOrigin;
- is >> routeOrigin;
+ BOOST_TEST_INFO_SCOPE("input = " << std::quoted(input));
- BOOST_CHECK(!is.fail());
- BOOST_CHECK_EQUAL(routeOrigin, expected);
- }
+ std::istringstream is(input);
+ RouteOrigin routeOrigin;
+ is >> routeOrigin;
+
+ BOOST_CHECK(!is.fail());
+ BOOST_CHECK_EQUAL(routeOrigin, expected);
};
auto expectFail = [] (const std::string& input) {
- BOOST_TEST_CONTEXT("input = " << std::quoted(input)) {
- std::istringstream is(input);
- RouteOrigin routeOrigin;
- is >> routeOrigin;
+ BOOST_TEST_INFO_SCOPE("input = " << std::quoted(input));
- BOOST_CHECK(is.fail());
- BOOST_CHECK_EQUAL(routeOrigin, ROUTE_ORIGIN_NONE);
- }
+ std::istringstream is(input);
+ RouteOrigin routeOrigin;
+ is >> routeOrigin;
+
+ BOOST_CHECK(is.fail());
+ BOOST_CHECK_EQUAL(routeOrigin, ROUTE_ORIGIN_NONE);
};
expectSuccess("none", ROUTE_ORIGIN_NONE);
@@ -133,10 +133,10 @@
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAGS_NONE), "none");
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CHILD_INHERIT), "child-inherit");
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CAPTURE), "capture");
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>(
- ROUTE_FLAG_CHILD_INHERIT | ROUTE_FLAG_CAPTURE)), "child-inherit|capture");
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>(
- ROUTE_FLAG_CAPTURE | 0x9c)), "capture|0x9c");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(
+ static_cast<RouteFlags>(ROUTE_FLAG_CHILD_INHERIT | ROUTE_FLAG_CAPTURE)), "child-inherit|capture");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(
+ static_cast<RouteFlags>(ROUTE_FLAG_CAPTURE | 0x9c)), "capture|0x9c");
}
BOOST_AUTO_TEST_SUITE_END() // TestNfdConstants
diff --git a/tests/unit/face.t.cpp b/tests/unit/face.t.cpp
index 55d8245..7324b1c 100644
--- a/tests/unit/face.t.cpp
+++ b/tests/unit/face.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -255,7 +255,8 @@
} while (false));
}
-BOOST_AUTO_TEST_CASE(PutDataFromDataCallback) // Bug 4596
+BOOST_AUTO_TEST_CASE(PutDataFromDataCallback,
+ * ut::description("test for bug #4596"))
{
face.expressInterest(*makeInterest("/localhost/notification/1"),
[&] (auto&&...) {
@@ -272,7 +273,8 @@
BOOST_CHECK_EQUAL(face.sentData.back().getName(), "/chronosync/sampleDigest/1");
}
-BOOST_AUTO_TEST_CASE(DestroyWithPendingInterest)
+BOOST_AUTO_TEST_CASE(DestroyWithPendingInterest,
+ * ut::description("test for bug #2518"))
{
auto face2 = make_unique<DummyClientFace>(m_io, m_keyChain);
face2->expressInterest(*makeInterest("/Hello/World", false, 50_ms),
@@ -280,7 +282,7 @@
advanceClocks(50_ms, 2);
face2.reset();
- advanceClocks(50_ms, 2); // should not crash - Bug 2518
+ advanceClocks(50_ms, 2); // should not crash
// avoid "test case [...] did not check any assertions" message from Boost.Test
BOOST_CHECK(true);
@@ -779,7 +781,8 @@
BOOST_CHECK_EQUAL(nInInterests, 2);
}
-BOOST_FIXTURE_TEST_CASE(WithoutRegisterPrefix, FaceFixture<NoPrefixRegReply>) // Bug 2318
+BOOST_FIXTURE_TEST_CASE(WithoutRegisterPrefix, FaceFixture<NoPrefixRegReply>,
+ * ut::description("test for bug #2318"))
{
// This behavior is specific to DummyClientFace.
// Regular Face won't accept incoming packets until something is sent.
@@ -840,7 +843,8 @@
BOOST_CHECK_EQUAL(nRegSuccesses, 1);
}
-BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents) // Bug 3248
+BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents,
+ * ut::description("test for bug #3248"))
{
auto face2 = make_unique<Face>(m_io);
face2.reset();
diff --git a/tests/unit/ims/in-memory-storage-fifo.t.cpp b/tests/unit/ims/in-memory-storage-fifo.t.cpp
index 632a566..03233aa 100644
--- a/tests/unit/ims/in-memory-storage-fifo.t.cpp
+++ b/tests/unit/ims/in-memory-storage-fifo.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -69,14 +69,15 @@
BOOST_CHECK(found2 == nullptr);
}
-BOOST_AUTO_TEST_CASE(MemoryPoolSizeZeroBug) // Bug #4769
+BOOST_AUTO_TEST_CASE(MemoryPoolSizeZero,
+ * ut::description("test for bug #4769"))
{
InMemoryStorageFifo ims;
BOOST_CHECK_EQUAL(ims.getCapacity(), 16);
for (int i = 1; i < 5; ++i) {
- ims.insert(*makeData(to_string(i)));
- ims.erase(Name(to_string(i)));
+ ims.insert(*makeData(std::to_string(i)));
+ ims.erase(Name(std::to_string(i)));
}
BOOST_CHECK_EQUAL(ims.getCapacity(), 16);
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index 73b7bef..c67bd0e 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -686,7 +686,7 @@
}
BOOST_AUTO_TEST_CASE(MatchesInterest,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
Interest interest;
interest.setName("/A")
diff --git a/tests/unit/mgmt/dispatcher.t.cpp b/tests/unit/mgmt/dispatcher.t.cpp
index 1e1c947..9087179 100644
--- a/tests/unit/mgmt/dispatcher.t.cpp
+++ b/tests/unit/mgmt/dispatcher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -262,7 +262,8 @@
int m_state = 0;
};
-BOOST_AUTO_TEST_CASE(ControlCommandAsyncAuthorization) // Bug 4059
+BOOST_AUTO_TEST_CASE(ControlCommandAsyncAuthorization,
+ * ut::description("test for bug #4059"))
{
AcceptContinuation authorizationAccept;
auto authorization =
diff --git a/tests/unit/name-component.t.cpp b/tests/unit/name-component.t.cpp
index 73a423b..840bccd 100644
--- a/tests/unit/name-component.t.cpp
+++ b/tests/unit/name-component.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -341,8 +341,6 @@
BOOST_AUTO_TEST_SUITE_END() // ConstructFromIterators
-BOOST_AUTO_TEST_SUITE(NamingConvention)
-
template<typename ArgType>
struct ConventionTest
{
@@ -354,9 +352,8 @@
std::function<bool(const Component&)> isComponent;
};
-class ConventionMarker
+struct ConventionMarker
{
-public:
ConventionMarker()
{
name::setConventionEncoding(name::Convention::MARKER);
@@ -368,13 +365,12 @@
}
};
-class ConventionTyped
+struct ConventionTyped
{
};
-class NumberWithMarker
+struct NumberWithMarker
{
-public:
using ConventionRev = ConventionMarker;
ConventionTest<uint64_t>
@@ -389,9 +385,8 @@
}
};
-class SegmentMarker
+struct SegmentMarker
{
-public:
using ConventionRev = ConventionMarker;
ConventionTest<uint64_t>
@@ -406,9 +401,8 @@
}
};
-class SegmentTyped
+struct SegmentTyped
{
-public:
using ConventionRev = ConventionTyped;
ConventionTest<uint64_t>
@@ -423,9 +417,8 @@
}
};
-class ByteOffsetTyped
+struct ByteOffsetTyped
{
-public:
using ConventionRev = ConventionTyped;
ConventionTest<uint64_t>
@@ -440,9 +433,8 @@
}
};
-class VersionMarker
+struct VersionMarker
{
-public:
using ConventionRev = ConventionMarker;
ConventionTest<uint64_t>
@@ -457,9 +449,8 @@
}
};
-class VersionTyped
+struct VersionTyped
{
-public:
using ConventionRev = ConventionTyped;
ConventionTest<uint64_t>
@@ -474,9 +465,8 @@
}
};
-class TimestampMarker
+struct TimestampMarker
{
-public:
using ConventionRev = ConventionMarker;
ConventionTest<time::system_clock::time_point>
@@ -491,9 +481,8 @@
}
};
-class TimestampTyped
+struct TimestampTyped
{
-public:
using ConventionRev = ConventionTyped;
ConventionTest<time::system_clock::time_point>
@@ -508,9 +497,8 @@
}
};
-class SequenceNumberMarker
+struct SequenceNumberMarker
{
-public:
using ConventionRev = ConventionMarker;
ConventionTest<uint64_t>
@@ -525,9 +513,8 @@
}
};
-class SequenceNumberTyped
+struct SequenceNumberTyped
{
-public:
using ConventionRev = ConventionTyped;
ConventionTest<uint64_t>
@@ -542,7 +529,7 @@
}
};
-using ConventionTests = boost::mp11::mp_list<
+using NamingConventionTests = boost::mp11::mp_list<
NumberWithMarker,
SegmentMarker,
SegmentTyped,
@@ -555,23 +542,22 @@
SequenceNumberTyped
>;
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(Convention, T, ConventionTests, T::ConventionRev)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(NamingConvention, T, NamingConventionTests, T::ConventionRev)
{
- Component invalidComponent1;
- Component invalidComponent2("1234567890");
-
auto test = T()();
- const Name& expected = test.expected;
Component actualComponent = test.makeComponent(test.value);
- BOOST_CHECK_EQUAL(actualComponent, expected[0]);
+ BOOST_CHECK_EQUAL(actualComponent, test.expected[0]);
Name actualName;
test.append(actualName, test.value);
- BOOST_CHECK_EQUAL(actualName, expected);
+ BOOST_CHECK_EQUAL(actualName, test.expected);
- BOOST_CHECK_EQUAL(test.isComponent(expected[0]), true);
- BOOST_CHECK_EQUAL(test.getValue(expected[0]), test.value);
+ BOOST_CHECK_EQUAL(test.isComponent(test.expected[0]), true);
+ BOOST_CHECK_EQUAL(test.getValue(test.expected[0]), test.value);
+
+ static const Component invalidComponent1;
+ static const Component invalidComponent2("1234567890");
BOOST_CHECK_EQUAL(test.isComponent(invalidComponent1), false);
BOOST_CHECK_EQUAL(test.isComponent(invalidComponent2), false);
@@ -580,8 +566,6 @@
BOOST_CHECK_THROW(test.getValue(invalidComponent2), Component::Error);
}
-BOOST_AUTO_TEST_SUITE_END() // NamingConvention
-
BOOST_AUTO_TEST_CASE(Compare)
{
const std::vector<Component> comps = {
@@ -609,6 +593,8 @@
for (size_t j = 0; j < comps.size(); ++j) {
const auto& lhs = comps[i];
const auto& rhs = comps[j];
+ BOOST_TEST_INFO_SCOPE("lhs = " << lhs);
+ BOOST_TEST_INFO_SCOPE("rhs = " << rhs);
BOOST_CHECK_EQUAL(lhs == rhs, i == j);
BOOST_CHECK_EQUAL(lhs != rhs, i != j);
BOOST_CHECK_EQUAL(lhs < rhs, i < j);
diff --git a/tests/unit/net/face-uri.t.cpp b/tests/unit/net/face-uri.t.cpp
index 170e498..f306a94 100644
--- a/tests/unit/net/face-uri.t.cpp
+++ b/tests/unit/net/face-uri.t.cpp
@@ -65,29 +65,29 @@
void
runTest(const std::string& request, bool shouldSucceed, const std::string& expectedUri = "")
{
- BOOST_TEST_CONTEXT(std::quoted(request) << " should " << (shouldSucceed ? "succeed" : "fail")) {
- bool didInvokeCb = false;
- FaceUri uri(request);
- uri.canonize(
- [&] (const FaceUri& canonicalUri) {
- BOOST_CHECK_EQUAL(didInvokeCb, false);
- didInvokeCb = true;
- BOOST_CHECK_EQUAL(shouldSucceed, true);
- if (shouldSucceed) {
- BOOST_CHECK_EQUAL(canonicalUri.toString(), expectedUri);
- }
- },
- [&] (const std::string&) {
- BOOST_CHECK_EQUAL(didInvokeCb, false);
- didInvokeCb = true;
- BOOST_CHECK_EQUAL(shouldSucceed, false);
- },
- m_io, 30_s);
+ BOOST_TEST_INFO_SCOPE(std::quoted(request) << " should " << (shouldSucceed ? "succeed" : "fail"));
- m_io.run();
- BOOST_CHECK_EQUAL(didInvokeCb, true);
- m_io.restart();
- }
+ bool didInvokeCb = false;
+ FaceUri uri(request);
+ uri.canonize(
+ [&] (const FaceUri& canonicalUri) {
+ BOOST_CHECK_EQUAL(didInvokeCb, false);
+ didInvokeCb = true;
+ BOOST_CHECK_EQUAL(shouldSucceed, true);
+ if (shouldSucceed) {
+ BOOST_CHECK_EQUAL(canonicalUri.toString(), expectedUri);
+ }
+ },
+ [&] (const std::string&) {
+ BOOST_CHECK_EQUAL(didInvokeCb, false);
+ didInvokeCb = true;
+ BOOST_CHECK_EQUAL(shouldSucceed, false);
+ },
+ m_io, 30_s);
+
+ m_io.run();
+ BOOST_CHECK_EQUAL(didInvokeCb, true);
+ m_io.restart();
}
protected:
@@ -208,7 +208,7 @@
}
BOOST_FIXTURE_TEST_CASE(CanonizeUdpV4, CanonizeFixture,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
SKIP_IF_IPV4_UNAVAILABLE();
@@ -236,7 +236,7 @@
}
BOOST_FIXTURE_TEST_CASE(CanonizeUdpV6, CanonizeFixture,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
SKIP_IF_IPV6_UNAVAILABLE();
@@ -338,7 +338,7 @@
}
BOOST_FIXTURE_TEST_CASE(CanonizeTcpV4, CanonizeFixture,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
SKIP_IF_IPV4_UNAVAILABLE();
@@ -377,7 +377,7 @@
}
BOOST_FIXTURE_TEST_CASE(CanonizeTcpV6, CanonizeFixture,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
SKIP_IF_IPV6_UNAVAILABLE();
@@ -401,7 +401,7 @@
}
BOOST_AUTO_TEST_CASE(ParseUnix,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
FaceUri uri;
@@ -470,7 +470,7 @@
}
BOOST_AUTO_TEST_CASE(ParseDev,
- * boost::unit_test::expected_failures(1))
+ * ut::expected_failures(1))
{
FaceUri uri;
@@ -591,7 +591,8 @@
runTest("fd://0", false);
}
-BOOST_AUTO_TEST_CASE(Bug1635)
+BOOST_AUTO_TEST_CASE(Ipv4MappedIpv6Address,
+ * ut::description("test for bug #1635"))
{
FaceUri uri;
diff --git a/tests/unit/security/certificate-cache.t.cpp b/tests/unit/security/certificate-cache.t.cpp
index acbdd00..0a00adf 100644
--- a/tests/unit/security/certificate-cache.t.cpp
+++ b/tests/unit/security/certificate-cache.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -31,31 +31,31 @@
{
public:
CertificateCacheFixture()
- : certCache(10_s)
{
identity = m_keyChain.createIdentity("/TestCertificateCache");
cert = identity.getDefaultKey().getDefaultCertificate();
}
void
- checkFindByInterest(const Name& name, bool canBePrefix, std::optional<Certificate> expected) const
+ checkFindByInterest(const Name& name, bool canBePrefix,
+ const std::optional<Certificate>& expected) const
{
Interest interest(name);
interest.setCanBePrefix(canBePrefix);
- BOOST_TEST_CONTEXT(interest) {
- auto found = certCache.find(interest);
- if (expected) {
- BOOST_REQUIRE(found != nullptr);
- BOOST_CHECK_EQUAL(found->getName(), expected->getName());
- }
- else {
- BOOST_CHECK(found == nullptr);
- }
+ BOOST_TEST_INFO_SCOPE("Interest = " << interest);
+
+ auto found = certCache.find(interest);
+ if (expected) {
+ BOOST_REQUIRE(found != nullptr);
+ BOOST_CHECK_EQUAL(found->getName(), expected->getName());
+ }
+ else {
+ BOOST_CHECK(found == nullptr);
}
}
public:
- security::CertificateCache certCache;
+ security::CertificateCache certCache{10_s};
Identity identity;
Certificate cert;
};
diff --git a/tests/unit/security/certificate-fetcher-direct-fetch.t.cpp b/tests/unit/security/certificate-fetcher-direct-fetch.t.cpp
index ca185c6..eb77031 100644
--- a/tests/unit/security/certificate-fetcher-direct-fetch.t.cpp
+++ b/tests/unit/security/certificate-fetcher-direct-fetch.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -39,8 +39,8 @@
BOOST_AUTO_TEST_SUITE(TestCertificateFetcherDirectFetch)
struct Cert {};
-struct Timeout {};
struct Nack {};
+struct Timeout {};
template<class Response>
class CertificateFetcherDirectFetchFixture : public HierarchicalValidatorFixture<ValidationPolicySimpleHierarchy,
@@ -53,7 +53,6 @@
BOTH
};
-public:
CertificateFetcherDirectFetchFixture()
: data("/Security/ValidatorFixture/Sub1/Sub3/Data")
, interest("/Security/ValidatorFixture/Sub1/Sub3/Interest")
@@ -85,7 +84,22 @@
}
void
- makeResponse(const Interest& interest);
+ makeResponse(const Interest& interest)
+ {
+ if constexpr (std::is_same_v<Response, Cert>) {
+ auto cert = cache.find(interest);
+ if (cert == nullptr) {
+ return;
+ }
+ face.receive(*cert);
+ }
+ else if constexpr (std::is_same_v<Response, Nack>) {
+ face.receive(makeNack(interest, lp::NackReason::NO_ROUTE));
+ }
+ else {
+ // do nothing
+ }
+ }
void
setResponseType(ResponseType type)
@@ -100,32 +114,7 @@
ResponseType responseType = ResponseType::INFRASTRUCTURE;
};
-template<>
-void
-CertificateFetcherDirectFetchFixture<Cert>::makeResponse(const Interest& interest)
-{
- auto cert = cache.find(interest);
- if (cert == nullptr) {
- return;
- }
- face.receive(*cert);
-}
-
-template<>
-void
-CertificateFetcherDirectFetchFixture<Timeout>::makeResponse(const Interest& interest)
-{
- // do nothing
-}
-
-template<>
-void
-CertificateFetcherDirectFetchFixture<Nack>::makeResponse(const Interest& interest)
-{
- face.receive(makeNack(interest, lp::NackReason::NO_ROUTE));
-}
-
-using Failures = boost::mp11::mp_list<Timeout, Nack>;
+using FailureModes = boost::mp11::mp_list<Nack, Timeout>;
BOOST_FIXTURE_TEST_CASE(ValidateSuccessData, CertificateFetcherDirectFetchFixture<Cert>)
{
@@ -158,7 +147,8 @@
}
}
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureData, T, Failures, CertificateFetcherDirectFetchFixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureData, T, FailureModes,
+ CertificateFetcherDirectFetchFixture<T>)
{
VALIDATE_FAILURE(this->data, "Should fail, as all interests either NACKed or timeout");
BOOST_TEST(this->lastError.getCode() == ValidationError::CANNOT_RETRIEVE_CERT);
@@ -179,7 +169,8 @@
}
}
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureDataDirectOnly, T, Failures, CertificateFetcherDirectFetchFixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureDataDirectOnly, T, FailureModes,
+ CertificateFetcherDirectFetchFixture<T>)
{
this->setResponseType(CertificateFetcherDirectFetchFixture<T>::ResponseType::DIRECT);
static_cast<CertificateFetcherDirectFetch&>(this->validator.getFetcher()).setSendDirectInterestOnly(true);
@@ -195,7 +186,8 @@
}
}
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureDataNoTagDirectOnly, T, Failures, CertificateFetcherDirectFetchFixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureDataNoTagDirectOnly, T, FailureModes,
+ CertificateFetcherDirectFetchFixture<T>)
{
this->setResponseType(CertificateFetcherDirectFetchFixture<T>::ResponseType::DIRECT);
static_cast<CertificateFetcherDirectFetch&>(this->validator.getFetcher()).setSendDirectInterestOnly(true);
@@ -226,7 +218,8 @@
}
}
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureInterest, T, Failures, CertificateFetcherDirectFetchFixture<T>)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateFailureInterest, T, FailureModes,
+ CertificateFetcherDirectFetchFixture<T>)
{
VALIDATE_FAILURE(this->interest, "Should fail, as all interests either NACKed or timeout");
BOOST_TEST(this->lastError.getCode() == ValidationError::CANNOT_RETRIEVE_CERT);
diff --git a/tests/unit/security/key-chain.t.cpp b/tests/unit/security/key-chain.t.cpp
index ac45ee7..4fd91b4 100644
--- a/tests/unit/security/key-chain.t.cpp
+++ b/tests/unit/security/key-chain.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -158,7 +158,8 @@
static constexpr std::string_view PATH = "build/config-file-non-canonical-tpm/";
};
-BOOST_FIXTURE_TEST_CASE(ConstructorNonCanonicalTpm, TestHomeAndPibFixture<PibPathConfigFileNonCanonicalTpm>) // Bug 4297
+BOOST_FIXTURE_TEST_CASE(ConstructorNonCanonicalTpm, TestHomeAndPibFixture<PibPathConfigFileNonCanonicalTpm>,
+ * ut::description("test for bug #4297"))
{
createClientConf({"pib=pib-sqlite3:", "tpm=tpm-file"});
@@ -328,7 +329,7 @@
struct DataPkt
{
Data packet{"/data"};
- SignedInterestFormat sigFormat = SignedInterestFormat::V02; // irrelevant for Data
+ static constexpr SignedInterestFormat sigFormat = SignedInterestFormat::V02; // irrelevant for Data
SignatureInfo
getSignatureInfo() const
@@ -340,7 +341,7 @@
struct InterestV02Pkt
{
Interest packet{"/interest02"};
- SignedInterestFormat sigFormat = SignedInterestFormat::V02;
+ static constexpr SignedInterestFormat sigFormat = SignedInterestFormat::V02;
SignatureInfo
getSignatureInfo() const
@@ -352,7 +353,7 @@
struct InterestV03Pkt
{
Interest packet{"/interest03"};
- SignedInterestFormat sigFormat = SignedInterestFormat::V03;
+ static constexpr SignedInterestFormat sigFormat = SignedInterestFormat::V03;
SignatureInfo
getSignatureInfo() const
@@ -421,8 +422,8 @@
const Key key = KeyMaker<AsymmetricKeyParams>()(m_keyChain, id);
const Certificate cert = key.getDefaultCertificate();
- const uint32_t expectedSigType = SignatureTypeTlvValue;
- const bool shouldHaveKeyLocator = true;
+ static constexpr uint32_t expectedSigType = SignatureTypeTlvValue;
+ static constexpr bool shouldHaveKeyLocator = true;
const std::optional<KeyLocator> expectedKeyLocator = cert.getName();
bool
@@ -498,8 +499,8 @@
SigningInfo("hmac-sha256:QjM3NEEyNkE3MTQ5MDQzN0FBMDI0RTRGQURENUI0OTdGREZGMUE4RUE2RkYxMkY2RkI2NUFGMjcyMEI1OUNDRg=="),
};
- const uint32_t expectedSigType = SignatureTypeTlvValue;
- const bool shouldHaveKeyLocator = true;
+ static constexpr uint32_t expectedSigType = SignatureTypeTlvValue;
+ static constexpr bool shouldHaveKeyLocator = true;
const std::optional<KeyLocator> expectedKeyLocator = std::nullopt; // don't check KeyLocator value
bool
@@ -518,8 +519,8 @@
signingWithSha256()
};
- const uint32_t expectedSigType = tlv::DigestSha256;
- const bool shouldHaveKeyLocator = false;
+ static constexpr uint32_t expectedSigType = tlv::DigestSha256;
+ static constexpr bool shouldHaveKeyLocator = false;
const std::optional<KeyLocator> expectedKeyLocator = std::nullopt;
bool
@@ -550,22 +551,21 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(SigningInterface, T, SigningTests, T)
{
- BOOST_TEST_CONTEXT("Packet = " << this->packet.getName()) {
- for (auto signingInfo : this->signingInfos) {
- signingInfo.setSignedInterestFormat(this->sigFormat);
+ BOOST_TEST_INFO_SCOPE("Packet = " << this->packet.getName());
- BOOST_TEST_CONTEXT("SigningInfo = " << signingInfo) {
- this->m_keyChain.sign(this->packet, signingInfo);
+ for (auto signingInfo : this->signingInfos) {
+ signingInfo.setSignedInterestFormat(this->sigFormat);
+ BOOST_TEST_INFO_SCOPE("SigningInfo = " << signingInfo);
- auto sigInfo = this->getSignatureInfo();
- BOOST_CHECK_EQUAL(sigInfo.getSignatureType(), this->expectedSigType);
- BOOST_CHECK_EQUAL(sigInfo.hasKeyLocator(), this->shouldHaveKeyLocator);
- if (this->expectedKeyLocator) {
- BOOST_CHECK_EQUAL(sigInfo.getKeyLocator(), *this->expectedKeyLocator);
- }
- BOOST_CHECK(this->verify(signingInfo));
- }
+ this->m_keyChain.sign(this->packet, signingInfo);
+
+ auto sigInfo = this->getSignatureInfo();
+ BOOST_CHECK_EQUAL(sigInfo.getSignatureType(), this->expectedSigType);
+ BOOST_CHECK_EQUAL(sigInfo.hasKeyLocator(), this->shouldHaveKeyLocator);
+ if (this->expectedKeyLocator) {
+ BOOST_CHECK_EQUAL(sigInfo.getKeyLocator(), *this->expectedKeyLocator);
}
+ BOOST_CHECK(this->verify(signingInfo));
}
}
diff --git a/tests/unit/security/pib/pib-data-fixture.cpp b/tests/unit/security/pib/pib-data-fixture.cpp
index dde1d8b..7196daa 100644
--- a/tests/unit/security/pib/pib-data-fixture.cpp
+++ b/tests/unit/security/pib/pib-data-fixture.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,91 +20,96 @@
*/
#include "tests/unit/security/pib/pib-data-fixture.hpp"
+
#include "ndn-cxx/security/pib/impl/pib-memory.hpp"
+#include "ndn-cxx/security/tpm/impl/back-end-mem.hpp"
+#include "ndn-cxx/security/tpm/tpm.hpp"
+#include "ndn-cxx/util/string-helper.hpp"
-// #include "ndn-cxx/security/tpm/impl/back-end-mem.hpp"
-// #include "ndn-cxx/security/tpm/tpm.hpp"
-// #include "ndn-cxx/util/string-helper.hpp"
+#include "tests/boost-test.hpp"
-// #include "tests/boost-test.hpp"
-
-// #include <iostream>
+#include <iostream>
namespace ndn::tests {
using namespace ndn::security;
-using namespace ndn::security::pib;
-// class TestCertDataGenerator
-// {
-// public:
-// void
-// printTestDataForId(const std::string& prefix, const Name& id)
-// {
-// for (auto keyId : {1u, 2u}) {
-// Name keyName = tpm.createKey(id, EcKeyParams(name::Component::fromNumber(keyId)));
+BOOST_AUTO_TEST_SUITE(Security)
+BOOST_AUTO_TEST_SUITE(PibData)
-// for (auto certVersion : {1u, 2u}) {
-// Name certName = keyName;
-// certName
-// .append("issuer")
-// .appendVersion(certVersion);
-// Certificate cert;
-// cert.setName(certName);
-// cert.setFreshnessPeriod(1_h);
-// cert.setContent(tpm.getPublicKey(keyName));
+class TestCertDataGenerator
+{
+public:
+ void
+ printTestDataForId(const std::string& prefix, const Name& id)
+ {
+ for (auto keyId : {1u, 2u}) {
+ Name keyName = m_tpm.createKey(id, EcKeyParams(name::Component::fromNumber(keyId)));
-// // TODO: sign using KeyChain
-// SignatureInfo info;
-// info.setSignatureType(tlv::SignatureSha256WithEcdsa);
-// info.setKeyLocator(keyName);
-// info.setValidityPeriod(ValidityPeriod(time::fromIsoString("20170102T000000"),
-// time::fromIsoString("20180102T000000")));
-// cert.setSignatureInfo(info);
+ for (auto certVersion : {1u, 2u}) {
+ Name certName = keyName;
+ certName.append("issuer");
+ certName.appendVersion(certVersion);
+ Certificate cert;
+ cert.setName(certName);
+ cert.setFreshnessPeriod(1_h);
+ cert.setContent(m_tpm.getPublicKey(keyName));
-// EncodingBuffer buf;
-// cert.wireEncode(buf, true);
-// cert.setSignatureValue(tpm.sign({buf}, keyName, DigestAlgorithm::SHA256));
+ // TODO: sign using KeyChain
+ SignatureInfo info;
+ info.setSignatureType(tlv::SignatureSha256WithEcdsa);
+ info.setKeyLocator(keyName);
+ info.setValidityPeriod(ValidityPeriod(time::fromIsoString("20170102T000000"),
+ time::fromIsoString("20180102T000000")));
+ cert.setSignatureInfo(info);
-// printBytes(prefix + "_KEY" + to_string(keyId) + "_CERT" + to_string(certVersion),
-// cert.wireEncode());
-// }
-// }
-// }
+ EncodingBuffer buf;
+ cert.wireEncode(buf, true);
+ cert.setSignatureValue(m_tpm.sign({buf}, keyName, DigestAlgorithm::SHA256));
-// static void
-// printBytes(const std::string& name, span<const uint8_t> bytes)
-// {
-// std::cout << "\nconst uint8_t " << name << "[] = {\n"
-// << " ";
+ printBytes(prefix + "_KEY" + std::to_string(keyId) + "_CERT" + std::to_string(certVersion),
+ cert.wireEncode());
+ }
+ }
+ }
-// std::string hex = toHex(bytes);
+ static void
+ printBytes(std::string_view name, span<const uint8_t> bytes)
+ {
+ auto hex = toHex(bytes);
+ std::cout << "\nconst uint8_t " << name << "[] = {\n"
+ << " ";
-// for (size_t i = 0; i < hex.size(); i++) {
-// if (i > 0 && i % 40 == 0)
-// std::cout << "\n ";
+ for (size_t i = 0; i < hex.size(); i++) {
+ if (i > 0 && i % 40 == 0)
+ std::cout << "\n ";
-// std::cout << "0x" << hex[i];
-// std::cout << hex[++i];
+ std::cout << "0x" << hex[i];
+ std::cout << hex[++i];
-// if (i + 1 != hex.size())
-// std::cout << ", ";
-// }
-// std::cout << "\n"
-// << "};" << std::endl;
-// }
+ if (i + 1 != hex.size())
+ std::cout << ", ";
+ }
+ std::cout << "\n"
+ << "};" << std::endl;
+ }
-// private:
-// PibMemory pib;
-// Tpm tpm{"test:test", make_unique<tpm::BackEndMem>()};
-// };
+private:
+ pib::PibMemory m_pib;
+ Tpm m_tpm{"test:test", make_unique<tpm::BackEndMem>()};
+};
-// // The test data can be generated using this test case
-// BOOST_FIXTURE_TEST_CASE(GenerateTestCertData, TestCertDataGenerator)
-// {
-// printTestDataForId("ID1", Name("/pib/interface/id/1"));
-// printTestDataForId("ID2", Name("/pib/interface/id/2"));
-// }
+BOOST_FIXTURE_TEST_CASE(GenerateTestCerts, TestCertDataGenerator,
+ * ut::description("regenerates the test certificates used in PibDataFixture")
+ * ut::disabled()
+ * ut::label("generator"))
+{
+ printTestDataForId("ID1", "/pib/interface/id/1");
+ printTestDataForId("ID2", "/pib/interface/id/2");
+}
+
+BOOST_AUTO_TEST_SUITE_END() // PibData
+BOOST_AUTO_TEST_SUITE_END() // Security
const uint8_t ID1_KEY1_CERT1[] = {
0x06, 0xFD, 0x02, 0x25, 0x07, 0x2B, 0x08, 0x03, 0x70, 0x69, 0x62, 0x08, 0x09, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61,
@@ -397,18 +402,18 @@
BOOST_ASSERT(id2Key2Cert2.getContent() == id2Key2Cert1.getContent());
}
-shared_ptr<PibImpl>
+shared_ptr<pib::PibImpl>
PibDataFixture::makePibWithIdentity(const Name& idName)
{
- auto pib = std::make_shared<PibMemory>();
+ auto pib = std::make_shared<pib::PibMemory>();
pib->addIdentity(idName);
return pib;
}
-shared_ptr<PibImpl>
+shared_ptr<pib::PibImpl>
PibDataFixture::makePibWithKey(const Name& keyName, span<const uint8_t> key)
{
- auto pib = std::make_shared<PibMemory>();
+ auto pib = std::make_shared<pib::PibMemory>();
pib->addIdentity(extractIdentityFromKeyName(keyName));
pib->addKey(extractIdentityFromKeyName(keyName), keyName, key);
return pib;
diff --git a/tests/unit/security/trust-anchor-container.t.cpp b/tests/unit/security/trust-anchor-container.t.cpp
index 0e76214..879ef40 100644
--- a/tests/unit/security/trust-anchor-container.t.cpp
+++ b/tests/unit/security/trust-anchor-container.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -55,19 +55,20 @@
}
void
- checkFindByInterest(const Name& name, bool canBePrefix, std::optional<Certificate> expected) const
+ checkFindByInterest(const Name& name, bool canBePrefix,
+ const std::optional<Certificate>& expected) const
{
Interest interest(name);
interest.setCanBePrefix(canBePrefix);
- BOOST_TEST_CONTEXT(interest) {
- auto found = anchorContainer.find(interest);
- if (expected) {
- BOOST_REQUIRE(found != nullptr);
- BOOST_CHECK_EQUAL(found->getName(), expected->getName());
- }
- else {
- BOOST_CHECK(found == nullptr);
- }
+ BOOST_TEST_INFO_SCOPE("Interest = " << interest);
+
+ auto found = anchorContainer.find(interest);
+ if (expected) {
+ BOOST_REQUIRE(found != nullptr);
+ BOOST_CHECK_EQUAL(found->getName(), expected->getName());
+ }
+ else {
+ BOOST_CHECK(found == nullptr);
}
}
diff --git a/tests/unit/security/validation-policy-command-interest.t.cpp b/tests/unit/security/validation-policy-command-interest.t.cpp
index 657b830..069c1be 100644
--- a/tests/unit/security/validation-policy-command-interest.t.cpp
+++ b/tests/unit/security/validation-policy-command-interest.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -38,26 +38,27 @@
struct CommandInterestDefaultOptions
{
- static ValidationPolicyCommandInterest::Options
+ static auto
getOptions()
{
- return {};
+ return ValidationPolicyCommandInterest::Options{};
}
};
-template<class T, class InnerPolicy>
+template<class ValidationOptions, class InnerPolicy>
class CommandInterestPolicyWrapper : public ValidationPolicyCommandInterest
{
public:
CommandInterestPolicyWrapper()
- : ValidationPolicyCommandInterest(make_unique<InnerPolicy>(), T::getOptions())
+ : ValidationPolicyCommandInterest(make_unique<InnerPolicy>(), ValidationOptions::getOptions())
{
}
};
-template<class T, class InnerPolicy = ValidationPolicySimpleHierarchy>
+template<class ValidationOptions = CommandInterestDefaultOptions,
+ class InnerPolicy = ValidationPolicySimpleHierarchy>
class ValidationPolicyCommandInterestFixture
- : public HierarchicalValidatorFixture<CommandInterestPolicyWrapper<T, InnerPolicy>>
+ : public HierarchicalValidatorFixture<CommandInterestPolicyWrapper<ValidationOptions, InnerPolicy>>
{
protected:
Interest
@@ -81,13 +82,12 @@
InterestSigner m_signer{this->m_keyChain};
};
-BOOST_FIXTURE_TEST_SUITE(TestValidationPolicyCommandInterest,
- ValidationPolicyCommandInterestFixture<CommandInterestDefaultOptions>)
+BOOST_FIXTURE_TEST_SUITE(TestValidationPolicyCommandInterest, ValidationPolicyCommandInterestFixture<>)
template<int secs>
struct GracePeriodSeconds
{
- static ValidationPolicyCommandInterest::Options
+ static auto
getOptions()
{
ValidationPolicyCommandInterest::Options options;
@@ -141,7 +141,8 @@
using ValidationPolicyAcceptAllCommands = ValidationPolicyCommandInterestFixture<CommandInterestDefaultOptions,
ValidationPolicyAcceptAll>;
-BOOST_FIXTURE_TEST_CASE(SignedWithSha256, ValidationPolicyAcceptAllCommands) // Bug 4635
+BOOST_FIXTURE_TEST_CASE(SignedWithSha256, ValidationPolicyAcceptAllCommands,
+ * ut::description("test for bug #4635"))
{
auto i1 = m_signer.makeCommandInterest("/hello/world/CMD", signingWithSha256());
VALIDATE_SUCCESS(i1, "Should succeed (within grace period)");
@@ -337,6 +338,19 @@
BOOST_AUTO_TEST_SUITE_END() // Rejects
+template<ssize_t count>
+struct MaxRecords
+{
+ static auto
+ getOptions()
+ {
+ ValidationPolicyCommandInterest::Options options;
+ options.gracePeriod = 15_s;
+ options.maxRecords = count;
+ return options;
+ }
+};
+
BOOST_AUTO_TEST_SUITE(Options)
using NonPositiveGracePeriods = boost::mp11::mp_list<GracePeriodSeconds<0>, GracePeriodSeconds<-1>>;
@@ -359,20 +373,7 @@
BOOST_TEST(this->lastError.getCode() == ValidationError::POLICY_ERROR);
}
-class LimitedRecordsOptions
-{
-public:
- static ValidationPolicyCommandInterest::Options
- getOptions()
- {
- ValidationPolicyCommandInterest::Options options;
- options.gracePeriod = 15_s;
- options.maxRecords = 3;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(LimitedRecords, ValidationPolicyCommandInterestFixture<LimitedRecordsOptions>)
+BOOST_FIXTURE_TEST_CASE(LimitedRecords, ValidationPolicyCommandInterestFixture<MaxRecords<3>>)
{
Identity id1 = this->addSubCertificate("/Security/ValidatorFixture/Sub1", identity);
this->cache.insert(id1.getDefaultKey().getDefaultCertificate());
@@ -410,20 +411,7 @@
VALIDATE_SUCCESS(i01, "Should succeed despite timestamp is reordered, because record has been evicted");
}
-class UnlimitedRecordsOptions
-{
-public:
- static ValidationPolicyCommandInterest::Options
- getOptions()
- {
- ValidationPolicyCommandInterest::Options options;
- options.gracePeriod = 15_s;
- options.maxRecords = -1;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(UnlimitedRecords, ValidationPolicyCommandInterestFixture<UnlimitedRecordsOptions>)
+BOOST_FIXTURE_TEST_CASE(UnlimitedRecords, ValidationPolicyCommandInterestFixture<MaxRecords<-1>>)
{
std::vector<Identity> identities;
for (size_t i = 0; i < 20; ++i) {
@@ -444,20 +432,7 @@
BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR);
}
-class ZeroRecordsOptions
-{
-public:
- static ValidationPolicyCommandInterest::Options
- getOptions()
- {
- ValidationPolicyCommandInterest::Options options;
- options.gracePeriod = 15_s;
- options.maxRecords = 0;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(ZeroRecords, ValidationPolicyCommandInterestFixture<ZeroRecordsOptions>)
+BOOST_FIXTURE_TEST_CASE(ZeroRecords, ValidationPolicyCommandInterestFixture<MaxRecords<0>>)
{
auto i1 = makeCommandInterest(identity); // signed at 0s
advanceClocks(1_s);
@@ -468,10 +443,9 @@
VALIDATE_SUCCESS(i1, "Should succeed despite timestamp is reordered, because record isn't kept");
}
-class LimitedRecordLifetimeOptions
+struct LimitedRecordLifetimeOptions
{
-public:
- static ValidationPolicyCommandInterest::Options
+ static auto
getOptions()
{
ValidationPolicyCommandInterest::Options options;
@@ -500,15 +474,14 @@
VALIDATE_SUCCESS(i2, "Should succeed despite timestamp is reordered, because record has been expired");
}
-class ZeroRecordLifetimeOptions
+struct ZeroRecordLifetimeOptions
{
-public:
- static ValidationPolicyCommandInterest::Options
+ static auto
getOptions()
{
ValidationPolicyCommandInterest::Options options;
options.gracePeriod = 15_s;
- options.recordLifetime = time::seconds::zero();
+ options.recordLifetime = 0_s;
return options;
}
};
diff --git a/tests/unit/security/validation-policy-config.t.cpp b/tests/unit/security/validation-policy-config.t.cpp
index 031eff0..746ac90 100644
--- a/tests/unit/security/validation-policy-config.t.cpp
+++ b/tests/unit/security/validation-policy-config.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -24,7 +24,6 @@
#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/io.hpp"
#include "tests/boost-test.hpp"
#include "tests/unit/security/validator-config/common.hpp"
@@ -57,44 +56,18 @@
VALIDATE_FAILURE(i, "Empty policy should reject everything");
}
-template<typename Packet>
-class PacketName;
-
-template<>
-class PacketName<Interest>
-{
-public:
- static std::string
- getName()
- {
- return "interest";
- }
-};
-
-template<>
-class PacketName<Data>
-{
-public:
- static std::string
- getName()
- {
- return "data";
- }
-};
-
template<typename PacketType>
class ValidationPolicyConfigFixture : public HierarchicalValidatorFixture<ValidationPolicyConfig>
{
public:
ValidationPolicyConfigFixture()
- : path(boost::filesystem::path(UNIT_TESTS_TMPDIR) / "security" / "validation-policy-config")
{
boost::filesystem::create_directories(path);
baseConfig = R"CONF(
rule
{
id test-rule-id
- for )CONF" + PacketName<Packet>::getName() + R"CONF(
+ for )CONF" + std::string(getPacketName()) + R"CONF(
filter
{
type name
@@ -115,11 +88,23 @@
boost::filesystem::remove_all(path);
}
-protected:
- using Packet = PacketType;
+private:
+ static constexpr std::string_view
+ getPacketName()
+ {
+ if constexpr (std::is_same_v<PacketType, Interest>)
+ return "interest";
+ else if constexpr (std::is_same_v<PacketType, Data>)
+ return "data";
+ else
+ return "";
+ }
- const boost::filesystem::path path;
+protected:
+ const boost::filesystem::path path{boost::filesystem::path(UNIT_TESTS_TMPDIR) / "security" / "validation-policy-config"};
std::string baseConfig;
+
+ using Packet = PacketType;
};
template<typename PacketType>
@@ -260,9 +245,8 @@
}
};
-class NoRefresh
+struct NoRefresh
{
-public:
static std::string
getRefreshString()
{
@@ -270,9 +254,8 @@
}
};
-class Refresh1h
+struct Refresh1h
{
-public:
static std::string
getRefreshString()
{
@@ -286,9 +269,8 @@
}
};
-class Refresh1m
+struct Refresh1m
{
-public:
static std::string
getRefreshString()
{
@@ -302,9 +284,8 @@
}
};
-class Refresh1s
+struct Refresh1s
{
-public:
static std::string
getRefreshString()
{
@@ -343,31 +324,20 @@
}
};
-using DataPolicies = boost::mp11::mp_list<
- LoadStringWithFileAnchor<Data>,
- LoadFileWithFileAnchor<Data>,
- LoadFileWithMultipleFileAnchors<Data>,
- LoadSectionWithFileAnchor<Data>,
- LoadStringWithBase64Anchor<Data>,
- LoadStringWithDirAnchor<Data>,
- LoadStringWithDirAnchor<Data, Refresh1h>,
- LoadStringWithDirAnchor<Data, Refresh1m>,
- LoadStringWithDirAnchor<Data, Refresh1s>
+template<typename PacketType>
+using Policies = boost::mp11::mp_list<
+ LoadStringWithFileAnchor<PacketType>,
+ LoadFileWithFileAnchor<PacketType>,
+ LoadFileWithMultipleFileAnchors<PacketType>,
+ LoadSectionWithFileAnchor<PacketType>,
+ LoadStringWithBase64Anchor<PacketType>,
+ LoadStringWithDirAnchor<PacketType>,
+ LoadStringWithDirAnchor<PacketType, Refresh1h>,
+ LoadStringWithDirAnchor<PacketType, Refresh1m>,
+ LoadStringWithDirAnchor<PacketType, Refresh1s>
>;
-using InterestPolicies = boost::mp11::mp_list<
- LoadStringWithFileAnchor<Interest>,
- LoadFileWithFileAnchor<Interest>,
- LoadFileWithMultipleFileAnchors<Interest>,
- LoadSectionWithFileAnchor<Interest>,
- LoadStringWithBase64Anchor<Interest>,
- LoadStringWithDirAnchor<Interest>,
- LoadStringWithDirAnchor<Interest, Refresh1h>,
- LoadStringWithDirAnchor<Interest, Refresh1m>,
- LoadStringWithDirAnchor<Interest, Refresh1s>
->;
-
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateData, Policy, DataPolicies, Policy)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateData, Policy, Policies<Data>, Policy)
{
BOOST_CHECK_EQUAL(this->policy.m_dataRules.size(), 1);
BOOST_CHECK_EQUAL(this->policy.m_interestRules.size(), 0);
@@ -403,7 +373,7 @@
VALIDATE_FAILURE(packet, "Should fail, because subSelfSignedIdentity is not a trust anchor");
}
-BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateInterest, Policy, InterestPolicies, Policy)
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateInterest, Policy, Policies<Interest>, Policy)
{
BOOST_CHECK_EQUAL(this->policy.m_dataRules.size(), 0);
BOOST_CHECK_EQUAL(this->policy.m_interestRules.size(), 1);
@@ -736,9 +706,7 @@
using RefreshPolicies = boost::mp11::mp_list<Refresh1h, Refresh1m, Refresh1s>;
template<typename RefreshPolicy>
-class RefreshPolicyFixture : public LoadStringWithDirAnchor<Data, RefreshPolicy>
-{
-};
+using RefreshPolicyFixture = LoadStringWithDirAnchor<Data, RefreshPolicy>;
BOOST_FIXTURE_TEST_CASE_TEMPLATE(ValidateRefresh, Refresh, RefreshPolicies, RefreshPolicyFixture<Refresh>)
{
@@ -757,7 +725,8 @@
VALIDATE_FAILURE(packet, "Should fail, as the trust anchor should no longer exist");
}
-BOOST_FIXTURE_TEST_CASE(OrphanedPolicyLoad, HierarchicalValidatorFixture<ValidationPolicyConfig>) // Bug #4758
+BOOST_FIXTURE_TEST_CASE(OrphanedPolicyLoad, HierarchicalValidatorFixture<ValidationPolicyConfig>,
+ * ut::description("test for bug #4758"))
{
using ndn::security::validator_config::Error;
diff --git a/tests/unit/security/validation-policy-signed-interest.t.cpp b/tests/unit/security/validation-policy-signed-interest.t.cpp
index 2cd91a7..75d1f5e 100644
--- a/tests/unit/security/validation-policy-signed-interest.t.cpp
+++ b/tests/unit/security/validation-policy-signed-interest.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,7 +22,6 @@
#include "ndn-cxx/security/validation-policy-signed-interest.hpp"
#include "ndn-cxx/security/interest-signer.hpp"
-#include "ndn-cxx/security/validation-policy-accept-all.hpp"
#include "ndn-cxx/security/validation-policy-simple-hierarchy.hpp"
#include "tests/test-common.hpp"
@@ -38,47 +37,46 @@
struct SignedInterestDefaultOptions
{
- static ValidationPolicySignedInterest::Options
+ static auto
getOptions()
{
- return {};
+ return ValidationPolicySignedInterest::Options{};
}
};
-template<class T, class InnerPolicy>
+template<class ValidationOptions, class InnerPolicy>
class SignedInterestPolicyWrapper : public ValidationPolicySignedInterest
{
public:
SignedInterestPolicyWrapper()
- : ValidationPolicySignedInterest(make_unique<InnerPolicy>(), T::getOptions())
+ : ValidationPolicySignedInterest(make_unique<InnerPolicy>(), ValidationOptions::getOptions())
{
}
};
-template<class T, class InnerPolicy = ValidationPolicySimpleHierarchy>
+template<class ValidationOptions = SignedInterestDefaultOptions,
+ class InnerPolicy = ValidationPolicySimpleHierarchy>
class ValidationPolicySignedInterestFixture
- : public HierarchicalValidatorFixture<SignedInterestPolicyWrapper<T, InnerPolicy>>
+ : public HierarchicalValidatorFixture<SignedInterestPolicyWrapper<ValidationOptions, InnerPolicy>>
{
protected:
Interest
- makeSignedInterest(const Identity& identity,
+ makeSignedInterest(const Identity& id,
uint32_t signingFlags = InterestSigner::WantNonce | InterestSigner::WantTime)
{
- Interest i(Name(identity.getName()).append("CMD"));
- m_signer.makeSignedInterest(i, signingByIdentity(identity), signingFlags);
- return i;
+ Interest interest(Name(id.getName()).append("CMD"));
+ m_signer.makeSignedInterest(interest, signingByIdentity(id), signingFlags);
+ return interest;
}
protected:
InterestSigner m_signer{this->m_keyChain};
-
static constexpr uint32_t WantAll = InterestSigner::WantNonce |
- InterestSigner::WantTime |
- InterestSigner::WantSeqNum;
+ InterestSigner::WantTime |
+ InterestSigner::WantSeqNum;
};
-BOOST_FIXTURE_TEST_SUITE(TestValidationPolicySignedInterest,
- ValidationPolicySignedInterestFixture<SignedInterestDefaultOptions>)
+BOOST_FIXTURE_TEST_SUITE(TestValidationPolicySignedInterest, ValidationPolicySignedInterestFixture<>)
BOOST_AUTO_TEST_CASE(Basic)
{
@@ -114,7 +112,7 @@
template<ssize_t count>
struct MaxRecordCount
{
- static ValidationPolicySignedInterest::Options
+ static auto
getOptions()
{
ValidationPolicySignedInterest::Options options;
@@ -194,6 +192,29 @@
VALIDATE_SUCCESS(i1, "Should succeed despite timestamp reordering, as records aren't kept");
}
+struct DisabledTimestampValidation
+{
+ static auto
+ getOptions()
+ {
+ ValidationPolicySignedInterest::Options options;
+ options.shouldValidateTimestamps = false;
+ return options;
+ }
+};
+
+template<int secs>
+struct GracePeriodSeconds
+{
+ static auto
+ getOptions()
+ {
+ ValidationPolicySignedInterest::Options options;
+ options.timestampGracePeriod = time::seconds(secs);
+ return options;
+ }
+};
+
BOOST_AUTO_TEST_SUITE(TimestampValidation)
BOOST_AUTO_TEST_CASE(MissingTimestamp)
@@ -203,19 +224,7 @@
BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR);
}
-struct DisabledTimestampValidationOptions
-{
- static ValidationPolicySignedInterest::Options
- getOptions()
- {
- ValidationPolicySignedInterest::Options options;
- options.shouldValidateTimestamps = false;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(Disabled,
- ValidationPolicySignedInterestFixture<DisabledTimestampValidationOptions>)
+BOOST_FIXTURE_TEST_CASE(Disabled, ValidationPolicySignedInterestFixture<DisabledTimestampValidation>)
{
auto i1 = makeSignedInterest(identity); // signed at 0ms
advanceClocks(100_ms);
@@ -229,18 +238,6 @@
VALIDATE_SUCCESS(i2, "Should succeed");
}
-template<int secs>
-struct GracePeriodSeconds
-{
- static ValidationPolicySignedInterest::Options
- getOptions()
- {
- ValidationPolicySignedInterest::Options options;
- options.timestampGracePeriod = time::seconds(secs);
- return options;
- }
-};
-
BOOST_FIXTURE_TEST_CASE(TimestampTooOld, ValidationPolicySignedInterestFixture<GracePeriodSeconds<15>>)
{
auto i1 = makeSignedInterest(identity); // signed at 0s
@@ -346,6 +343,17 @@
BOOST_AUTO_TEST_SUITE_END() // TimestampValidation
+struct EnabledSeqNumValidation
+{
+ static auto
+ getOptions()
+ {
+ ValidationPolicySignedInterest::Options options;
+ options.shouldValidateSeqNums = true;
+ return options;
+ }
+};
+
BOOST_AUTO_TEST_SUITE(SeqNumValidation)
// By default, sequence number validation is disabled
@@ -362,27 +370,14 @@
VALIDATE_SUCCESS(i2, "Should succeed");
}
-struct SeqNumValidationOptions
-{
- static ValidationPolicySignedInterest::Options
- getOptions()
- {
- ValidationPolicySignedInterest::Options options;
- options.shouldValidateSeqNums = true;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(MissingSeqNum,
- ValidationPolicySignedInterestFixture<SeqNumValidationOptions>)
+BOOST_FIXTURE_TEST_CASE(MissingSeqNum, ValidationPolicySignedInterestFixture<EnabledSeqNumValidation>)
{
auto i1 = makeSignedInterest(identity, InterestSigner::WantTime);
VALIDATE_FAILURE(i1, "Should fail (sequence number missing");
BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR);
}
-BOOST_FIXTURE_TEST_CASE(SeqNumReorder,
- ValidationPolicySignedInterestFixture<SeqNumValidationOptions>)
+BOOST_FIXTURE_TEST_CASE(SeqNumReorder, ValidationPolicySignedInterestFixture<EnabledSeqNumValidation>)
{
auto i1 = makeSignedInterest(identity, WantAll); // seq num is i
VALIDATE_SUCCESS(i1, "Should succeed");
@@ -400,6 +395,31 @@
BOOST_AUTO_TEST_SUITE_END() // SeqNumValidation
+struct DisabledNonceValidation
+{
+ static auto
+ getOptions()
+ {
+ ValidationPolicySignedInterest::Options options;
+ options.shouldValidateNonces = false;
+ return options;
+ }
+};
+
+template<ssize_t count>
+struct MaxNonceRecordCount
+{
+ static auto
+ getOptions()
+ {
+ ValidationPolicySignedInterest::Options options;
+ options.shouldValidateTimestamps = false;
+ options.shouldValidateSeqNums = false;
+ options.maxNonceRecordCount = count;
+ return options;
+ }
+};
+
BOOST_AUTO_TEST_SUITE(NonceValidation)
BOOST_AUTO_TEST_CASE(MissingNonce)
@@ -429,19 +449,7 @@
VALIDATE_SUCCESS(i3, "Should succeed");
}
-struct DisabledNonceValidationOptions
-{
- static ValidationPolicySignedInterest::Options
- getOptions()
- {
- ValidationPolicySignedInterest::Options options;
- options.shouldValidateNonces = false;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(Disabled,
- ValidationPolicySignedInterestFixture<DisabledNonceValidationOptions>)
+BOOST_FIXTURE_TEST_CASE(Disabled, ValidationPolicySignedInterestFixture<DisabledNonceValidation>)
{
auto i1 = makeSignedInterest(identity, WantAll ^ InterestSigner::WantNonce);
VALIDATE_SUCCESS(i1, "Should succeed");
@@ -460,21 +468,7 @@
VALIDATE_SUCCESS(i3, "Should succeed");
}
-struct NonceLimit2Options
-{
- static ValidationPolicySignedInterest::Options
- getOptions()
- {
- ValidationPolicySignedInterest::Options options;
- options.shouldValidateTimestamps = false;
- options.shouldValidateSeqNums = false;
- options.maxNonceRecordCount = 2;
- return options;
- }
-};
-
-BOOST_FIXTURE_TEST_CASE(NonceRecordLimit,
- ValidationPolicySignedInterestFixture<NonceLimit2Options>)
+BOOST_FIXTURE_TEST_CASE(NonceRecordLimit, ValidationPolicySignedInterestFixture<MaxNonceRecordCount<2>>)
{
auto i1 = makeSignedInterest(identity, WantAll);
VALIDATE_SUCCESS(i1, "Should succeed");
diff --git a/tests/unit/security/validator-config.t.cpp b/tests/unit/security/validator-config.t.cpp
index 7cdfa53..3cfb122 100644
--- a/tests/unit/security/validator-config.t.cpp
+++ b/tests/unit/security/validator-config.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -124,8 +124,8 @@
BOOST_AUTO_TEST_SUITE_END() // Loads
-
-BOOST_FIXTURE_TEST_CASE(ValidateCommandInterestWithDigestSha256, ValidatorConfigFixture) // Bug 4635
+BOOST_FIXTURE_TEST_CASE(ValidateCommandInterestWithDigestSha256, ValidatorConfigFixture,
+ * ut::description("test for bug #4635"))
{
validator.load(configFile);
diff --git a/tests/unit/security/validator-config/checker.t.cpp b/tests/unit/security/validator-config/checker.t.cpp
index d7e2fb9..523f1a2 100644
--- a/tests/unit/security/validator-config/checker.t.cpp
+++ b/tests/unit/security/validator-config/checker.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -64,14 +64,15 @@
static void
testChecker(C& checker, tlv::SignatureTypeValue sigType, const Name& pktName, const Name& klName, bool expectedOutcome)
{
- BOOST_TEST_CONTEXT("pkt=" << pktName << " kl=" << klName) {
- auto state = PktType::makeState();
- auto result = checker.check(PktType::getType(), sigType, pktName, klName, *state);
- BOOST_CHECK_EQUAL(bool(result), expectedOutcome);
- BOOST_CHECK(boost::logic::indeterminate(state->getOutcome()));
- if (!result) {
- BOOST_CHECK_NE(result.getErrorMessage(), "");
- }
+ BOOST_TEST_INFO_SCOPE("Packet = " << pktName);
+ BOOST_TEST_INFO_SCOPE("KeyLocator = " << klName);
+
+ auto state = PktType::makeState();
+ auto result = checker.check(PktType::getType(), sigType, pktName, klName, *state);
+ BOOST_CHECK_EQUAL(bool(result), expectedOutcome);
+ BOOST_CHECK(boost::logic::indeterminate(state->getOutcome()));
+ if (!result) {
+ BOOST_CHECK_NE(result.getErrorMessage(), "");
}
}
diff --git a/tests/unit/security/validator-config/rule.t.cpp b/tests/unit/security/validator-config/rule.t.cpp
index 434a0c9..49fdde2 100644
--- a/tests/unit/security/validator-config/rule.t.cpp
+++ b/tests/unit/security/validator-config/rule.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -95,20 +95,21 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Checkers, PktType, PktTypes, RuleFixture<PktType>)
{
auto testChecker = [this] (const Name& klName, bool expectedOutcome) {
- BOOST_TEST_CONTEXT(klName << " expected=" << expectedOutcome) {
- this->state = PktType::makeState(); // reset state
- BOOST_CHECK_EQUAL(this->rule.check(PktType::getType(), tlv::SignatureSha256WithRsa,
- this->pktName, klName, this->state),
- expectedOutcome);
+ BOOST_TEST_INFO_SCOPE("Name = " << klName);
+ BOOST_TEST_INFO_SCOPE("Expected = " << expectedOutcome);
- auto outcome = this->state->getOutcome();
- if (expectedOutcome) {
- BOOST_CHECK(boost::logic::indeterminate(outcome));
- }
- else {
- BOOST_CHECK(!boost::logic::indeterminate(outcome));
- BOOST_CHECK(!bool(outcome));
- }
+ this->state = PktType::makeState(); // reset state
+ BOOST_CHECK_EQUAL(this->rule.check(PktType::getType(), tlv::SignatureSha256WithRsa,
+ this->pktName, klName, this->state),
+ expectedOutcome);
+
+ auto outcome = this->state->getOutcome();
+ if (expectedOutcome) {
+ BOOST_CHECK(boost::logic::indeterminate(outcome));
+ }
+ else {
+ BOOST_CHECK(!boost::logic::indeterminate(outcome));
+ BOOST_CHECK(!bool(outcome));
}
};
diff --git a/tests/unit/security/verification-helpers.t.cpp b/tests/unit/security/verification-helpers.t.cpp
index 0e34bcd..fa8be69 100644
--- a/tests/unit/security/verification-helpers.t.cpp
+++ b/tests/unit/security/verification-helpers.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -21,13 +21,15 @@
#include "ndn-cxx/security/verification-helpers.hpp"
#include "ndn-cxx/security/transform/public-key.hpp"
-// #include "ndn-cxx/util/string-helper.hpp"
+#include "ndn-cxx/util/string-helper.hpp"
#include "tests/key-chain-fixture.hpp"
#include "tests/test-common.hpp"
#include <boost/mp11/list.hpp>
+#include <iostream>
+
namespace ndn::tests {
using namespace ndn::security;
@@ -35,95 +37,108 @@
BOOST_AUTO_TEST_SUITE(Security)
BOOST_AUTO_TEST_SUITE(TestVerificationHelpers)
-// // Use this test case to regenerate the dataset if the signature format changes
-// BOOST_FIXTURE_TEST_CASE(Generator, KeyChainFixture)
-// {
-// Identity wrongIdentity = m_keyChain.createIdentity("/Security/TestVerificationHelpers/Wrong");
-// const std::map<std::string, SigningInfo> identities = {
-// {"Ecdsa", signingByIdentity(m_keyChain.createIdentity("/Security/TestVerificationHelpers/EC", EcKeyParams()))},
-// {"Rsa", signingByIdentity(m_keyChain.createIdentity("/Security/TestVerificationHelpers/RSA", RsaKeyParams()))},
-// {"Sha256", signingWithSha256()}
-// };
+// Use this test case to regenerate the datasets if the signature format changes
+BOOST_FIXTURE_TEST_CASE(GenerateTestData, KeyChainFixture,
+ * ut::description("regenerates the static test data used by other test cases")
+ * ut::disabled()
+ * ut::label("generator"))
+{
+ auto wrongIdentity = m_keyChain.createIdentity("/Security/TestVerificationHelpers/Wrong");
+ const std::map<std::string, SigningInfo> identities = {
+ {"Ecdsa", signingByIdentity(m_keyChain.createIdentity("/Security/TestVerificationHelpers/EC", EcKeyParams()))},
+ {"Rsa", signingByIdentity(m_keyChain.createIdentity("/Security/TestVerificationHelpers/RSA", RsaKeyParams()))},
+ {"Sha256", signingWithSha256()}
+ };
-// auto print = [] (const std::string& name, span<const uint8_t> buf) {
-// std::cout << " const Block " + name + "{{\n ";
+ auto print = [] (std::string_view name, span<const uint8_t> buf) {
+ auto hex = toHex(buf);
+ std::cout << " const Block " << name << "{{\n ";
-// std::string hex = toHex(buf);
+ for (size_t i = 0; i < hex.size(); i++) {
+ if (i > 0 && i % 32 == 0)
+ std::cout << "\n ";
-// for (size_t i = 0; i < hex.size(); i++) {
-// if (i > 0 && i % 32 == 0)
-// std::cout << "\n ";
+ std::cout << "0x" << hex[i];
+ std::cout << hex[++i];
-// std::cout << "0x" << hex[i];
-// std::cout << hex[++i];
+ if ((i + 1) != hex.size())
+ std::cout << ", ";
+ }
+ std::cout << "\n }};";
+ };
-// if ((i + 1) != hex.size())
-// std::cout << ", ";
-// }
-// std::cout << "\n }};";
-// };
+ for (const auto& i : identities) {
+ const std::string& type = i.first;
+ const SigningInfo& signingInfo = i.second;
-// for (const auto& i : identities) {
-// const std::string& type = i.first;
-// const SigningInfo& signingInfo = i.second;
+ std::cout << "struct " << type << "Dataset\n{\n";
-// std::cout << "struct " + type + "Dataset\n{\n";
-// std::cout << " const std::string name = \"" << type << "\";\n";
+ if (signingInfo.getSignerType() == SigningInfo::SIGNER_TYPE_ID) {
+ print("cert", signingInfo.getPibIdentity().getDefaultKey().getDefaultCertificate().wireEncode());
+ }
+ else {
+ print("cert", {});
+ }
+ std::cout << "\n";
-// if (signingInfo.getSignerType() == SigningInfo::SIGNER_TYPE_ID) {
-// print("cert", signingInfo.getPibIdentity().getDefaultKey().getDefaultCertificate().wireEncode());
-// }
-// else {
-// print("cert", {});
-// }
-// std::cout << "\n";
+ // Create data that can be verified by cert
+ Data data(Name("/test/data").append(type));
+ m_keyChain.sign(data, signingInfo);
+ print("goodData", data.wireEncode());
+ std::cout << "\n";
-// // Create data that can be verified by cert
-// Data data(Name("/test/data").append(type));
-// m_keyChain.sign(data, signingInfo);
-// print("goodData", data.wireEncode());
-// std::cout << "\n";
+ // Create data that cannot be verified by cert
+ m_keyChain.sign(data, signingByIdentity(wrongIdentity));
+ print("badSigData", data.wireEncode());
+ std::cout << "\n";
-// // Create data that cannot be verified by cert
-// m_keyChain.sign(data, signingByIdentity(wrongIdentity));
-// print("badSigData", data.wireEncode());
-// std::cout << "\n";
+ // Create interest that can be verified by cert
+ Interest interest1(Name("/test/interest").append(type));
+ SigningInfo signingInfoV03(signingInfo);
+ signingInfoV03.setSignedInterestFormat(SignedInterestFormat::V03);
+ interest1.setNonce(0xF72C8A4B);
+ m_keyChain.sign(interest1, signingInfoV03);
+ print("goodInterest", interest1.wireEncode());
+ std::cout << "\n";
-// // Create interest that can be verified by cert
-// Interest interest1(Name("/test/interest").append(type));
-// SigningInfo signingInfoV03(signingInfo);
-// signingInfoV03.setSignedInterestFormat(SignedInterestFormat::V03);
-// interest1.setNonce(0xF72C8A4B);
-// m_keyChain.sign(interest1, signingInfoV03);
-// print("goodInterest", interest1.wireEncode());
-// std::cout << "\n";
+ // Create interest that cannot be verified by cert
+ m_keyChain.sign(interest1,
+ signingByIdentity(wrongIdentity).setSignedInterestFormat(SignedInterestFormat::V03));
+ print("badSigInterest", interest1.wireEncode());
+ std::cout << "\n";
-// // Create interest that cannot be verified by cert
-// m_keyChain.sign(interest1, signingByIdentity(wrongIdentity)
-// .setSignedInterestFormat(SignedInterestFormat::V03));
-// print("badSigInterest", interest1.wireEncode());
-// std::cout << "\n";
+ // Create interest that can be verified by cert (old signed Interest format)
+ Interest interest2(Name("/test/interest").append(type));
+ SigningInfo signingInfoV02(signingInfo);
+ signingInfoV02.setSignedInterestFormat(SignedInterestFormat::V03);
+ interest2.setNonce(0xF72C8A4B);
+ m_keyChain.sign(interest2, signingInfoV02);
+ print("goodInterestOldFormat", interest2.wireEncode());
+ std::cout << "\n";
-// // Create interest that can be verified by cert (old signed Interest format)
-// Interest interest2(Name("/test/interest").append(type));
-// SigningInfo signingInfoV02(signingInfo);
-// signingInfoV02.setSignedInterestFormat(SignedInterestFormat::V03);
-// interest2.setNonce(0xF72C8A4B);
-// m_keyChain.sign(interest2, signingInfoV02);
-// print("goodInterestOldFormat", interest2.wireEncode());
-// std::cout << "\n";
+ // Create interest that cannot be verified by cert (old signed Interest format)
+ m_keyChain.sign(interest2,
+ signingByIdentity(wrongIdentity).setSignedInterestFormat(SignedInterestFormat::V02));
+ print("badSigInterestOldFormat", interest2.wireEncode());
+ std::cout << "\n};\n\n";
+ }
+}
-// // Create interest that cannot be verified by cert (old signed Interest format)
-// m_keyChain.sign(interest2, signingByIdentity(wrongIdentity)
-// .setSignedInterestFormat(SignedInterestFormat::V02));
-// print("badSigInterestOldFormat", interest2.wireEncode());
-// std::cout << "\n};\n\n";
-// }
-// }
+// Note about the datasets below:
+// - .cert a valid certificate
+// - .goodData is a Data packet that can be verified against .cert
+// - .badSigData a valid and signed Data packet that cannot be verified against cert (signed using
+// a different private key)
+// - .goodInterest is an Interest packet that can be verified against .cert
+// - .badSigInterest is a valid and signed Interest packet that cannot be verified against .cert
+// (signed using a different private key)
+// - .goodInterestOldFormat is an Interest packet that can be verified against .cert (in the old
+// signed Interest format)
+// - .badSigInterestOldFormat is a valid and signed Interest packet that cannot be verified against
+// .cert (signed using a different private key and in the old signed Interest format)
struct EcdsaDataset
{
- const std::string name = "Ecdsa";
const Block cert{{
0x06, 0xFD, 0x01, 0x62, 0x07, 0x47, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79,
0x08, 0x17, 0x54, 0x65, 0x73, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
@@ -249,7 +264,6 @@
struct RsaDataset
{
- const std::string name = "Rsa";
const Block cert{{
0x06, 0xFD, 0x02, 0xED, 0x07, 0x48, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79,
0x08, 0x17, 0x54, 0x65, 0x73, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
@@ -446,7 +460,6 @@
struct Sha256Dataset
{
- const std::string name = "Sha256";
const Block cert{{
}};
const Block goodData{{
@@ -522,19 +535,6 @@
}};
};
-// Note about the datasets:
-// - .cert a valid certificate
-// - .goodData is a Data packet that can be verified against .cert
-// - .badSigData a valid and signed Data packet that cannot be verified against cert (signed using
-// a different private key)
-// - .goodInterest is an Interest packet that can be verified against .cert
-// - .badSigInterest is a valid and signed Interest packet that cannot be verified against .cert
-// (signed using a different private key)
-// - .goodInterestOldFormat is an Interest packet that can be verified against .cert (in the old
-// signed Interest format)
-// - .badSigInterestOldFormat is a valid and signed Interest packet that cannot be verified against
-// .cert (signed using a different private key and in the old signed Interest format)
-
using SignatureDatasets = boost::mp11::mp_list<EcdsaDataset, RsaDataset>;
BOOST_AUTO_TEST_CASE_TEMPLATE(VerifySignature, Dataset, SignatureDatasets)
@@ -587,8 +587,8 @@
BOOST_CHECK(!verifySignature(unsignedData, invalidKey));
BOOST_CHECK(!verifySignature(unsignedInterest1, invalidKey));
- // - base version of verifySignature is tested transitively
- // - pib::Key version is tested as part of key-chain.t.cpp (Security/TestKeyChain)
+ // - base version of verifySignature() is tested transitively
+ // - pib::Key version is tested in key-chain.t.cpp (Security/TestKeyChain)
}
BOOST_FIXTURE_TEST_CASE(VerifyHmac, KeyChainFixture)
@@ -663,7 +663,8 @@
0x02, 0x03, 0x04
};
-BOOST_AUTO_TEST_CASE(VerifyWithUnrecognizedElements) // Bug #4583
+BOOST_AUTO_TEST_CASE(VerifyWithUnrecognizedElements,
+ * ut::description("test for bug #4583"))
{
Data data(Block{sha256DataUnrecognizedElements});
Interest interest(Block{sha256InterestUnrecognizedElements});
diff --git a/tests/unit/signature-info.t.cpp b/tests/unit/signature-info.t.cpp
index 8fc459c..d3e4c7e 100644
--- a/tests/unit/signature-info.t.cpp
+++ b/tests/unit/signature-info.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -483,7 +483,8 @@
BOOST_CHECK(!info.getCustomTlv(0x81));
}
-BOOST_AUTO_TEST_CASE(CustomTlvsEncoding) // Bug #3914
+BOOST_AUTO_TEST_CASE(CustomTlvsEncoding,
+ * ut::description("test for bug #3914"))
{
SignatureInfo info1(tlv::SignatureSha256WithRsa);
info1.addCustomTlv(makeStringBlock(102, "First"));
diff --git a/tests/unit/util/indented-stream.t.cpp b/tests/unit/util/indented-stream.t.cpp
index 4994d0d..63bb483 100644
--- a/tests/unit/util/indented-stream.t.cpp
+++ b/tests/unit/util/indented-stream.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -53,7 +53,8 @@
));
}
-BOOST_AUTO_TEST_CASE(BasicWithFlushes) // Bug #2723
+BOOST_AUTO_TEST_CASE(BasicWithFlushes,
+ * ut::description("test for bug #2723"))
{
output_test_stream os;
diff --git a/tests/unit/util/io.t.cpp b/tests/unit/util/io.t.cpp
index 3492fa1..2dc303d 100644
--- a/tests/unit/util/io.t.cpp
+++ b/tests/unit/util/io.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -34,22 +34,22 @@
struct NoEncoding
{
- const io::IoEncoding encoding{io::NO_ENCODING};
- const std::vector<uint8_t> blob{0xd1, 0x0, 0xb0, 0x1a};
+ static constexpr io::IoEncoding encoding = io::NO_ENCODING;
+ static inline const std::vector<uint8_t> blob{0xd1, 0x0, 0xb0, 0x1a};
std::istringstream stream{std::string("\xd1\x00\xb0\x1a", 4), std::ios_base::binary};
};
struct Base64Encoding
{
- const io::IoEncoding encoding = io::BASE64;
- const std::vector<uint8_t> blob{0x42, 0x61, 0x73, 0x65, 0x36, 0x34, 0x45, 0x6e, 0x63};
+ static constexpr io::IoEncoding encoding = io::BASE64;
+ static inline const std::vector<uint8_t> blob{0x42, 0x61, 0x73, 0x65, 0x36, 0x34, 0x45, 0x6e, 0x63};
std::istringstream stream{"QmFzZTY0RW5j\n", std::ios_base::binary};
};
struct HexEncoding
{
- const io::IoEncoding encoding = io::HEX;
- const std::vector<uint8_t> blob{0x48, 0x65, 0x78, 0x45, 0x6e, 0x63};
+ static constexpr io::IoEncoding encoding = io::HEX;
+ static inline const std::vector<uint8_t> blob{0x48, 0x65, 0x78, 0x45, 0x6e, 0x63};
std::istringstream stream{"486578456E63", std::ios_base::binary};
};
@@ -58,15 +58,15 @@
BOOST_AUTO_TEST_CASE_TEMPLATE(LoadBuffer, T, Encodings)
{
T t;
- shared_ptr<Buffer> buf = io::loadBuffer(t.stream, t.encoding);
- BOOST_CHECK_EQUAL_COLLECTIONS(buf->begin(), buf->end(), t.blob.begin(), t.blob.end());
+ shared_ptr<Buffer> buf = io::loadBuffer(t.stream, T::encoding);
+ BOOST_CHECK_EQUAL_COLLECTIONS(buf->begin(), buf->end(), T::blob.begin(), T::blob.end());
}
BOOST_AUTO_TEST_CASE_TEMPLATE(SaveBuffer, T, Encodings)
{
T t;
std::ostringstream os(std::ios_base::binary);
- io::saveBuffer(t.blob, os, t.encoding);
+ io::saveBuffer(T::blob, os, T::encoding);
BOOST_CHECK_EQUAL(os.str(), t.stream.str());
}
diff --git a/tests/unit/util/scheduler.t.cpp b/tests/unit/util/scheduler.t.cpp
index 88c4313..ec59c30 100644
--- a/tests/unit/util/scheduler.t.cpp
+++ b/tests/unit/util/scheduler.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -201,7 +201,8 @@
BOOST_CHECK_EQUAL(count, 0);
}
-BOOST_AUTO_TEST_CASE(CancelAllWithScopedEventId) // Bug 3691
+BOOST_AUTO_TEST_CASE(CancelAllWithScopedEventId,
+ * ut::description("test for bug #3691"))
{
ScopedEventId eid = scheduler.schedule(10_ms, []{});
scheduler.cancelAllEvents();
diff --git a/tests/unit/util/segment-fetcher.t.cpp b/tests/unit/util/segment-fetcher.t.cpp
index 1166110..567918a 100644
--- a/tests/unit/util/segment-fetcher.t.cpp
+++ b/tests/unit/util/segment-fetcher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -824,7 +824,8 @@
BOOST_CHECK_EQUAL(nAfterSegmentTimedOut, 2);
}
-BOOST_AUTO_TEST_CASE(UncanceledPendingInterestBug) // Bug #4770
+BOOST_AUTO_TEST_CASE(UncanceledPendingInterest,
+ * ut::description("test for bug #4770"))
{
DummyValidator acceptValidator;
auto fetcher = SegmentFetcher::start(face, Interest("/hello/world"), acceptValidator);