blob: 410f41ca9c79500caebdf404e0136fd14d47c7e7 [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{
60 bool didAcceptCallbackFire = false;
61 bool didRejectCallbackFire = false;
62 auto testAuthorization = [&] {
63 didAcceptCallbackFire = false;
64 didRejectCallbackFire = false;
65
66 auto command = makeControlCommandRequest("/localhost/nfd/test-module/test-verb",
67 ControlParameters());
68 ndn::nfd::ControlParameters params;
69 m_manager.authorize("/top/prefix", *command, &params,
70 bind([&] { didAcceptCallbackFire = true; }),
71 bind([&] { didRejectCallbackFire = true; }));
72 };
73
74 testAuthorization();
75 BOOST_CHECK(!didAcceptCallbackFire);
76 BOOST_CHECK(didRejectCallbackFire);
77
78 m_validator.addInterestRule("^<localhost><nfd><test-module>", *m_certificate);
79 testAuthorization();
80 BOOST_CHECK(didAcceptCallbackFire);
81 BOOST_CHECK(!didRejectCallbackFire);
82}
83
84BOOST_AUTO_TEST_SUITE_END() // TestNfdManagerBase
85BOOST_AUTO_TEST_SUITE_END() // Mgmt
86
87} // namespace tests
88} // namespace nfd