mgmt: respond Nack when query is invalid

refs #1993

Change-Id: I21e398cd7b2e562b7dc759a89f6e668960e72c41
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index daba08e..712d096 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -1158,7 +1158,7 @@
       !FACES_QUERY_DATASET_PREFIX.isPrefixOf(query))
     {
       NFD_LOG_DEBUG("query result: malformed");
-      //sendNack(query);
+      sendNack(query);
       return;
     }
 
@@ -1170,7 +1170,7 @@
   catch (tlv::Error&)
     {
       NFD_LOG_DEBUG("query result: malformed filter");
-      //sendNack(query);
+      sendNack(query);
       return;
     }
 
diff --git a/daemon/mgmt/manager-base.cpp b/daemon/mgmt/manager-base.cpp
index da553a5..cf75d04 100644
--- a/daemon/mgmt/manager-base.cpp
+++ b/daemon/mgmt/manager-base.cpp
@@ -99,21 +99,20 @@
   m_face->put(*responseData);
 }
 
-// for future commit
-//void
-//ManagerBase::sendNack(const Name& name)
-//{
-//  NFD_LOG_DEBUG("responding NACK to " << name);
-//
-//  ndn::MetaInfo meta;
-//  meta.setType(ndn::tlv::ContentType_Nack);
-//
-//  shared_ptr<Data> responseData(make_shared<Data>(name));
-//  responseData->setMetaInfo(meta);
-//
-//  m_keyChain.sign(*responseData);
-//  m_face->put(*responseData);
-//}
+void
+ManagerBase::sendNack(const Name& name)
+{
+  NFD_LOG_DEBUG("responding NACK to " << name);
+
+  ndn::MetaInfo meta;
+  meta.setType(tlv::ContentType_Nack);
+
+  shared_ptr<Data> responseData(make_shared<Data>(name));
+  responseData->setMetaInfo(meta);
+
+  m_keyChain.sign(*responseData);
+  m_face->put(*responseData);
+}
 
 bool
 ManagerBase::validateParameters(const ControlCommand& command,
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
index feaa54a..1611615 100644
--- a/daemon/mgmt/manager-base.hpp
+++ b/daemon/mgmt/manager-base.hpp
@@ -94,8 +94,8 @@
                const std::string& text,
                const Block& body);
 
-  //void
-  //sendNack(const Name& name);
+  void
+  sendNack(const Name& name);
 
   virtual bool
   validateParameters(const ControlCommand& command,
diff --git a/tests/daemon/mgmt/face-manager.cpp b/tests/daemon/mgmt/face-manager.cpp
index 966844a..2b2a15e 100644
--- a/tests/daemon/mgmt/face-manager.cpp
+++ b/tests/daemon/mgmt/face-manager.cpp
@@ -1813,23 +1813,23 @@
   BOOST_REQUIRE(m_finished);
 }
 
-//BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture)
-//{
-//  Name queryName("/localhost/nfd/faces/query");
-//  ndn::nfd::FaceStatus queryFilter;
-//  queryName.append(queryFilter.wireEncode());
-//
-//  shared_ptr<Interest> query(make_shared<Interest>(queryName));
-//
-//  shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>());
-//  add(face);
-//
-//  m_face->onReceiveData +=
-//    bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1);
-//
-//  m_manager.listQueriedFaces(*query);
-//  BOOST_REQUIRE(m_finished);
-//}
+BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture)
+{
+  Name queryName("/localhost/nfd/faces/query");
+  ndn::nfd::FaceStatus queryFilter;
+  queryName.append(queryFilter.wireEncode());
+
+  shared_ptr<Interest> query(make_shared<Interest>(queryName));
+
+  shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>());
+  add(face);
+
+  m_face->onReceiveData +=
+    bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1);
+
+  m_manager.listQueriedFaces(*query);
+  BOOST_REQUIRE(m_finished);
+}
 
 BOOST_AUTO_TEST_SUITE_END()
 
diff --git a/tests/daemon/mgmt/face-query-status-publisher-common.hpp b/tests/daemon/mgmt/face-query-status-publisher-common.hpp
index a0e4070..a274c52 100644
--- a/tests/daemon/mgmt/face-query-status-publisher-common.hpp
+++ b/tests/daemon/mgmt/face-query-status-publisher-common.hpp
@@ -133,13 +133,13 @@
     m_finished = true;
   }
 
-  //void
-  //decodeNackBlock(const Data& data)
-  //{
-  //  BOOST_REQUIRE_EQUAL(data.getContentType(), ndn::tlv::ContentType_Nack);
+  void
+  decodeNackBlock(const Data& data)
+  {
+    BOOST_REQUIRE_EQUAL(data.getContentType(), tlv::ContentType_Nack);
 
-  //  m_finished = true;
-  //}
+    m_finished = true;
+  }
 
 protected:
   Forwarder m_forwarder;