diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp index 9732bd2c..6cb5d573 100644 --- a/daemon/mgmt/strategy-choice-manager.cpp +++ b/daemon/mgmt/strategy-choice-manager.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2017, Regents of the University of California, +/* + * Copyright (c) 2014-2018, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -57,7 +57,7 @@ StrategyChoiceManager::setStrategy(ControlParameters parameters, StrategyChoice::InsertResult res = m_table.insert(prefix, strategy); if (!res) { NFD_LOG_DEBUG("strategy-choice/set(" << prefix << "," << strategy << "): cannot-create " << res); - return done(ControlResponse(404, boost::lexical_cast(res))); + return done(ControlResponse(res.getStatusCode(), boost::lexical_cast(res))); } NFD_LOG_DEBUG("strategy-choice/set(" << prefix << "," << strategy << "): OK"); diff --git a/daemon/table/strategy-choice.hpp b/daemon/table/strategy-choice.hpp index 8cfa93bb..5965ddc4 100644 --- a/daemon/table/strategy-choice.hpp +++ b/daemon/table/strategy-choice.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2017, Regents of the University of California, + * Copyright (c) 2014-2018, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -83,12 +83,20 @@ public: // Strategy Choice table return m_status == OK || m_status == EXCEPTION; } + /** \brief get a status code for use in management command response + */ + int + getStatusCode() const + { + return static_cast(m_status); + } + private: enum Status { - OK, - NOT_REGISTERED, - EXCEPTION, - DEPTH_EXCEEDED + OK = 200, + NOT_REGISTERED = 404, + EXCEPTION = 409, + DEPTH_EXCEEDED = 414, }; // implicitly constructible from Status diff --git a/tests/daemon/mgmt/strategy-choice-manager.t.cpp b/tests/daemon/mgmt/strategy-choice-manager.t.cpp index e0933e45..b4718a91 100644 --- a/tests/daemon/mgmt/strategy-choice-manager.t.cpp +++ b/tests/daemon/mgmt/strategy-choice-manager.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2017, Regents of the University of California, +/* + * Copyright (c) 2014-2018, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -120,6 +120,28 @@ BOOST_AUTO_TEST_CASE(SetUnknownStrategy) BOOST_CHECK_EQUAL(hasEntry("/A"), false); } +BOOST_AUTO_TEST_CASE(SetNameTooLong) +{ + Name prefix; + while (prefix.size() <= FIB_MAX_DEPTH) { + prefix.append("A"); + } + ControlParameters reqParams; + reqParams.setName(prefix) + .setStrategy(strategyNameP); + auto req = makeControlCommandRequest("/localhost/nfd/strategy-choice/set", reqParams); + receiveInterest(req); + + ControlResponse expectedResp; + expectedResp.setCode(414) + .setText("Prefix has too many components (limit is " + + to_string(NameTree::getMaxDepth()) + ")"); + BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), expectedResp), + CheckResponseResult::OK); + + BOOST_CHECK_EQUAL(hasEntry(prefix), false); +} + BOOST_AUTO_TEST_CASE(UnsetSuccess) { auto insertRes = sc.insert("/A", strategyNameP);