blob: 77c7620f9e9b8ed709af2bf5c13969a9cb0883d6 [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -08002/*
Alexander Afanasyev09236c22020-06-03 13:42:38 -04003 * Copyright (c) 2013-2020 Regents of the University of California.
Junxiao Shi034c1882016-06-24 18:06:51 +00004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050022#ifndef NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP
23#define NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP
Junxiao Shi034c1882016-06-24 18:06:51 +000024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/mgmt/nfd/controller.hpp"
Alexander Afanasyev09236c22020-06-03 13:42:38 -040026#include "ndn-cxx/security/certificate-fetcher-offline.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050027#include "ndn-cxx/util/dummy-client-face.hpp"
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000028
Davide Pesavento7e780642018-11-24 15:51:34 -050029#include "tests/unit/dummy-validator.hpp"
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050030#include "tests/unit/io-key-chain-fixture.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000031
32namespace ndn {
33namespace nfd {
34namespace tests {
35
36using namespace ndn::tests;
37
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050038class ControllerFixture : public IoKeyChainFixture
Junxiao Shi034c1882016-06-24 18:06:51 +000039{
40protected:
41 ControllerFixture()
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050042 : face(m_io, m_keyChain)
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080043 , m_validator(true)
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000044 , controller(face, m_keyChain, m_validator)
Junxiao Shie7c7f152016-08-20 22:36:22 +000045 , commandFailCallback(bind(&ControllerFixture::recordCommandFail, this, _1))
46 , datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2))
Junxiao Shi034c1882016-06-24 18:06:51 +000047 {
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050048 m_keyChain.setDefaultIdentity(m_keyChain.createIdentity("/localhost/ControllerFixture"));
Junxiao Shi034c1882016-06-24 18:06:51 +000049 }
50
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000051 /** \brief controls whether Controller's validator should accept or reject validation requests
52 *
53 * Initially, the validator accepts all requests.
54 * Setting \p false causes validator to reject all requests.
55 */
56 void
57 setValidationResult(bool shouldAccept)
58 {
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080059 m_validator.getPolicy().setResult(shouldAccept);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +000060 }
61
Junxiao Shi034c1882016-06-24 18:06:51 +000062private:
63 void
Junxiao Shie7c7f152016-08-20 22:36:22 +000064 recordCommandFail(const ControlResponse& response)
65 {
66 failCodes.push_back(response.getCode());
67 }
68
69 void
70 recordDatasetFail(uint32_t code, const std::string& reason)
Junxiao Shi034c1882016-06-24 18:06:51 +000071 {
72 failCodes.push_back(code);
73 }
74
75protected:
76 ndn::util::DummyClientFace face;
Alexander Afanasyev6dfeffe2017-01-30 22:40:32 -080077 DummyValidator m_validator;
Junxiao Shi034c1882016-06-24 18:06:51 +000078 Controller controller;
Junxiao Shie7c7f152016-08-20 22:36:22 +000079 Controller::CommandFailCallback commandFailCallback;
80 Controller::DatasetFailCallback datasetFailCallback;
Junxiao Shi034c1882016-06-24 18:06:51 +000081 std::vector<uint32_t> failCodes;
Junxiao Shi034c1882016-06-24 18:06:51 +000082};
83
84} // namespace tests
85} // namespace nfd
86} // namespace ndn
87
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050088#endif // NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP