face: change default Unix socket path

Refs: #5304
Change-Id: I5c7415874131b156e54a655960d9de47c1eae91d
diff --git a/tests/daemon/face/unix-stream-factory.t.cpp b/tests/daemon/face/unix-stream-factory.t.cpp
index 53a8687..1f0a62f 100644
--- a/tests/daemon/face/unix-stream-factory.t.cpp
+++ b/tests/daemon/face/unix-stream-factory.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2023,  Regents of the University of California,
+ * Copyright (c) 2014-2024,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,21 +28,18 @@
 #include "face-system-fixture.hpp"
 #include "factory-test-common.hpp"
 
+#include <boost/filesystem.hpp>
+
 namespace nfd::tests {
 
-using face::UnixStreamFactory;
-
-using UnixStreamFactoryFixture = FaceSystemFactoryFixture<UnixStreamFactory>;
+using UnixStreamFactoryFixture = FaceSystemFactoryFixture<face::UnixStreamFactory>;
 
 BOOST_AUTO_TEST_SUITE(Face)
 BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, UnixStreamFactoryFixture)
 
-const std::string CHANNEL_PATH1("unix-stream-test.1.sock");
-const std::string CHANNEL_PATH2("unix-stream-test.2.sock");
-
 BOOST_AUTO_TEST_SUITE(ProcessConfig)
 
-BOOST_AUTO_TEST_CASE(Normal)
+BOOST_AUTO_TEST_CASE(AbsolutePath)
 {
   const std::string CONFIG = R"CONFIG(
     face_system
@@ -58,9 +55,40 @@
   parseConfig(CONFIG, false);
 
   BOOST_REQUIRE_EQUAL(factory.getChannels().size(), 1);
+  BOOST_TEST(factory.getChannels().front()->isListening());
+
   const auto& uri = factory.getChannels().front()->getUri();
-  BOOST_CHECK_EQUAL(uri.getScheme(), "unix");
-  BOOST_CHECK_NE(uri.getPath().find("nfd-test.sock"), std::string::npos);
+  BOOST_TEST(uri.getScheme() == "unix");
+  boost::filesystem::path path(uri.getPath());
+  BOOST_TEST(path.filename() == "nfd-test.sock");
+  BOOST_TEST(boost::filesystem::canonical(path) == path); // path should already be in canonical form
+  BOOST_TEST(boost::filesystem::equivalent(path, "/tmp/nfd-test.sock"));
+}
+
+BOOST_AUTO_TEST_CASE(RelativePath)
+{
+  const std::string CONFIG = R"CONFIG(
+    face_system
+    {
+      unix
+      {
+        path nfd-test.sock
+      }
+    }
+  )CONFIG";
+
+  parseConfig(CONFIG, true);
+  parseConfig(CONFIG, false);
+
+  BOOST_REQUIRE_EQUAL(factory.getChannels().size(), 1);
+  BOOST_TEST(factory.getChannels().front()->isListening());
+
+  const auto& uri = factory.getChannels().front()->getUri();
+  BOOST_TEST(uri.getScheme() == "unix");
+  boost::filesystem::path path(uri.getPath());
+  BOOST_TEST(path.filename() == "nfd-test.sock");
+  BOOST_TEST(boost::filesystem::canonical(path) == path); // path should already be in canonical form
+  BOOST_TEST(boost::filesystem::equivalent(path, "nfd-test.sock"));
 }
 
 BOOST_AUTO_TEST_CASE(Omitted)
@@ -95,6 +123,9 @@
 
 BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
 
+const std::string CHANNEL_PATH1("unix-stream-test.1.sock");
+const std::string CHANNEL_PATH2("unix-stream-test.2.sock");
+
 BOOST_AUTO_TEST_CASE(GetChannels)
 {
   BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
@@ -107,16 +138,24 @@
 
 BOOST_AUTO_TEST_CASE(CreateChannel)
 {
-  auto channel1 = factory.createChannel(CHANNEL_PATH1);
+  auto channel1 = factory.createChannel("./" + CHANNEL_PATH1); // test path normalization
   auto channel1a = factory.createChannel(CHANNEL_PATH1);
+  auto channel1b = factory.createChannel(boost::filesystem::absolute(CHANNEL_PATH1).string());
+  auto channel1c = factory.createChannel("foo//../" + CHANNEL_PATH1);
   BOOST_CHECK_EQUAL(channel1, channel1a);
+  BOOST_CHECK_EQUAL(channel1, channel1b);
+  BOOST_CHECK_EQUAL(channel1, channel1c);
   BOOST_CHECK_EQUAL(factory.getChannels().size(), 1);
 
   const auto& uri = channel1->getUri();
+  BOOST_TEST_INFO_SCOPE(uri);
   BOOST_CHECK_EQUAL(uri.getScheme(), "unix");
   BOOST_CHECK_EQUAL(uri.getHost(), "");
   BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath().rfind(CHANNEL_PATH1), uri.getPath().size() - CHANNEL_PATH1.size());
+  boost::filesystem::path path1(uri.getPath());
+  BOOST_TEST(path1.filename() == CHANNEL_PATH1);
+  BOOST_TEST(path1.is_absolute()); // path should always be absolute
+  BOOST_TEST(path1.lexically_normal() == path1); // path should be in normal form
 
   auto channel2 = factory.createChannel(CHANNEL_PATH2);
   BOOST_CHECK_NE(channel1, channel2);