/* -*- 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/interest-signer.hpp"
#include "ndn-cxx/security/signing-helpers.hpp"

#include "tests/boost-test.hpp"
#include "tests/unit/identity-management-time-fixture.hpp"

namespace ndn {
namespace security {
namespace tests {

using namespace ndn::tests;

BOOST_AUTO_TEST_SUITE(Security)
BOOST_FIXTURE_TEST_SUITE(TestInterestSigner, IdentityManagementTimeFixture)

BOOST_AUTO_TEST_CASE(V02)
{
  addIdentity("/test");

  InterestSigner signer(m_keyChain);
  Interest i1 = signer.makeCommandInterest("/hello/world");
  BOOST_REQUIRE_EQUAL(i1.getName().size(), 6);
  BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_SIG_VALUE).blockFromValue().type(), tlv::SignatureValue);
  BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_SIG_INFO).blockFromValue().type(), tlv::SignatureInfo);

  time::milliseconds timestamp = toUnixTimestamp(time::system_clock::now());
  BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_TIMESTAMP).toNumber(), timestamp.count());

  Interest i2 = signer.makeCommandInterest("/hello/world/!", signingByIdentity("/test"));
  BOOST_REQUIRE_EQUAL(i2.getName().size(), 7);
  BOOST_CHECK_EQUAL(i2.getName().at(command_interest::POS_SIG_VALUE).blockFromValue().type(), tlv::SignatureValue);
  BOOST_CHECK_EQUAL(i2.getName().at(command_interest::POS_SIG_INFO).blockFromValue().type(), tlv::SignatureInfo);
  BOOST_CHECK_GT(i2.getName().at(command_interest::POS_TIMESTAMP), i1.getName().at(command_interest::POS_TIMESTAMP));
  BOOST_CHECK_NE(i2.getName().at(command_interest::POS_RANDOM_VAL),
                 i1.getName().at(command_interest::POS_RANDOM_VAL)); // this sometimes can fail

  advanceClocks(100_s);

  i2 = signer.makeCommandInterest("/hello/world/!");
  BOOST_CHECK_GT(i2.getName().at(command_interest::POS_TIMESTAMP), i1.getName().at(command_interest::POS_TIMESTAMP));
}

BOOST_AUTO_TEST_CASE(V03)
{
  addIdentity("/test");

  InterestSigner signer(m_keyChain);
  Interest i1("/hello/world");
  i1.setCanBePrefix(false);
  signer.makeSignedInterest(i1);
  BOOST_CHECK_EQUAL(i1.isSigned(), true);
  BOOST_REQUIRE_EQUAL(i1.getName().size(), 3);
  BOOST_REQUIRE(i1.getSignatureInfo());

  BOOST_TEST(*i1.getSignatureInfo()->getTime() == time::system_clock::now());

  Interest i2("/hello/world/!");
  i2.setCanBePrefix(false);
  signer.makeSignedInterest(i2, signingByIdentity("/test"));
  BOOST_CHECK_EQUAL(i2.isSigned(), true);
  BOOST_REQUIRE_EQUAL(i2.getName().size(), 4);
  BOOST_REQUIRE(i2.getSignatureInfo());

  BOOST_TEST(*i2.getSignatureInfo()->getTime() > *i1.getSignatureInfo()->getTime());
  BOOST_TEST(*i2.getSignatureInfo()->getNonce() != *i1.getSignatureInfo()->getNonce());

  advanceClocks(100_s);

  signer.makeSignedInterest(i2);
  BOOST_CHECK_EQUAL(i2.isSigned(), true);

  BOOST_TEST(*i2.getSignatureInfo()->getTime() == time::system_clock::now());
}

BOOST_AUTO_TEST_SUITE_END() // TestInterestSigner
BOOST_AUTO_TEST_SUITE_END() // Security

} // namespace tests
} // namespace security
} // namespace ndn
