security: modernize Key and KeyContainer; add logging
Change-Id: Ibbe6a4ea54e2a1cc7ad7a7e00ea88a29ab1f6c3d
diff --git a/tests/unit/security/pib/impl/key-impl.t.cpp b/tests/unit/security/pib/impl/key-impl.t.cpp
index c59efb5..dfcd19a 100644
--- a/tests/unit/security/pib/impl/key-impl.t.cpp
+++ b/tests/unit/security/pib/impl/key-impl.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -37,7 +37,7 @@
BOOST_AUTO_TEST_SUITE(Pib)
BOOST_FIXTURE_TEST_SUITE(TestKeyImpl, security::tests::PibDataFixture)
-using security::Pib;
+using pib::Pib;
BOOST_AUTO_TEST_CASE(Basic)
{
@@ -47,18 +47,16 @@
BOOST_CHECK_EQUAL(key11.getName(), id1Key1Name);
BOOST_CHECK_EQUAL(key11.getIdentity(), id1);
BOOST_CHECK_EQUAL(key11.getKeyType(), KeyType::EC);
- BOOST_CHECK_EQUAL_COLLECTIONS(key11.getPublicKey().begin(), key11.getPublicKey().end(),
- id1Key1.begin(), id1Key1.end());
+ BOOST_TEST(key11.getPublicKey() == id1Key1, boost::test_tools::per_element());
KeyImpl key11Bak(id1Key1Name, pibImpl);
BOOST_CHECK_EQUAL(key11Bak.getName(), id1Key1Name);
BOOST_CHECK_EQUAL(key11Bak.getIdentity(), id1);
BOOST_CHECK_EQUAL(key11Bak.getKeyType(), KeyType::EC);
- BOOST_CHECK_EQUAL_COLLECTIONS(key11Bak.getPublicKey().begin(), key11Bak.getPublicKey().end(),
- id1Key1.begin(), id1Key1.end());
+ BOOST_TEST(key11Bak.getPublicKey() == id1Key1, boost::test_tools::per_element());
}
-BOOST_AUTO_TEST_CASE(CertificateOperation)
+BOOST_AUTO_TEST_CASE(CertificateOperations)
{
auto pibImpl = make_shared<pib::PibMemory>();
KeyImpl key11(id1Key1Name, id1Key1, pibImpl);
@@ -72,16 +70,15 @@
// get default certificate, throw Pib::Error
BOOST_CHECK_THROW(key11.getDefaultCertificate(), Pib::Error);
// set non-existing certificate as default certificate, throw Pib::Error
- BOOST_REQUIRE_THROW(key11.setDefaultCertificate(id1Key1Cert1.getName()), Pib::Error);
+ BOOST_CHECK_THROW(key11.setDefaultCertificate(id1Key1Cert1.getName()), Pib::Error);
// add certificate
key11.addCertificate(id1Key1Cert1);
- BOOST_CHECK_NO_THROW(key11.getCertificate(id1Key1Cert1.getName()));
+ const auto& addedCert = key11.getCertificate(id1Key1Cert1.getName());
+ BOOST_CHECK_EQUAL(addedCert, id1Key1Cert1);
// new certificate becomes default certificate when there was no default certificate
- BOOST_REQUIRE_NO_THROW(key11.getDefaultCertificate());
const auto& defaultCert0 = key11.getDefaultCertificate();
- BOOST_CHECK_EQUAL(defaultCert0.getName(), id1Key1Cert1.getName());
BOOST_CHECK_EQUAL(defaultCert0, id1Key1Cert1);
// remove certificate
@@ -91,23 +88,16 @@
// set default certificate directly
BOOST_REQUIRE_NO_THROW(key11.setDefaultCertificate(id1Key1Cert1));
- BOOST_REQUIRE_NO_THROW(key11.getDefaultCertificate());
- BOOST_CHECK_NO_THROW(key11.getCertificate(id1Key1Cert1.getName()));
-
- // check default cert
const auto& defaultCert1 = key11.getDefaultCertificate();
- BOOST_CHECK_EQUAL(defaultCert1.getName(), id1Key1Cert1.getName());
BOOST_CHECK_EQUAL(defaultCert1, id1Key1Cert1);
// add another certificate
key11.addCertificate(id1Key1Cert2);
BOOST_CHECK_EQUAL(key11.getCertificates().size(), 2);
- // set default certificate through name
- BOOST_REQUIRE_NO_THROW(key11.setDefaultCertificate(id1Key1Cert2.getName()));
- BOOST_REQUIRE_NO_THROW(key11.getDefaultCertificate());
+ // set default certificate through name and check return value
+ BOOST_CHECK_EQUAL(key11.setDefaultCertificate(id1Key1Cert2.getName()), id1Key1Cert2);
const auto& defaultCert2 = key11.getDefaultCertificate();
- BOOST_CHECK_EQUAL(defaultCert2.getName(), id1Key1Cert2.getName());
BOOST_CHECK_EQUAL(defaultCert2, id1Key1Cert2);
// remove certificate
@@ -115,10 +105,9 @@
BOOST_CHECK_THROW(key11.getCertificate(id1Key1Cert1.getName()), Pib::Error);
BOOST_CHECK_EQUAL(key11.getCertificates().size(), 1);
- // set default certificate directly again, change the default setting
+ // set removed certificate as default, certificate is implicitly added
BOOST_REQUIRE_NO_THROW(key11.setDefaultCertificate(id1Key1Cert1));
const auto& defaultCert3 = key11.getDefaultCertificate();
- BOOST_CHECK_EQUAL(defaultCert3.getName(), id1Key1Cert1.getName());
BOOST_CHECK_EQUAL(defaultCert3, id1Key1Cert1);
BOOST_CHECK_EQUAL(key11.getCertificates().size(), 2);
@@ -128,8 +117,8 @@
BOOST_CHECK_EQUAL(key11.getCertificates().size(), 1);
key11.removeCertificate(id1Key1Cert2.getName());
BOOST_CHECK_THROW(key11.getCertificate(id1Key1Cert2.getName()), Pib::Error);
- BOOST_CHECK_THROW(key11.getDefaultCertificate(), Pib::Error);
BOOST_CHECK_EQUAL(key11.getCertificates().size(), 0);
+ BOOST_CHECK_THROW(key11.getDefaultCertificate(), Pib::Error);
}
class OverwriteFixture : public ndn::security::tests::PibDataFixture,
@@ -158,17 +147,15 @@
auto otherCert = id1Key1Cert1;
SignatureInfo info;
- info.setValidityPeriod(ValidityPeriod(time::system_clock::now(),
- time::system_clock::now() + 1_s));
+ info.setValidityPeriod(ValidityPeriod::makeRelative(-1_s, 10_s));
m_keyChain.sign(otherCert, SigningInfo().setSignatureInfo(info));
- BOOST_CHECK_EQUAL(otherCert.getName(), id1Key1Cert1.getName());
- BOOST_CHECK(otherCert.getContent() == id1Key1Cert1.getContent());
- BOOST_CHECK_NE(otherCert, id1Key1Cert1);
+ BOOST_TEST(otherCert.getName() == id1Key1Cert1.getName());
+ BOOST_TEST(otherCert.getContent() == id1Key1Cert1.getContent());
+ BOOST_TEST(otherCert != id1Key1Cert1);
key1.addCertificate(otherCert);
-
- BOOST_CHECK_EQUAL(key1.getCertificate(id1Key1Cert1.getName()), otherCert);
+ BOOST_TEST(key1.getCertificate(id1Key1Cert1.getName()) == otherCert);
}
BOOST_AUTO_TEST_CASE(Errors)