/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2013-2020 Regents of the University of California.
 *
 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
 *
 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * ndn-cxx library 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 Lesser General Public License for more details.
 *
 * You should have received copies of the GNU General Public License and GNU Lesser
 * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
 */

#include "ndn-cxx/security/certificate-fetcher-offline.hpp"
#include "ndn-cxx/security/validation-policy-simple-hierarchy.hpp"
#include "ndn-cxx/util/scope.hpp"

#include "tests/boost-test.hpp"
#include "tests/unit/security/validator-fixture.hpp"

namespace ndn {
namespace security {
inline namespace v2 {
namespace tests {

using namespace ndn::tests;

BOOST_AUTO_TEST_SUITE(Security)

class CertificateFetcherOfflineWrapper : public CertificateFetcherOffline
{
public:
  CertificateFetcherOfflineWrapper(Face&)
  {
  }
};

using CertificateFetcherOfflineFixture = HierarchicalValidatorFixture<ValidationPolicySimpleHierarchy,
                                                                      CertificateFetcherOfflineWrapper>;

BOOST_FIXTURE_TEST_SUITE(TestCertificateFetcherOffline, CertificateFetcherOfflineFixture)

using Packets = boost::mpl::vector<Interest, Data>;

BOOST_AUTO_TEST_CASE_TEMPLATE(Validate, Packet, Packets)
{
  // Can't set CanBePrefix on Interests in this test case because of template
  // TODO: Remove in #4582
  auto guard = make_scope_exit([] { Interest::s_errorIfCanBePrefixUnset = true; });
  Interest::s_errorIfCanBePrefixUnset = false;

  Packet unsignedPacket("/Security/ValidatorFixture/Sub1/Packet");

  Packet packet = unsignedPacket;
  m_keyChain.sign(packet, signingByIdentity(subIdentity));
  VALIDATE_FAILURE(packet, "Should fail, as no cert should be requested");
  BOOST_CHECK_EQUAL(this->face.sentInterests.size(), 0);

  packet = unsignedPacket;
  m_keyChain.sign(packet, signingByIdentity(identity));
  VALIDATE_SUCCESS(packet, "Should succeed, as signed by trust anchor");
  BOOST_CHECK_EQUAL(this->face.sentInterests.size(), 0);
}

BOOST_AUTO_TEST_SUITE_END() // TestCertificateFetcherOffline
BOOST_AUTO_TEST_SUITE_END() // Security

} // namespace tests
} // inline namespace v2
} // namespace security
} // namespace ndn
