blob: 11b20fb7b47a6e40c11a93c605a86bd3084e0bf4 [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Yingdi Yu7640cb32014-01-29 20:00:50 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Yingdi Yu7640cb32014-01-29 20:00:50 -080011 */
12
Yingdi Yu7640cb32014-01-29 20:00:50 -080013#include "security/certificate-cache-ttl.hpp"
14#include "face.hpp"
15
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070016#include "boost-test.hpp"
17
Yingdi Yu7640cb32014-01-29 20:00:50 -080018using namespace std;
Yingdi Yu7640cb32014-01-29 20:00:50 -080019
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080020namespace ndn {
Yingdi Yu7640cb32014-01-29 20:00:50 -080021
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070022BOOST_AUTO_TEST_SUITE(SecurityTestCertificateCache)
Yingdi Yu7640cb32014-01-29 20:00:50 -080023
24void
25getCertificateTtl(shared_ptr<CertificateCacheTtl> cache, const Name &name, bool cached)
26{
27 BOOST_CHECK_EQUAL(static_cast<bool>(cache->getCertificate(name)), cached);
28}
29
30
31BOOST_AUTO_TEST_CASE (Ttl)
32{
33 shared_ptr<boost::asio::io_service> io = make_shared<boost::asio::io_service>();
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070034 shared_ptr<CertificateCacheTtl> cache = make_shared<CertificateCacheTtl>(io, time::seconds(1));
Yingdi Yu7640cb32014-01-29 20:00:50 -080035 Scheduler scheduler(*io);
36
37 shared_ptr<IdentityCertificate> cert1 = make_shared<IdentityCertificate>();
38 Name certName1("/tmp/KEY/ksk-1/ID-CERT/1");
39 cert1->setName(certName1);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070040 cert1->setFreshnessPeriod(time::milliseconds(500));
Yingdi Yu7640cb32014-01-29 20:00:50 -080041 shared_ptr<IdentityCertificate> cert2 = make_shared<IdentityCertificate>();
42 Name certName2("/tmp/KEY/ksk-2/ID-CERT/2");
43 cert2->setName(certName2);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070044 cert2->setFreshnessPeriod(time::milliseconds(1000));
Yingdi Yu7640cb32014-01-29 20:00:50 -080045
46 Name name1 = certName1.getPrefix(-1);
47 Name name2 = certName2.getPrefix(-1);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070048
Yingdi Yu7640cb32014-01-29 20:00:50 -080049 cache->insertCertificate(cert1);
50 cache->insertCertificate(cert2);
51
Alexander Afanasyevfcb4f6d2014-04-08 00:20:08 -070052 scheduler.scheduleEvent(time::milliseconds(200), bind(&getCertificateTtl, cache, name1, true));
53 scheduler.scheduleEvent(time::milliseconds(200), bind(&getCertificateTtl, cache, name2, true));
54 scheduler.scheduleEvent(time::milliseconds(900), bind(&getCertificateTtl, cache, name1, false));
55 scheduler.scheduleEvent(time::milliseconds(900), bind(&getCertificateTtl, cache, name2, true));
56 scheduler.scheduleEvent(time::milliseconds(900), bind(&CertificateCache::insertCertificate, cache, cert2));
57 scheduler.scheduleEvent(time::milliseconds(1500), bind(&getCertificateTtl, cache, name2, true));
58 scheduler.scheduleEvent(time::milliseconds(2500), bind(&getCertificateTtl, cache, name2, false));
Yingdi Yu7640cb32014-01-29 20:00:50 -080059
60 io->run();
61}
62
63BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080064
65} // namespace ndn