mgmt: Allow only canonical FaceUri in faces/create command
refs #1910
Change-Id: I89a84cd8584d5a718bcc85db05cc337b4b4f8f73
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 6a7bb1e..f5d849b 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -957,6 +957,13 @@
return;
}
+ if (!uri.isCanonical())
+ {
+ sendResponse(requestName, 400, "Non-canonical URI");
+ NFD_LOG_TRACE("received non-canonical URI");
+ return;
+ }
+
FactoryMap::iterator factory = m_factories.find(uri.getScheme());
if (factory == m_factories.end())
{
diff --git a/tests/daemon/mgmt/face-manager.cpp b/tests/daemon/mgmt/face-manager.cpp
index 000a0d6..047f00c 100644
--- a/tests/daemon/mgmt/face-manager.cpp
+++ b/tests/daemon/mgmt/face-manager.cpp
@@ -823,7 +823,7 @@
BOOST_AUTO_TEST_CASE(UnsignedCommand)
{
ControlParameters parameters;
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -845,7 +845,7 @@
BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>)
{
ControlParameters parameters;
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -977,7 +977,7 @@
AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
{
ControlParameters parameters;
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -996,7 +996,7 @@
AuthorizedCommandFixture<ValidatedFaceRequestFixture>)
{
ControlParameters parameters;
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -1503,7 +1503,7 @@
BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>)
{
ControlParameters parameters;
- parameters.setUri("tcp:/127.0.0.1");
+ parameters.setUri("tcp4:/127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -1522,6 +1522,28 @@
BOOST_REQUIRE(didCallbackFire());
}
+BOOST_FIXTURE_TEST_CASE(CreateFaceNoncanonicalUri, AuthorizedCommandFixture<FaceFixture>)
+{
+ ControlParameters parameters;
+ parameters.setUri("tcp://127.0.0.1");
+
+ Block encodedParameters(parameters.wireEncode());
+
+ Name commandName("/localhost/nfd/faces");
+ commandName.append("create");
+ commandName.append(encodedParameters);
+
+ shared_ptr<Interest> command(make_shared<Interest>(commandName));
+ generateCommand(*command);
+
+ getFace()->onReceiveData += [this, command] (const Data& response) {
+ this->validateControlResponse(response, command->getName(), 400, "Non-canonical URI");
+ };
+
+ createFace(*command, parameters);
+
+ BOOST_REQUIRE(didCallbackFire());
+}
BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>)
{
@@ -1550,7 +1572,7 @@
ControlParameters parameters;
// this will be an unsupported protocol because no factories have been
// added to the face manager
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -1573,7 +1595,7 @@
BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>)
{
ControlParameters parameters;
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());
@@ -1615,7 +1637,7 @@
BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>)
{
ControlParameters parameters;
- parameters.setUri("tcp://127.0.0.1");
+ parameters.setUri("tcp4://127.0.0.1:6363");
Block encodedParameters(parameters.wireEncode());