/* -*- 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)
{
  ndn::mgmt::Authorization authorize = m_manager.makeAuthorization("test-verb");

  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;
    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
