face+security: Introduce environment variables to set/override transport, pib, and tpm configurations.

- NDN_CLIENT_TRANSPORT: equivalent of transport in client.conf
- NDN_CLIENT_PIB: equivalent of pib in client.conf
- NDN_CLIENT_TPM: equivalent of tpm in client.conf

Whenever an environment variable is set, it takes precedence over any
values specified in the configuration file.

Change-Id: I44c2347168616387a0489b6bf5c2c3a12db29863
Refs: #2925, #2514
diff --git a/tests/unit-tests/face.t.cpp b/tests/unit-tests/face.t.cpp
index 5c8dda0..3a40320 100644
--- a/tests/unit-tests/face.t.cpp
+++ b/tests/unit-tests/face.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -24,6 +24,7 @@
 #include "security/key-chain.hpp"
 #include "util/dummy-client-face.hpp"
 #include "transport/tcp-transport.hpp"
+#include "transport/unix-transport.hpp"
 
 #include "boost-test.hpp"
 #include "unit-test-time-fixture.hpp"
@@ -612,7 +613,25 @@
   BOOST_CHECK(Face(transport, io, keyChain).getTransport() == transport);
 }
 
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_CASE(CustomizeTransportWithEnv)
+{
+  shared_ptr<Face> face;
+  BOOST_REQUIRE_NO_THROW(face = make_shared<Face>());
+  BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr);
 
-} // tests
+  setenv("NDN_CLIENT_TRANSPORT", "tcp://localhost:6363", true);
+  BOOST_REQUIRE_NO_THROW(face = make_shared<Face>());
+  BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr);
+  unsetenv("NDN_CLIENT_TRANSPORT");
+
+  setenv("NDN_CLIENT_TRANSPORT", "wrong-transport:", true);
+  BOOST_CHECK_THROW(face = make_shared<Face>(), ConfigFile::Error);
+  unsetenv("NDN_CLIENT_TRANSPORT");
+}
+
+/// @todo Tests to create Face using the config file
+
+BOOST_AUTO_TEST_SUITE_END() // TestFace
+
+} // namespace tests
 } // namespace ndn
diff --git a/tests/unit-tests/transport/tcp-transport.t.cpp b/tests/unit-tests/transport/tcp-transport.t.cpp
index c8aa461..3e9a99b 100644
--- a/tests/unit-tests/transport/tcp-transport.t.cpp
+++ b/tests/unit-tests/transport/tcp-transport.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -31,9 +31,7 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOk)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/ok");
-
-  const auto got = TcpTransport::getDefaultSocketHostAndPort(*m_config);
+  const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1:6000");
 
   BOOST_CHECK_EQUAL(got.first, "127.0.0.1");
   BOOST_CHECK_EQUAL(got.second, "6000");
@@ -41,22 +39,16 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMissingHost)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/"
-                   "bad-missing-host");
-
-  BOOST_CHECK_EXCEPTION(TcpTransport::getDefaultSocketHostAndPort(*m_config),
-                        ConfigFile::Error,
-                        [] (const ConfigFile::Error& error) {
+  BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp://:6000"),
+                        Transport::Error,
+                        [] (const Transport::Error& error) {
                           return error.what() == std::string("Malformed URI: tcp://:6000");
                         });
 }
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortOkOmittedPort)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/"
-                   "ok-omitted-port");
-
-  const auto got = TcpTransport::getDefaultSocketHostAndPort(*m_config);
+  const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://127.0.0.1");
 
   BOOST_CHECK_EQUAL(got.first, "127.0.0.1");
   BOOST_CHECK_EQUAL(got.second, "6363");
@@ -64,10 +56,7 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortNameOkOmittedHostOmittedPort)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/"
-                   "ok-omitted-host-omitted-port");
-
-  const auto got = TcpTransport::getDefaultSocketHostAndPort(*m_config);
+  const auto got = TcpTransport::getSocketHostAndPortFromUri("tcp://");
 
   BOOST_CHECK_EQUAL(got.first, "localhost");
   BOOST_CHECK_EQUAL(got.second, "6363");
@@ -75,10 +64,7 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadWrongTransport)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/"
-                   "bad-wrong-transport");
-
-  BOOST_CHECK_EXCEPTION(TcpTransport::getDefaultSocketHostAndPort(*m_config),
+  BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("unix://"),
                         Transport::Error,
                         [] (const Transport::Error& error) {
                           return error.what() == std::string("Cannot create TcpTransport "
@@ -88,12 +74,9 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketHostAndPortBadMalformedUri)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/tcp-transport/"
-                   "bad-malformed-uri");
-
-  BOOST_CHECK_EXCEPTION(TcpTransport::getDefaultSocketHostAndPort(*m_config),
-                        ConfigFile::Error,
-                        [] (const ConfigFile::Error& error) {
+  BOOST_CHECK_EXCEPTION(TcpTransport::getSocketHostAndPortFromUri("tcp"),
+                        Transport::Error,
+                        [] (const Transport::Error& error) {
                           return error.what() == std::string("Malformed URI: tcp");
                         });
 }
diff --git a/tests/unit-tests/transport/test-homes/tcp-transport/bad-malformed-uri/.ndn/client.conf b/tests/unit-tests/transport/test-homes/tcp-transport/bad-malformed-uri/.ndn/client.conf
deleted file mode 100644
index d4714da..0000000
--- a/tests/unit-tests/transport/test-homes/tcp-transport/bad-malformed-uri/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=tcp
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/tcp-transport/bad-missing-host/.ndn/client.conf b/tests/unit-tests/transport/test-homes/tcp-transport/bad-missing-host/.ndn/client.conf
deleted file mode 100644
index 7f7dd5e..0000000
--- a/tests/unit-tests/transport/test-homes/tcp-transport/bad-missing-host/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=tcp://:6000
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/tcp-transport/bad-wrong-transport/.ndn/client.conf b/tests/unit-tests/transport/test-homes/tcp-transport/bad-wrong-transport/.ndn/client.conf
deleted file mode 100644
index 7f8065a..0000000
--- a/tests/unit-tests/transport/test-homes/tcp-transport/bad-wrong-transport/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=unix://
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/tcp-transport/ok-omitted-host-omitted-port/.ndn/client.conf b/tests/unit-tests/transport/test-homes/tcp-transport/ok-omitted-host-omitted-port/.ndn/client.conf
deleted file mode 100644
index 182f47c..0000000
--- a/tests/unit-tests/transport/test-homes/tcp-transport/ok-omitted-host-omitted-port/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=tcp://
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/tcp-transport/ok-omitted-port/.ndn/client.conf b/tests/unit-tests/transport/test-homes/tcp-transport/ok-omitted-port/.ndn/client.conf
deleted file mode 100644
index 95b5ccc..0000000
--- a/tests/unit-tests/transport/test-homes/tcp-transport/ok-omitted-port/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=tcp://127.0.0.1
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/tcp-transport/ok/.ndn/client.conf b/tests/unit-tests/transport/test-homes/tcp-transport/ok/.ndn/client.conf
deleted file mode 100644
index 4c2d8c0..0000000
--- a/tests/unit-tests/transport/test-homes/tcp-transport/ok/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=tcp://127.0.0.1:6000
diff --git a/tests/unit-tests/transport/test-homes/unix-transport/bad-malformed-uri/.ndn/client.conf b/tests/unit-tests/transport/test-homes/unix-transport/bad-malformed-uri/.ndn/client.conf
deleted file mode 100644
index 427a2db..0000000
--- a/tests/unit-tests/transport/test-homes/unix-transport/bad-malformed-uri/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=unix
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/unix-transport/bad-wrong-transport/.ndn/client.conf b/tests/unit-tests/transport/test-homes/unix-transport/bad-wrong-transport/.ndn/client.conf
deleted file mode 100644
index 182f47c..0000000
--- a/tests/unit-tests/transport/test-homes/unix-transport/bad-wrong-transport/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=tcp://
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/unix-transport/ok-omitted-unix-socket-omitted-protocol/.ndn/client.conf b/tests/unit-tests/transport/test-homes/unix-transport/ok-omitted-unix-socket-omitted-protocol/.ndn/client.conf
deleted file mode 100644
index 2c4c027..0000000
--- a/tests/unit-tests/transport/test-homes/unix-transport/ok-omitted-unix-socket-omitted-protocol/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-; Empty client.conf is unfeasible in automated tests,
-; see tests/unit-tests/security/config-file-readme.txt.
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
\ No newline at end of file
diff --git a/tests/unit-tests/transport/test-homes/unix-transport/ok-omitted-unix-socket-with-protocol/.ndn/client.conf b/tests/unit-tests/transport/test-homes/unix-transport/ok-omitted-unix-socket-with-protocol/.ndn/client.conf
deleted file mode 100644
index 8fae7f5..0000000
--- a/tests/unit-tests/transport/test-homes/unix-transport/ok-omitted-unix-socket-with-protocol/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-protocol=nrd-0.1
diff --git a/tests/unit-tests/transport/test-homes/unix-transport/ok/.ndn/client.conf b/tests/unit-tests/transport/test-homes/unix-transport/ok/.ndn/client.conf
deleted file mode 100644
index ce8b950..0000000
--- a/tests/unit-tests/transport/test-homes/unix-transport/ok/.ndn/client.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-pib=pib-sqlite3:/tmp/test/ndn-cxx/keychain/sqlite3-empty/
-
-transport=unix:///tmp/test/nfd.sock
diff --git a/tests/unit-tests/transport/unix-transport.t.cpp b/tests/unit-tests/transport/unix-transport.t.cpp
index 83ae2b0..86bd7f3 100644
--- a/tests/unit-tests/transport/unix-transport.t.cpp
+++ b/tests/unit-tests/transport/unix-transport.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -31,33 +31,17 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOk)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/unix-transport/ok");
-
-  BOOST_CHECK_EQUAL(UnixTransport::getDefaultSocketName(*m_config), "/tmp/test/nfd.sock");
+  BOOST_CHECK_EQUAL(UnixTransport::getSocketNameFromUri("unix:///tmp/test/nfd.sock"), "/tmp/test/nfd.sock");
 }
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOkOmittedSocketOmittedProtocol)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/unix-transport/"
-                   "ok-omitted-unix-socket-omitted-protocol");
-
-  BOOST_CHECK_EQUAL(UnixTransport::getDefaultSocketName(*m_config), "/var/run/nfd.sock");
-}
-
-BOOST_AUTO_TEST_CASE(GetDefaultSocketNameOkOmittedSocketWithProtocol)
-{
-  initializeConfig("tests/unit-tests/transport/test-homes/unix-transport/"
-                   "ok-omitted-unix-socket-with-protocol");
-
-  BOOST_CHECK_EQUAL(UnixTransport::getDefaultSocketName(*m_config), "/var/run/nfd.sock");
+  BOOST_CHECK_EQUAL(UnixTransport::getSocketNameFromUri(""), "/var/run/nfd.sock");
 }
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketNameBadWrongTransport)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/unix-transport/"
-                   "bad-wrong-transport");
-
-  BOOST_CHECK_EXCEPTION(UnixTransport::getDefaultSocketName(*m_config),
+  BOOST_CHECK_EXCEPTION(UnixTransport::getSocketNameFromUri("tcp://"),
                         Transport::Error,
                         [] (const Transport::Error& error) {
                           return error.what() == std::string("Cannot create UnixTransport "
@@ -67,12 +51,9 @@
 
 BOOST_AUTO_TEST_CASE(GetDefaultSocketNameBadMalformedUri)
 {
-  initializeConfig("tests/unit-tests/transport/test-homes/unix-transport/"
-                   "bad-malformed-uri");
-
-  BOOST_CHECK_EXCEPTION(UnixTransport::getDefaultSocketName(*m_config),
-                        ConfigFile::Error,
-                        [] (const ConfigFile::Error& error) {
+  BOOST_CHECK_EXCEPTION(UnixTransport::getSocketNameFromUri("unix"),
+                        Transport::Error,
+                        [] (const Transport::Error& error) {
                           return error.what() == std::string("Malformed URI: unix");
                         });
 }