blob: 3718170cce115ad11a82f8ad4f3ca4d099eb3eaf [file] [log] [blame]
Yingdi Yu7640cb32014-01-29 20:00:50 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Yingdi Yu <yingdi0@cs.ucla.edu>
4 * See COPYING for copyright and distribution information.
5 */
6
7#include <boost/test/unit_test.hpp>
8#include <unistd.h>
9#include "security/certificate-cache-ttl.hpp"
10#include "face.hpp"
11
12using namespace std;
Yingdi Yu7640cb32014-01-29 20:00:50 -080013
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080014namespace ndn {
Yingdi Yu7640cb32014-01-29 20:00:50 -080015
16BOOST_AUTO_TEST_SUITE(TestCertificateCache)
17
18void
19getCertificateTtl(shared_ptr<CertificateCacheTtl> cache, const Name &name, bool cached)
20{
21 BOOST_CHECK_EQUAL(static_cast<bool>(cache->getCertificate(name)), cached);
22}
23
24
25BOOST_AUTO_TEST_CASE (Ttl)
26{
27 shared_ptr<boost::asio::io_service> io = make_shared<boost::asio::io_service>();
28 shared_ptr<CertificateCacheTtl> cache = make_shared<CertificateCacheTtl>(io, 1);
29 Scheduler scheduler(*io);
30
31 shared_ptr<IdentityCertificate> cert1 = make_shared<IdentityCertificate>();
32 Name certName1("/tmp/KEY/ksk-1/ID-CERT/1");
33 cert1->setName(certName1);
34 cert1->setFreshnessPeriod(500);
35 shared_ptr<IdentityCertificate> cert2 = make_shared<IdentityCertificate>();
36 Name certName2("/tmp/KEY/ksk-2/ID-CERT/2");
37 cert2->setName(certName2);
38 cert2->setFreshnessPeriod(1000);
39
40 Name name1 = certName1.getPrefix(-1);
41 Name name2 = certName2.getPrefix(-1);
42
43 cache->insertCertificate(cert1);
44 cache->insertCertificate(cert2);
45
46 scheduler.scheduleEvent(time::seconds(0.3), bind(&getCertificateTtl, cache, name1, true));
47 scheduler.scheduleEvent(time::seconds(0.3), bind(&getCertificateTtl, cache, name2, true));
48 scheduler.scheduleEvent(time::seconds(0.6), bind(&getCertificateTtl, cache, name1, false));
49 scheduler.scheduleEvent(time::seconds(0.6), bind(&getCertificateTtl, cache, name2, true));
50 scheduler.scheduleEvent(time::seconds(0.6), bind(&CertificateCache::insertCertificate, &*cache, cert2));
51 scheduler.scheduleEvent(time::seconds(1.3), bind(&getCertificateTtl, cache, name2, true));
52 scheduler.scheduleEvent(time::seconds(1.7), bind(&getCertificateTtl, cache, name2, false));
53
54 io->run();
55}
56
57BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080058
59} // namespace ndn