Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "mgmt/local-control-header-manager.hpp" |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 8 | #include "mgmt/internal-face.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 9 | #include "tests/face/dummy-face.hpp" |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 10 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 11 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 12 | #include "validation-common.hpp" |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 13 | |
| 14 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 15 | namespace tests { |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 16 | |
| 17 | NFD_LOG_INIT("LocalControlHeaderManagerTest"); |
| 18 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 19 | class LocalControlHeaderManagerFixture : protected BaseFixture |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 20 | { |
| 21 | public: |
| 22 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 23 | shared_ptr<Face> |
| 24 | getFace(FaceId id) |
| 25 | { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 26 | if (id > 0 && static_cast<size_t>(id) <= m_faces.size()) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 27 | { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | return m_faces[id - 1]; |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 29 | } |
| 30 | NFD_LOG_DEBUG("No face found returning NULL"); |
| 31 | return shared_ptr<DummyFace>(); |
| 32 | } |
| 33 | |
| 34 | void |
| 35 | addFace(shared_ptr<Face> face) |
| 36 | { |
| 37 | m_faces.push_back(face); |
| 38 | } |
| 39 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 40 | shared_ptr<InternalFace> |
| 41 | getInternalFace() |
| 42 | { |
| 43 | return m_face; |
| 44 | } |
| 45 | |
| 46 | LocalControlHeaderManager& |
| 47 | getManager() |
| 48 | { |
| 49 | return m_manager; |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | addInterestRule(const std::string& regex, |
| 54 | ndn::IdentityCertificate& certificate) |
| 55 | { |
| 56 | m_manager.addInterestRule(regex, certificate); |
| 57 | } |
| 58 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 59 | void |
| 60 | validateControlResponse(const Data& response, |
| 61 | const Name& expectedName, |
| 62 | uint32_t expectedCode, |
| 63 | const std::string& expectedText) |
| 64 | { |
| 65 | m_callbackFired = true; |
| 66 | |
| 67 | ControlResponse control; |
| 68 | Block controlRaw = response.getContent().blockFromValue(); |
| 69 | |
| 70 | control.wireDecode(controlRaw); |
| 71 | |
| 72 | NFD_LOG_DEBUG("received control response" |
| 73 | << " Name: " << response.getName() |
| 74 | << " code: " << control.getCode() |
| 75 | << " text: " << control.getText()); |
| 76 | |
| 77 | BOOST_CHECK_EQUAL(response.getName(), expectedName); |
| 78 | BOOST_CHECK_EQUAL(control.getCode(), expectedCode); |
| 79 | BOOST_CHECK_EQUAL(control.getText(), expectedText); |
| 80 | |
| 81 | if (!control.getBody().empty()) |
| 82 | { |
| 83 | BOOST_FAIL("found unexpected control response body"); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | bool |
| 88 | didCallbackFire() |
| 89 | { |
| 90 | return m_callbackFired; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | resetCallbackFired() |
| 95 | { |
| 96 | m_callbackFired = false; |
| 97 | } |
| 98 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 99 | protected: |
| 100 | LocalControlHeaderManagerFixture() |
| 101 | : m_face(make_shared<InternalFace>()), |
| 102 | m_manager(bind(&LocalControlHeaderManagerFixture::getFace, this, _1), |
| 103 | m_face), |
| 104 | m_callbackFired(false) |
| 105 | { |
| 106 | } |
| 107 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 108 | private: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 109 | shared_ptr<InternalFace> m_face; |
| 110 | LocalControlHeaderManager m_manager; |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 111 | std::vector<shared_ptr<Face> > m_faces; |
| 112 | bool m_callbackFired; |
| 113 | }; |
| 114 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 115 | template <typename T> class AuthorizedCommandFixture: |
| 116 | public CommandFixture<T> |
| 117 | { |
| 118 | public: |
| 119 | AuthorizedCommandFixture() |
| 120 | { |
| 121 | const std::string regex = "^<localhost><nfd><control-header>"; |
| 122 | T::addInterestRule(regex, *CommandFixture<T>::m_certificate); |
| 123 | } |
| 124 | |
| 125 | virtual |
| 126 | ~AuthorizedCommandFixture() |
| 127 | { |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | BOOST_FIXTURE_TEST_SUITE(MgmtLocalControlHeaderManager, |
| 132 | AuthorizedCommandFixture<LocalControlHeaderManagerFixture>) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 133 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 134 | BOOST_AUTO_TEST_CASE(InFaceId) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 135 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 136 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 137 | addFace(dummy); |
| 138 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 139 | Name enable("/localhost/nfd/control-header/in-faceid/enable"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 140 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 141 | enableCommand->setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 142 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 143 | generateCommand(*enableCommand); |
| 144 | |
| 145 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 146 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 147 | enableCommand->getName(), 200, "Success"); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 148 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 149 | getManager().onLocalControlHeaderRequest(*enableCommand); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 150 | |
| 151 | BOOST_REQUIRE(didCallbackFire()); |
| 152 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 153 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 154 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 155 | getInternalFace()->onReceiveData.clear(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 156 | resetCallbackFired(); |
| 157 | |
| 158 | Name disable("/localhost/nfd/control-header/in-faceid/disable"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 159 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 160 | disableCommand->setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 161 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 162 | generateCommand(*disableCommand); |
| 163 | |
| 164 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 165 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 166 | disableCommand->getName(), 200, "Success"); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 167 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 168 | getManager().onLocalControlHeaderRequest(*disableCommand); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 169 | |
| 170 | BOOST_REQUIRE(didCallbackFire()); |
| 171 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 172 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 173 | } |
| 174 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 175 | BOOST_AUTO_TEST_CASE(NextHopFaceId) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 176 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 177 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 178 | addFace(dummy); |
| 179 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 180 | Name enable("/localhost/nfd/control-header/nexthop-faceid/enable"); |
| 181 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 182 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 183 | enableCommand->setIncomingFaceId(1); |
| 184 | generateCommand(*enableCommand); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 185 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 186 | getInternalFace()->onReceiveData += |
| 187 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 188 | enableCommand->getName(), 200, "Success"); |
| 189 | |
| 190 | getManager().onLocalControlHeaderRequest(*enableCommand); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 191 | |
| 192 | BOOST_REQUIRE(didCallbackFire()); |
| 193 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 194 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 195 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 196 | getInternalFace()->onReceiveData.clear(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 197 | resetCallbackFired(); |
| 198 | |
| 199 | Name disable("/localhost/nfd/control-header/nexthop-faceid/disable"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 200 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 201 | disableCommand->setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 202 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 203 | generateCommand(*disableCommand); |
| 204 | |
| 205 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 206 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 207 | disableCommand->getName(), 200, "Success"); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 208 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 209 | getManager().onLocalControlHeaderRequest(*disableCommand); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 210 | |
| 211 | BOOST_REQUIRE(didCallbackFire()); |
| 212 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 213 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 214 | } |
| 215 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 216 | BOOST_AUTO_TEST_CASE(ShortCommand) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 217 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 218 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 219 | addFace(dummy); |
| 220 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 221 | Name commandName("/localhost/nfd/control-header"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 222 | Interest command(commandName); |
| 223 | command.setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 224 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 225 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 226 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 227 | commandName, 400, "Malformed command"); |
| 228 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 229 | getManager().onLocalControlHeaderRequest(command); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 230 | |
| 231 | BOOST_REQUIRE(didCallbackFire()); |
| 232 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 233 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 234 | } |
| 235 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 236 | BOOST_AUTO_TEST_CASE(ShortCommandModule) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 237 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 238 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 239 | addFace(dummy); |
| 240 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 241 | Name commandName("/localhost/nfd/control-header/in-faceid"); |
| 242 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 243 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 244 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 245 | commandName, 400, "Malformed command"); |
| 246 | |
| 247 | Interest command(commandName); |
| 248 | command.setIncomingFaceId(1); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 249 | getManager().onLocalControlHeaderRequest(command); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 250 | |
| 251 | BOOST_REQUIRE(didCallbackFire()); |
| 252 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 253 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 254 | } |
| 255 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 256 | BOOST_AUTO_TEST_CASE(UnsupportedModule) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 257 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 258 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 259 | addFace(dummy); |
| 260 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 261 | Name commandName("/localhost/nfd/control-header/madeup/moremadeup"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 262 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 263 | command->setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 264 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 265 | generateCommand(*command); |
| 266 | |
| 267 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 268 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 269 | command->getName(), 501, "Unsupported"); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 270 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 271 | getManager().onLocalControlHeaderRequest(*command); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 272 | |
| 273 | BOOST_REQUIRE(didCallbackFire()); |
| 274 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 275 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 276 | } |
| 277 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 278 | BOOST_AUTO_TEST_CASE(InFaceIdUnsupportedVerb) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 279 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 280 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 281 | addFace(dummy); |
| 282 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 283 | Name commandName("/localhost/nfd/control-header/in-faceid/madeup"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 284 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 285 | command->setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 286 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 287 | |
| 288 | generateCommand(*command); |
| 289 | |
| 290 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 291 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 292 | command->getName(), 501, "Unsupported"); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 293 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 294 | getManager().onLocalControlHeaderRequest(*command); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 295 | |
| 296 | BOOST_REQUIRE(didCallbackFire()); |
| 297 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 298 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 299 | } |
| 300 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 301 | BOOST_AUTO_TEST_CASE(NextHopFaceIdUnsupportedVerb) |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 302 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 303 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 304 | addFace(dummy); |
| 305 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 306 | Name commandName("/localhost/nfd/control-header/nexthop-faceid/madeup"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 307 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 308 | command->setIncomingFaceId(1); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 309 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 310 | generateCommand(*command); |
| 311 | |
| 312 | getInternalFace()->onReceiveData += |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 313 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 314 | command->getName(), 501, "Unsupported"); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 315 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 316 | getManager().onLocalControlHeaderRequest(*command); |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 317 | |
| 318 | BOOST_REQUIRE(didCallbackFire()); |
| 319 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 320 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 321 | } |
| 322 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 323 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, |
| 324 | UnauthorizedCommandFixture<LocalControlHeaderManagerFixture>) |
| 325 | { |
| 326 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 327 | addFace(dummy); |
| 328 | |
| 329 | Name enable("/localhost/nfd/control-header/in-faceid/enable"); |
| 330 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 331 | enableCommand->setIncomingFaceId(1); |
| 332 | |
| 333 | generateCommand(*enableCommand); |
| 334 | |
| 335 | getInternalFace()->onReceiveData += |
| 336 | bind(&LocalControlHeaderManagerFixture::validateControlResponse, this, _1, |
| 337 | enableCommand->getName(), 403, "Unauthorized command"); |
| 338 | |
| 339 | getManager().onLocalControlHeaderRequest(*enableCommand); |
| 340 | |
| 341 | BOOST_REQUIRE(didCallbackFire()); |
| 342 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 343 | } |
| 344 | |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 345 | BOOST_AUTO_TEST_SUITE_END() |
| 346 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 347 | } // namespace tests |
Steve DiBenedetto | 471c060 | 2014-02-18 12:32:00 -0700 | [diff] [blame] | 348 | } // namespace nfd |