blob: 340c9ecc305173e84e7a68b3cee1114e6238c410 [file] [log] [blame]
Yanbiao Lidf846e52016-01-30 21:53:47 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "mgmt/nfd-manager-base.hpp"
27#include "manager-common-fixture.hpp"
28
29#include <ndn-cxx/security/key-chain.hpp>
30#include <ndn-cxx/management/nfd-control-command.hpp>
31
32namespace nfd {
33namespace tests {
34
35class NfdManagerBaseFixture : public ManagerCommonFixture
36{
37public:
38 NfdManagerBaseFixture()
39 : m_manager(m_dispatcher, m_validator, "test-module")
40 {
41 }
42
43protected:
44 CommandValidator m_validator;
45 NfdManagerBase m_manager;
46};
47
48BOOST_AUTO_TEST_SUITE(Mgmt)
49BOOST_FIXTURE_TEST_SUITE(TestNfdManagerBase, NfdManagerBaseFixture)
50
51BOOST_AUTO_TEST_CASE(AddSupportedPrivilegeInConstructor)
52{
53 BOOST_CHECK_NO_THROW(m_validator.addSupportedPrivilege("other-module"));
54 // test-module has already been added by the constructor of ManagerBase
55 BOOST_CHECK_THROW(m_validator.addSupportedPrivilege("test-module"), CommandValidator::Error);
56}
57
58BOOST_AUTO_TEST_CASE(CommandAuthorization)
59{
Junxiao Shi21738402016-08-19 19:48:00 +000060 ndn::mgmt::Authorization authorize = m_manager.makeAuthorization("test-verb");
61
Yanbiao Lidf846e52016-01-30 21:53:47 -080062 bool didAcceptCallbackFire = false;
63 bool didRejectCallbackFire = false;
64 auto testAuthorization = [&] {
65 didAcceptCallbackFire = false;
66 didRejectCallbackFire = false;
67
68 auto command = makeControlCommandRequest("/localhost/nfd/test-module/test-verb",
69 ControlParameters());
70 ndn::nfd::ControlParameters params;
Junxiao Shi21738402016-08-19 19:48:00 +000071 authorize("/top/prefix", *command, &params,
72 bind([&] { didAcceptCallbackFire = true; }),
73 bind([&] { didRejectCallbackFire = true; }));
Yanbiao Lidf846e52016-01-30 21:53:47 -080074 };
75
76 testAuthorization();
77 BOOST_CHECK(!didAcceptCallbackFire);
78 BOOST_CHECK(didRejectCallbackFire);
79
80 m_validator.addInterestRule("^<localhost><nfd><test-module>", *m_certificate);
81 testAuthorization();
82 BOOST_CHECK(didAcceptCallbackFire);
83 BOOST_CHECK(!didRejectCallbackFire);
84}
85
86BOOST_AUTO_TEST_SUITE_END() // TestNfdManagerBase
87BOOST_AUTO_TEST_SUITE_END() // Mgmt
88
89} // namespace tests
90} // namespace nfd