tests: expect certificate name in KeyLocator

Also, delete unused KeyChainFixture::makeCert function.

refs #5112

Change-Id: I59b1ca81fca0481a37126270c447f639080ec75f
diff --git a/tests/daemon/mgmt/manager-base.t.cpp b/tests/daemon/mgmt/manager-base.t.cpp
index 8b57258..a70784c 100644
--- a/tests/daemon/mgmt/manager-base.t.cpp
+++ b/tests/daemon/mgmt/manager-base.t.cpp
@@ -141,8 +141,9 @@
 
   requesterName = "";
   m_manager.extractRequester(makeControlCommandRequest("/test/interest/signed", ControlParameters()), testAccept);
-  auto keyLocator = m_keyChain.getPib().getIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY).getDefaultKey().getName();
-  BOOST_CHECK_EQUAL(requesterName, keyLocator.toUri());
+  BOOST_CHECK_EQUAL(requesterName,
+    m_keyChain.getPib().getIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY)
+      .getDefaultKey().getDefaultCertificate().getName().toUri());
 }
 
 BOOST_AUTO_TEST_CASE(ValidateParameters)
diff --git a/tests/daemon/mgmt/rib-manager.t.cpp b/tests/daemon/mgmt/rib-manager.t.cpp
index b688996..d23eb70 100644
--- a/tests/daemon/mgmt/rib-manager.t.cpp
+++ b/tests/daemon/mgmt/rib-manager.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -128,17 +128,17 @@
     , m_fibUpdater(m_rib, m_nfdController)
     , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher)
   {
-    m_keyChain.createIdentity(m_anchorId);
-    m_keyChain.createIdentity(m_derivedId);
-
-    m_derivedCert = m_keyChain.getPib().getIdentity(m_derivedId).getDefaultKey().getDefaultCertificate();
-    ndn::SignatureInfo signatureInfo;
-    signatureInfo.setValidityPeriod(m_derivedCert.getValidityPeriod());
-    ndn::security::SigningInfo signingInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
-                                           m_anchorId, signatureInfo);
-    m_keyChain.sign(m_derivedCert, signingInfo);
+    auto anchorIdentity = m_keyChain.createIdentity(m_anchorId);
     saveIdentityCert(m_anchorId, "signer.ndncert", true);
 
+    auto derivedKey = m_keyChain.createIdentity(m_derivedId).getDefaultKey();
+    auto derivedSelfSigned = derivedKey.getDefaultCertificate();
+    ndn::security::MakeCertificateOptions opts;
+    opts.validity = derivedSelfSigned.getValidityPeriod();
+    auto derivedCert = m_keyChain.makeCertificate(derivedSelfSigned,
+                       ndn::security::signingByIdentity(anchorIdentity), opts);
+    m_keyChain.setDefaultCertificate(derivedKey, derivedCert);
+
     if (m_status.isLocalhostConfigured) {
       m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test");
     }
@@ -155,11 +155,11 @@
       clearRib();
     }
 
-    m_face.onSendInterest.connect([this] (const Interest& interest) {
-      if (interest.getName().isPrefixOf(m_derivedCert.getName())) {
-        if (m_status.isLocalhopConfigured && interest.template getTag<lp::NextHopFaceIdTag>() != nullptr) {
-          m_face.put(m_derivedCert);
-        }
+    m_face.onSendInterest.connect([=] (const Interest& interest) {
+      if (interest.matchesData(derivedCert) &&
+          m_status.isLocalhopConfigured &&
+          interest.template getTag<lp::NextHopFaceIdTag>() != nullptr) {
+        m_face.put(derivedCert);
       }
     });
   }
@@ -234,7 +234,6 @@
   ConfigurationStatus m_status;
   Name m_anchorId;
   Name m_derivedId;
-  ndn::security::Certificate m_derivedCert;
 
   ndn::nfd::Controller m_nfdController;
   rib::Rib m_rib;
diff --git a/tests/key-chain-fixture.cpp b/tests/key-chain-fixture.cpp
index faca165..de6feb6 100644
--- a/tests/key-chain-fixture.cpp
+++ b/tests/key-chain-fixture.cpp
@@ -47,30 +47,6 @@
   }
 }
 
-Certificate
-KeyChainFixture::makeCert(const Key& key, const std::string& issuer, const Key& signingKey)
-{
-  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());
-
-  // 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::saveCert(const Data& cert, const std::string& filename)
 {
diff --git a/tests/key-chain-fixture.hpp b/tests/key-chain-fixture.hpp
index 9f03ea0..0ffcb0e 100644
--- a/tests/key-chain-fixture.hpp
+++ b/tests/key-chain-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -49,16 +49,6 @@
 
 public:
   /**
-   * @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
    */