/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2016,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mgmt/nfd-manager-base.hpp"
#include "manager-common-fixture.hpp"

#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/management/nfd-control-command.hpp>

namespace nfd {
namespace tests {

class NfdManagerBaseFixture : public ManagerCommonFixture
{
public:
  NfdManagerBaseFixture()
    : m_manager(m_dispatcher, m_validator, "test-module")
  {
  }

protected:
  CommandValidator m_validator;
  NfdManagerBase m_manager;
};

BOOST_AUTO_TEST_SUITE(Mgmt)
BOOST_FIXTURE_TEST_SUITE(TestNfdManagerBase, NfdManagerBaseFixture)

BOOST_AUTO_TEST_CASE(AddSupportedPrivilegeInConstructor)
{
  BOOST_CHECK_NO_THROW(m_validator.addSupportedPrivilege("other-module"));
  // test-module has already been added by the constructor of ManagerBase
  BOOST_CHECK_THROW(m_validator.addSupportedPrivilege("test-module"), CommandValidator::Error);
}

BOOST_AUTO_TEST_CASE(CommandAuthorization)
{
  bool didAcceptCallbackFire = false;
  bool didRejectCallbackFire = false;
  auto testAuthorization = [&] {
    didAcceptCallbackFire = false;
    didRejectCallbackFire = false;

    auto command = makeControlCommandRequest("/localhost/nfd/test-module/test-verb",
                                             ControlParameters());
    ndn::nfd::ControlParameters params;
    m_manager.authorize("/top/prefix", *command, &params,
                        bind([&] { didAcceptCallbackFire = true; }),
                        bind([&] { didRejectCallbackFire = true; }));
  };

  testAuthorization();
  BOOST_CHECK(!didAcceptCallbackFire);
  BOOST_CHECK(didRejectCallbackFire);

  m_validator.addInterestRule("^<localhost><nfd><test-module>", *m_certificate);
  testAuthorization();
  BOOST_CHECK(didAcceptCallbackFire);
  BOOST_CHECK(!didRejectCallbackFire);
}

BOOST_AUTO_TEST_SUITE_END() // TestNfdManagerBase
BOOST_AUTO_TEST_SUITE_END() // Mgmt

} // namespace tests
} // namespace nfd
