blob: dfcfef6a9586f758c98786665f2c5ad1ab23dcbf [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
*
* ndn-tools 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.
*
* ndn-tools 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
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author Yingdi Yu <yingdi@cs.ucla.edu>
*/
#include "tools/pib/cert-publisher.hpp"
#include "tests/identity-management-fixture.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
#include <boost/filesystem.hpp>
namespace ndn {
namespace pib {
namespace tests {
class CertPublisherFixture : public ndn::tests::IdentityManagementTimeFixture
{
public:
CertPublisherFixture()
: tmpPath(boost::filesystem::path(TMP_TESTS_PATH) / "DbTest")
, db(tmpPath.c_str())
, face(io, m_keyChain, {true, true})
{
}
~CertPublisherFixture()
{
boost::filesystem::remove_all(tmpPath);
}
boost::asio::io_service io;
boost::filesystem::path tmpPath;
PibDb db;
util::DummyClientFace face;
};
BOOST_AUTO_TEST_SUITE(Pib)
BOOST_FIXTURE_TEST_SUITE(TestCertPublisher, CertPublisherFixture)
BOOST_AUTO_TEST_CASE(Basic)
{
// Initialize id1
Name id1("/test/identity");
addIdentity(id1);
Name certName111 = m_keyChain.getDefaultCertificateNameForIdentity(id1);
shared_ptr<IdentityCertificate> cert111 = m_keyChain.getCertificate(certName111);
Name keyName11 = cert111->getPublicKeyName();
advanceClocks(io, time::milliseconds(100));
shared_ptr<IdentityCertificate> cert112 = m_keyChain.selfSign(keyName11);
Name certName112 = cert112->getName();
CertPublisher certPublisher(face, db);
// Add a certificate
db.addCertificate(*cert111);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 0);
auto interest111 = make_shared<Interest>(cert111->getName().getPrefix(-1));
face.receive(*interest111);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
BOOST_CHECK(face.sentData[0].wireEncode() == cert111->wireEncode());
face.sentData.clear();
// Add another certificate
db.addCertificate(*cert112);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 0);
auto interest112 = make_shared<Interest>(cert112->getName().getPrefix(-1));
face.receive(*interest112);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
BOOST_CHECK(face.sentData[0].wireEncode() == cert111->wireEncode());
face.sentData.clear();
Exclude exclude;
exclude.excludeOne(cert111->getName().get(-1));
interest112->setExclude(exclude);
face.receive(*interest112);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
BOOST_CHECK(face.sentData[0].wireEncode() == cert112->wireEncode());
face.sentData.clear();
// delete a certificate
db.deleteCertificate(certName112);
face.receive(*interest112);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 0);
face.receive(*interest111);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
BOOST_CHECK(face.sentData[0].wireEncode() == cert111->wireEncode());
face.sentData.clear();
// delete another certificate
db.deleteCertificate(certName111);
face.receive(*interest112);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 0);
face.receive(*interest111);
advanceClocks(io, time::milliseconds(2), 50);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 0);
}
BOOST_AUTO_TEST_SUITE_END() // TestPibPublisher
BOOST_AUTO_TEST_SUITE_END() // Pib
} // namespace tests
} // namespace pib
} // namespace ndn