**breaking change**: Switch Face and related classes to v2::KeyChain

security::v2::KeyChain is now exposed as ndn::KeyChain, which should
ensure that dependent code can be mostly compiled.  However, expect code
that explicitly uses the old KeyChain interface to be broken.

Change-Id: I7330d0250d92f3f0f2570ab6d0214ab3dfdd18cc
Refs: #3098
diff --git a/tests/unit-tests/face.t.cpp b/tests/unit-tests/face.t.cpp
index 3f73f8a..8657613 100644
--- a/tests/unit-tests/face.t.cpp
+++ b/tests/unit-tests/face.t.cpp
@@ -36,7 +36,7 @@
 
 using ndn::util::DummyClientFace;
 
-class FaceFixture : public IdentityManagementV1TimeFixture
+class FaceFixture : public IdentityManagementTimeFixture
 {
 public:
   explicit
@@ -648,21 +648,18 @@
   const std::string PATH = "build/keys-with-default-tpm";
 };
 
-BOOST_FIXTURE_TEST_CASE(FaceTransport, PibDirFixture<PibDirWithDefaultTpm>)
+BOOST_FIXTURE_TEST_CASE(FaceTransport, IdentityManagementTimeFixture)
 {
-  KeyChain keyChain;
-  boost::asio::io_service io;
-
   BOOST_CHECK(Face().getTransport() != nullptr);
 
   BOOST_CHECK(Face(shared_ptr<Transport>()).getTransport() != nullptr);
   BOOST_CHECK(Face(shared_ptr<Transport>(), io).getTransport() != nullptr);
-  BOOST_CHECK(Face(shared_ptr<Transport>(), io, keyChain).getTransport() != nullptr);
+  BOOST_CHECK(Face(shared_ptr<Transport>(), io, m_keyChain).getTransport() != nullptr);
 
   auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled
   BOOST_CHECK(Face(transport).getTransport() == transport);
   BOOST_CHECK(Face(transport, io).getTransport() == transport);
-  BOOST_CHECK(Face(transport, io, keyChain).getTransport() == transport);
+  BOOST_CHECK(Face(transport, io, m_keyChain).getTransport() == transport);
 }
 
 class WithEnv : private IdentityManagementTimeFixture
diff --git a/tests/unit-tests/mgmt/dispatcher.t.cpp b/tests/unit-tests/mgmt/dispatcher.t.cpp
index 96623f5..6127ea0 100644
--- a/tests/unit-tests/mgmt/dispatcher.t.cpp
+++ b/tests/unit-tests/mgmt/dispatcher.t.cpp
@@ -34,7 +34,7 @@
 
 using namespace ndn::tests;
 
-class DispatcherFixture : public IdentityManagementV1TimeFixture
+class DispatcherFixture : public IdentityManagementTimeFixture
 {
 public:
   DispatcherFixture()
diff --git a/tests/unit-tests/mgmt/nfd/controller-fixture.hpp b/tests/unit-tests/mgmt/nfd/controller-fixture.hpp
index d64d77e..8f31f14 100644
--- a/tests/unit-tests/mgmt/nfd/controller-fixture.hpp
+++ b/tests/unit-tests/mgmt/nfd/controller-fixture.hpp
@@ -35,7 +35,7 @@
 
 using namespace ndn::tests;
 
-class ControllerFixture : public IdentityManagementV1TimeFixture
+class ControllerFixture : public IdentityManagementTimeFixture
 {
 protected:
   ControllerFixture()
@@ -45,8 +45,7 @@
     , datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2))
   {
     Name identityName("/localhost/ControllerFixture");
-    this->addIdentity(identityName);
-    m_keyChain.setDefaultIdentity(identityName);
+    m_keyChain.setDefaultIdentity(this->addIdentity(identityName));
   }
 
   /** \brief controls whether Controller's validator should accept or reject validation requests
diff --git a/tests/unit-tests/security/command-interest-validator.t.cpp b/tests/unit-tests/security/command-interest-validator.t.cpp
index cb01b36..e8c4eeb 100644
--- a/tests/unit-tests/security/command-interest-validator.t.cpp
+++ b/tests/unit-tests/security/command-interest-validator.t.cpp
@@ -20,6 +20,7 @@
  */
 
 #include "security/command-interest-validator.hpp"
+#include "security/command-interest-signer.hpp"
 #include "security/signing-helpers.hpp"
 
 #include "boost-test.hpp"
@@ -35,10 +36,11 @@
 
 using namespace ndn::tests;
 
-class CommandInterestValidatorFixture : public IdentityManagementV1TimeFixture
+class CommandInterestValidatorFixture : public IdentityManagementTimeFixture
 {
 protected:
   CommandInterestValidatorFixture()
+    : signer(m_keyChain)
   {
     this->initialize(CommandInterestValidator::Options{});
   }
@@ -63,10 +65,8 @@
   shared_ptr<Interest>
   makeCommandInterest(uint64_t identity = 0)
   {
-    auto interest = makeInterest("/CommandInterestPrefix");
-    m_keyChain.sign(*interest, signingByIdentity(makeIdentity(identity)));
-    BOOST_TEST_MESSAGE("makeCommandInterest " << interest->getName());
-    return interest;
+    auto interest = signer.makeCommandInterest("/CommandInterestPrefix", signingByIdentity(makeIdentity(identity)));
+    return make_shared<Interest>(std::move(interest));
   }
 
   /** \brief check that validator accepts interest
@@ -75,7 +75,6 @@
   void
   assertAccept(const Interest& interest)
   {
-    BOOST_TEST_MESSAGE("assertAccept " << interest.getName());
     int nAccepts = 0;
     validator->validate(interest,
       [&nAccepts] (const shared_ptr<const Interest>&) { ++nAccepts; },
@@ -93,7 +92,6 @@
   void
   assertReject(const Interest& interest, CommandInterestValidator::ErrorCode error)
   {
-    BOOST_TEST_MESSAGE("assertReject " << interest.getName());
     int nRejects = 0;
     validator->validate(interest,
       [] (const shared_ptr<const Interest>&) {
@@ -109,6 +107,7 @@
   }
 
 protected:
+  CommandInterestSigner signer;
   DummyValidator* inner;
   unique_ptr<CommandInterestValidator> validator;
 };
diff --git a/tests/unit-tests/security/v2/key-chain.t.cpp b/tests/unit-tests/security/v2/key-chain.t.cpp
index 4eaf75e..d1a954c 100644
--- a/tests/unit-tests/security/v2/key-chain.t.cpp
+++ b/tests/unit-tests/security/v2/key-chain.t.cpp
@@ -47,6 +47,12 @@
     unsetenv("NDN_CLIENT_PIB");
     unsetenv("NDN_CLIENT_TPM");
   }
+
+  ~TestHomeAndPibFixture()
+  {
+    const_cast<std::string&>(KeyChain::getDefaultPibLocator()).clear();
+    const_cast<std::string&>(KeyChain::getDefaultTpmLocator()).clear();
+  }
 };
 
 struct PibPathConfigFileHome
diff --git a/tests/unit-tests/security/validator-config.t.cpp b/tests/unit-tests/security/validator-config.t.cpp
index 14ed721..74c29ae 100644
--- a/tests/unit-tests/security/validator-config.t.cpp
+++ b/tests/unit-tests/security/validator-config.t.cpp
@@ -49,12 +49,14 @@
 {
 public:
   ValidatorConfigFixture()
-    : face(nullptr, m_keyChain)
+    : m_v2KeyChain("pib-memory:", "tpm-memory:")
+    , face(nullptr, m_v2KeyChain)
     , validator(face)
   {
   }
 
 public:
+  v2::KeyChain m_v2KeyChain;
   Face face;
   ValidatorConfig validator;
 };
@@ -1078,8 +1080,8 @@
 struct FacesFixture : public ValidatorConfigFixture
 {
   FacesFixture()
-    : face1(io, m_keyChain, {true, true})
-    , face2(io, m_keyChain, {true, true})
+    : face1(io, m_v2KeyChain, {true, true})
+    , face2(io, m_v2KeyChain, {true, true})
     , readInterestOffset1(0)
     , readDataOffset1(0)
     , readInterestOffset2(0)
@@ -1486,11 +1488,11 @@
   advanceClocks(time::milliseconds(10), 20);
 }
 
-class DirectCertFetchFixture : public IdentityManagementV1TimeFixture
+class DirectCertFetchFixture : public ValidatorConfigFixture
 {
 public:
   DirectCertFetchFixture()
-    : clientFace(io, m_keyChain, {true, true})
+    : clientFace(io, m_v2KeyChain, {true, true})
     , validationResult(boost::logic::indeterminate)
   {
     auto certName = addIdentity(ca);
diff --git a/tests/unit-tests/util/dummy-client-face.t.cpp b/tests/unit-tests/util/dummy-client-face.t.cpp
index 2e7368d..809034d 100644
--- a/tests/unit-tests/util/dummy-client-face.t.cpp
+++ b/tests/unit-tests/util/dummy-client-face.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "util/dummy-client-face.hpp"
 
 #include "boost-test.hpp"
+#include "../identity-management-time-fixture.hpp"
 
 namespace ndn {
 namespace util {
@@ -30,7 +31,7 @@
 BOOST_AUTO_TEST_SUITE(Util)
 BOOST_AUTO_TEST_SUITE(TestDummyClientFace)
 
-BOOST_AUTO_TEST_CASE(ProcessEventsOverride)
+BOOST_FIXTURE_TEST_CASE(ProcessEventsOverride, ndn::tests::IdentityManagementTimeFixture)
 {
   bool isOverrideInvoked = false;
   auto override = [&] (time::milliseconds timeout) {
@@ -38,7 +39,7 @@
     BOOST_CHECK_EQUAL(timeout, time::milliseconds(200));
   };
 
-  DummyClientFace face({false, false, override});
+  DummyClientFace face(io, {false, false, override});
   face.processEvents(time::milliseconds(200));
   BOOST_CHECK(isOverrideInvoked);
 }
diff --git a/tests/unit-tests/util/notification-stream.t.cpp b/tests/unit-tests/util/notification-stream.t.cpp
index 3697c41..faedec8 100644
--- a/tests/unit-tests/util/notification-stream.t.cpp
+++ b/tests/unit-tests/util/notification-stream.t.cpp
@@ -37,7 +37,7 @@
 namespace tests {
 
 BOOST_AUTO_TEST_SUITE(Util)
-BOOST_FIXTURE_TEST_SUITE(TestNotificationStream, ndn::tests::IdentityManagementV1TimeFixture)
+BOOST_FIXTURE_TEST_SUITE(TestNotificationStream, ndn::tests::IdentityManagementTimeFixture)
 
 BOOST_AUTO_TEST_CASE(Post)
 {
diff --git a/tests/unit-tests/util/notification-subscriber.t.cpp b/tests/unit-tests/util/notification-subscriber.t.cpp
index e7144e9..30924f3 100644
--- a/tests/unit-tests/util/notification-subscriber.t.cpp
+++ b/tests/unit-tests/util/notification-subscriber.t.cpp
@@ -39,7 +39,7 @@
 
 using namespace ndn::tests;
 
-class NotificationSubscriberFixture : public IdentityManagementV1TimeFixture
+class NotificationSubscriberFixture : public IdentityManagementTimeFixture
 {
 public:
   NotificationSubscriberFixture()
diff --git a/tests/unit-tests/util/segment-fetcher.t.cpp b/tests/unit-tests/util/segment-fetcher.t.cpp
index 6d9ea36..02ef85b 100644
--- a/tests/unit-tests/util/segment-fetcher.t.cpp
+++ b/tests/unit-tests/util/segment-fetcher.t.cpp
@@ -40,7 +40,7 @@
 BOOST_AUTO_TEST_SUITE(Util)
 BOOST_AUTO_TEST_SUITE(TestSegmentFetcher)
 
-class Fixture : public IdentityManagementV1TimeFixture
+class Fixture : public IdentityManagementTimeFixture
 {
 public:
   Fixture()