**breaking** Add KeyChain parameter to the producer API

Applications must be able to specify the KeyChain instance to use

Change-Id: If5054dbb8c00e2d18af8bf6a9199ded7266688f3
diff --git a/tests/clock-fixture.cpp b/tests/clock-fixture.cpp
index d47f695..e900f16 100644
--- a/tests/clock-fixture.cpp
+++ b/tests/clock-fixture.cpp
@@ -19,11 +19,11 @@
 
 #include "tests/clock-fixture.hpp"
 
-namespace ndn::tests {
+namespace psync::tests {
 
 ClockFixture::ClockFixture()
-  : m_steadyClock(make_shared<time::UnitTestSteadyClock>())
-  , m_systemClock(make_shared<time::UnitTestSystemClock>())
+  : m_steadyClock(std::make_shared<time::UnitTestSteadyClock>())
+  , m_systemClock(std::make_shared<time::UnitTestSystemClock>())
 {
   time::setCustomClocks(m_steadyClock, m_systemClock);
 }
@@ -49,4 +49,4 @@
   }
 }
 
-} // namespace ndn::tests
+} // namespace psync::tests
diff --git a/tests/clock-fixture.hpp b/tests/clock-fixture.hpp
index 6f79950..8523041 100644
--- a/tests/clock-fixture.hpp
+++ b/tests/clock-fixture.hpp
@@ -22,7 +22,9 @@
 
 #include <ndn-cxx/util/time-unit-test-clock.hpp>
 
-namespace ndn::tests {
+namespace psync::tests {
+
+namespace time = ndn::time;
 
 /** \brief A test fixture that overrides steady clock and system clock.
  */
@@ -72,10 +74,10 @@
   }
 
 protected:
-  shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
-  shared_ptr<time::UnitTestSystemClock> m_systemClock;
+  std::shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
+  std::shared_ptr<time::UnitTestSystemClock> m_systemClock;
 };
 
-} // namespace ndn::tests
+} // namespace psync::tests
 
 #endif // PSYNC_TESTS_CLOCK_FIXTURE_HPP
diff --git a/tests/io-fixture.hpp b/tests/io-fixture.hpp
index cdd2713..20d3e5b 100644
--- a/tests/io-fixture.hpp
+++ b/tests/io-fixture.hpp
@@ -24,7 +24,7 @@
 
 #include <boost/asio/io_service.hpp>
 
-namespace ndn::tests {
+namespace psync::tests {
 
 class IoFixture : public ClockFixture
 {
@@ -46,6 +46,6 @@
   boost::asio::io_service m_io;
 };
 
-} // namespace ndn::tests
+} // namespace psync::tests
 
 #endif // PSYNC_TESTS_IO_FIXTURE_HPP
diff --git a/tests/key-chain-fixture.hpp b/tests/key-chain-fixture.hpp
new file mode 100644
index 0000000..bdd705a
--- /dev/null
+++ b/tests/key-chain-fixture.hpp
@@ -0,0 +1,37 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2022 Regents of the University of California.
+ *
+ * This file is part of PSync.
+ *
+ * PSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * PSync 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * PSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PSYNC_TESTS_KEY_CHAIN_FIXTURE_HPP
+#define PSYNC_TESTS_KEY_CHAIN_FIXTURE_HPP
+
+#include <ndn-cxx/security/key-chain.hpp>
+
+namespace psync::tests {
+
+/**
+ * @brief A fixture providing an in-memory KeyChain.
+ */
+class KeyChainFixture
+{
+protected:
+  ndn::KeyChain m_keyChain{"pib-memory:", "tpm-memory:"};
+};
+
+} // namespace psync::tests
+
+#endif // PSYNC_TESTS_KEY_CHAIN_FIXTURE_HPP
diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp
index 1ea3119..7218e6b 100644
--- a/tests/test-full-producer.cpp
+++ b/tests/test-full-producer.cpp
@@ -22,55 +22,50 @@
 
 #include "tests/boost-test.hpp"
 #include "tests/io-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
 
-#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace psync {
 
 using namespace ndn;
 
-BOOST_AUTO_TEST_SUITE(TestFullProducer)
-
-BOOST_AUTO_TEST_CASE(Constructor)
+class FullProducerFixture : public tests::IoFixture, public tests::KeyChainFixture
 {
-  util::DummyClientFace face({true, true});
-  BOOST_CHECK_NO_THROW(FullProducer(40, face, Name("/psync"), Name("/testUser"), nullptr));
-}
+protected:
+  util::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture)
 
 BOOST_AUTO_TEST_CASE(OnInterest)
 {
   Name syncPrefix("/psync"), userNode("/testUser");
-  util::DummyClientFace face({true, true});
-
-  FullProducer node(40, face, syncPrefix, userNode, nullptr);
+  FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
 
   Name syncInterestName(syncPrefix);
   syncInterestName.append("malicious-IBF");
 
-  BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
+  BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
 }
 
-BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
+BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
 {
   Name syncPrefix("/psync"), userNode("/testUser");
-  util::DummyClientFace face(m_io, {true, true});
+  FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr, 8_s);
 
-  FullProducer node(40, face, syncPrefix, userNode, nullptr, 8_s);
   advanceClocks(10_ms);
-  face.sentInterests.clear();
+  m_face.sentInterests.clear();
 
   // full sync sends the next one in interest lifetime / 2 +- jitter
   advanceClocks(6_s);
-  BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
+  BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1);
 }
 
 BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
 {
   Name syncPrefix("/psync"), userNode("/testUser");
-  util::DummyClientFace face({true, true});
-
-  FullProducer node(40, face, syncPrefix, userNode, nullptr);
+  FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
 
   Name syncInterestName(syncPrefix);
   node.m_iblt.appendToName(syncInterestName);
diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp
index 16ba4bc..81a4aef 100644
--- a/tests/test-full-sync.cpp
+++ b/tests/test-full-sync.cpp
@@ -24,24 +24,26 @@
 
 #include "tests/boost-test.hpp"
 #include "tests/io-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
 
+#include <array>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace psync {
 
-using ndn::Name;
-using ndn::util::DummyClientFace;
+using namespace ndn;
 
-class FullSyncFixture : public ndn::tests::IoFixture
+class FullSyncFixture : public tests::IoFixture, public tests::KeyChainFixture
 {
 protected:
   void
   addNode(int id)
   {
     BOOST_ASSERT(id >= 0 && id < MAX_NODES);
-    faces[id] = std::make_shared<DummyClientFace>(m_io, DummyClientFace::Options{true, true});
     userPrefixes[id] = "/userPrefix" + std::to_string(id);
-    nodes[id] = std::make_shared<FullProducer>(40, *faces[id], syncPrefix, userPrefixes[id],
+    faces[id] = std::make_shared<util::DummyClientFace>(m_io, m_keyChain,
+                                                        util::DummyClientFace::Options{true, true});
+    nodes[id] = std::make_shared<FullProducer>(*faces[id], m_keyChain, 40, syncPrefix, userPrefixes[id],
                                                [] (const auto&) {});
   }
 
@@ -170,8 +172,8 @@
 protected:
   const Name syncPrefix = "/psync";
   static constexpr int MAX_NODES = 4;
-  std::array<std::shared_ptr<DummyClientFace>, MAX_NODES> faces;
   std::array<Name, MAX_NODES> userPrefixes;
+  std::array<std::shared_ptr<util::DummyClientFace>, MAX_NODES> faces;
   std::array<std::shared_ptr<FullProducer>, MAX_NODES> nodes;
   static constexpr uint64_t NOT_EXIST = std::numeric_limits<uint64_t>::max();
 };
diff --git a/tests/test-partial-producer.cpp b/tests/test-partial-producer.cpp
index bfbcc12..3f2ab95 100644
--- a/tests/test-partial-producer.cpp
+++ b/tests/test-partial-producer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  The University of Memphis
+ * Copyright (c) 2014-2022,  The University of Memphis
  *
  * This file is part of PSync.
  * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -20,8 +20,8 @@
 #include "PSync/partial-producer.hpp"
 
 #include "tests/boost-test.hpp"
+#include "tests/key-chain-fixture.hpp"
 
-#include <ndn-cxx/name.hpp>
 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 
@@ -29,24 +29,23 @@
 
 using namespace ndn;
 
-BOOST_AUTO_TEST_SUITE(TestPartialProducer)
-
-BOOST_AUTO_TEST_CASE(Constructor)
+class PartialProducerFixture : public tests::KeyChainFixture
 {
-  util::DummyClientFace face({true, true});
-  BOOST_CHECK_NO_THROW(PartialProducer(40, face, Name("/psync"), Name("/testUser")));
-}
+protected:
+  util::DummyClientFace m_face{m_keyChain, {true, true}};
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestPartialProducer, PartialProducerFixture)
 
 BOOST_AUTO_TEST_CASE(RegisterPrefix)
 {
   Name syncPrefix("/psync"), userNode("/testUser");
-  util::DummyClientFace face({true, true});
-  PartialProducer producer(40, face, syncPrefix, userNode);
+  PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
 
-  face.processEvents(-1_ms);
+  m_face.processEvents(-1_ms);
 
-  BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-  auto interest = face.sentInterests.front();
+  BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 1);
+  auto interest = m_face.sentInterests.front();
   BOOST_CHECK_EQUAL(interest.getName().at(3), name::Component("register"));
   nfd::ControlParameters params(interest.getName().at(4).blockFromValue());
   BOOST_CHECK_EQUAL(params.getName(), syncPrefix);
@@ -55,8 +54,7 @@
 BOOST_AUTO_TEST_CASE(PublishName)
 {
   Name syncPrefix("/psync"), userNode("/testUser"), nonUser("/testUser2");
-  util::DummyClientFace face({true, true});
-  PartialProducer producer(40, face, syncPrefix, userNode);
+  PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
 
   BOOST_CHECK_EQUAL(producer.getSeqNo(userNode).value_or(-1), 0);
   producer.publishName(userNode);
@@ -75,8 +73,7 @@
 BOOST_AUTO_TEST_CASE(SameSyncInterest)
 {
   Name syncPrefix("/psync"), userNode("/testUser");
-  util::DummyClientFace face({true, true});
-  PartialProducer producer(40, face, syncPrefix, userNode);
+  PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
 
   Name syncInterestName(syncPrefix);
   syncInterestName.append("sync");
@@ -91,29 +88,28 @@
   syncInterest.setInterestLifetime(1_s);
   syncInterest.setNonce(1);
   BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
-  face.processEvents(10_ms);
+  m_face.processEvents(10_ms);
   BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
 
-  face.processEvents(500_ms);
+  m_face.processEvents(500_ms);
 
   // Same interest again - size of pending interest should remain same, but expirationEvent should change
   syncInterest.setNonce(2);
   BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
-  face.processEvents(10_ms);
+  m_face.processEvents(10_ms);
   BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
 
-  face.processEvents(500_ms);
+  m_face.processEvents(500_ms);
   BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
 
-  face.processEvents(500_ms);
+  m_face.processEvents(500_ms);
   BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 0);
 }
 
 BOOST_AUTO_TEST_CASE(OnSyncInterest)
 {
   Name syncPrefix("/psync"), userNode("/testUser");
-  util::DummyClientFace face({true, true});
-  PartialProducer producer(40, face, syncPrefix, userNode);
+  PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
 
   // Sync interest with no bloom filter attached
   Name syncInterestName(syncPrefix);
diff --git a/tests/test-partial-sync.cpp b/tests/test-partial-sync.cpp
index 7353c5e..d7a0b4f 100644
--- a/tests/test-partial-sync.cpp
+++ b/tests/test-partial-sync.cpp
@@ -22,6 +22,7 @@
 
 #include "tests/boost-test.hpp"
 #include "tests/io-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
 
 #include <ndn-cxx/name.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
@@ -30,12 +31,12 @@
 
 using namespace ndn;
 
-class PartialSyncFixture : public tests::IoFixture
+class PartialSyncFixture : public tests::IoFixture, public tests::KeyChainFixture
 {
 public:
   PartialSyncFixture()
   {
-    producer = make_shared<PartialProducer>(40, face, syncPrefix, userPrefix);
+    producer = make_shared<PartialProducer>(face, m_keyChain, 40, syncPrefix, userPrefix);
     addUserNodes("testUser", 10);
   }
 
@@ -51,9 +52,8 @@
   void
   addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true)
   {
-    consumerFaces[id] =
-        std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true});
-
+    consumerFaces[id] = std::make_shared<util::DummyClientFace>(m_io, m_keyChain,
+                                                                util::DummyClientFace::Options{true, true});
     if (linkToProducer) {
       face.linkTo(*consumerFaces[id]);
     }
@@ -131,7 +131,8 @@
     producer->updateSeqNo(prefix, seq);
   }
 
-  util::DummyClientFace face{m_io, {true, true}};
+protected:
+  util::DummyClientFace face{m_io, m_keyChain, {true, true}};
   Name syncPrefix{"psync"};
   Name userPrefix{"testUser-0"};
 
@@ -288,8 +289,8 @@
   // Link to first producer goes down
   face.unlink();
 
-  util::DummyClientFace face2(m_io, {true, true});
-  PartialProducer replicatedProducer(40, face2, syncPrefix, userPrefix);
+  util::DummyClientFace face2(m_io, m_keyChain, {true, true});
+  PartialProducer replicatedProducer(face2, m_keyChain, 40, syncPrefix, userPrefix);
   for (int i = 1; i < 10; i++) {
       replicatedProducer.addUserNode("testUser-" + std::to_string(i));
   }
diff --git a/tests/test-producer-base.cpp b/tests/test-producer-base.cpp
index deab560..67d4aa2 100644
--- a/tests/test-producer-base.cpp
+++ b/tests/test-producer-base.cpp
@@ -20,28 +20,27 @@
 #include "PSync/producer-base.hpp"
 
 #include "tests/boost-test.hpp"
+#include "tests/key-chain-fixture.hpp"
 
-#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace psync {
 
 using namespace ndn;
 
-BOOST_AUTO_TEST_SUITE(TestProducerBase)
-
-BOOST_AUTO_TEST_CASE(Constructor)
+class ProducerBaseFixture : public tests::KeyChainFixture
 {
-  util::DummyClientFace face;
-  BOOST_CHECK_NO_THROW(ProducerBase(40, face, Name("/psync"), Name("/testUser")));
-}
+protected:
+  util::DummyClientFace m_face;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestProducerBase, ProducerBaseFixture)
 
 BOOST_AUTO_TEST_CASE(Basic)
 {
-  util::DummyClientFace face;
   Name userNode("/testUser");
-  ProducerBase producerBase(40, face, Name("/psync"), userNode);
+  ProducerBase producerBase(m_face, m_keyChain, 40, Name("/psync"), userNode);
+
   // Hash table size should be 40 + 40/2 = 60 (which is perfectly divisible by N_HASH = 3)
   BOOST_CHECK_EQUAL(producerBase.m_iblt.getHashTable().size(), 60);
   BOOST_CHECK_EQUAL(producerBase.getSeqNo(userNode).value(), 0);
@@ -67,16 +66,14 @@
 
 BOOST_AUTO_TEST_CASE(ApplicationNack)
 {
-  util::DummyClientFace face;
-  ProducerBase producerBase(40, face, Name("/psync"), Name("/testUser"));
+  ProducerBase producerBase(m_face, m_keyChain, 40, Name("/psync"), Name("/testUser"));
 
-  BOOST_CHECK_EQUAL(face.sentData.size(), 0);
-  producerBase.m_syncReplyFreshness = 1_s;
+  BOOST_CHECK_EQUAL(m_face.sentData.size(), 0);
   producerBase.sendApplicationNack(Name("test"));
-  face.processEvents(10_ms);
+  m_face.processEvents(10_ms);
 
-  BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
-  BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), tlv::ContentType_Nack);
+  BOOST_REQUIRE_EQUAL(m_face.sentData.size(), 1);
+  BOOST_CHECK_EQUAL(m_face.sentData.front().getContentType(), tlv::ContentType_Nack);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-segment-publisher.cpp b/tests/test-segment-publisher.cpp
index 4874c49..bccaee1 100644
--- a/tests/test-segment-publisher.cpp
+++ b/tests/test-segment-publisher.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  The University of Memphis
+ * Copyright (c) 2014-2022,  The University of Memphis
  *
  * This file is part of PSync.
  * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -22,9 +22,8 @@
 
 #include "tests/boost-test.hpp"
 #include "tests/io-fixture.hpp"
+#include "tests/key-chain-fixture.hpp"
 
-#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/security/validator-null.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 #include <ndn-cxx/util/segment-fetcher.hpp>
@@ -33,16 +32,14 @@
 
 using namespace ndn;
 
-class SegmentPublisherFixture : public tests::IoFixture
+class SegmentPublisherFixture : public tests::IoFixture, public tests::KeyChainFixture
 {
-public:
+protected:
   SegmentPublisherFixture()
-    : face(m_io, util::DummyClientFace::Options{true, true})
-    , publisher(face, keyChain)
   {
-    face.setInterestFilter(InterestFilter("/hello/world"),
-                           bind(&SegmentPublisherFixture::onInterest, this, _1, _2),
-                           [] (auto&&...) { BOOST_CHECK(false); });
+    m_face.setInterestFilter(InterestFilter("/hello/world"),
+                             bind(&SegmentPublisherFixture::onInterest, this, _1, _2),
+                             [] (auto&&...) { BOOST_CHECK(false); });
     advanceClocks(10_ms);
 
     for (int i = 0; i < 1000; ++i) {
@@ -58,7 +55,7 @@
   void
   expressInterest(const Interest& interest)
   {
-    fetcher = util::SegmentFetcher::start(face, interest, security::getAcceptAllValidator());
+    fetcher = util::SegmentFetcher::start(m_face, interest, security::getAcceptAllValidator());
     fetcher->onComplete.connect([this] (auto&&...) { numComplete++; });
     fetcher->onError.connect([] (auto&&...) { BOOST_CHECK(false); });
 
@@ -82,16 +79,17 @@
     }
   }
 
-  util::DummyClientFace face;
-  KeyChain keyChain;
-  SegmentPublisher publisher;
+protected:
+  util::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
+  SegmentPublisher publisher{m_face, m_keyChain};
   shared_ptr<util::SegmentFetcher> fetcher;
   Name dataName;
-  time::milliseconds freshness = 1_s;
   detail::State state;
 
   int numComplete = 0;
   int numRepliesFromStore = 0;
+
+  static constexpr time::milliseconds freshness = 1_s;
 };
 
 BOOST_FIXTURE_TEST_SUITE(TestSegmentPublisher, SegmentPublisherFixture)
@@ -120,10 +118,10 @@
   BOOST_CHECK_EQUAL(numRepliesFromStore, 2);
 
   numRepliesFromStore = 0;
-  face.expressInterest(Interest("/hello/world/").setCanBePrefix(true),
-                       [this] (auto&&...) { this->numComplete++; },
-                       [] (auto&&...) { BOOST_CHECK(false); },
-                       [] (auto&&...) { BOOST_CHECK(false); });
+  m_face.expressInterest(Interest("/hello/world/").setCanBePrefix(true),
+                         [this] (auto&&...) { this->numComplete++; },
+                         [] (auto&&...) { BOOST_CHECK(false); },
+                         [] (auto&&...) { BOOST_CHECK(false); });
   advanceClocks(10_ms);
   BOOST_CHECK_EQUAL(numComplete, 4);
   BOOST_CHECK_EQUAL(numRepliesFromStore, 1);