blob: ee7fd6f9968e10f6e5bbf7f15adbbebceb9acdde [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>();
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070028 shared_ptr<CertificateCacheTtl> cache = make_shared<CertificateCacheTtl>(io, time::seconds(1));
Yingdi Yu7640cb32014-01-29 20:00:50 -080029 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);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070034 cert1->setFreshnessPeriod(time::milliseconds(500));
Yingdi Yu7640cb32014-01-29 20:00:50 -080035 shared_ptr<IdentityCertificate> cert2 = make_shared<IdentityCertificate>();
36 Name certName2("/tmp/KEY/ksk-2/ID-CERT/2");
37 cert2->setName(certName2);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070038 cert2->setFreshnessPeriod(time::milliseconds(1000));
Yingdi Yu7640cb32014-01-29 20:00:50 -080039
40 Name name1 = certName1.getPrefix(-1);
41 Name name2 = certName2.getPrefix(-1);
42
43 cache->insertCertificate(cert1);
44 cache->insertCertificate(cert2);
45
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070046 scheduler.scheduleEvent(time::milliseconds(300), bind(&getCertificateTtl, cache, name1, true));
47 scheduler.scheduleEvent(time::milliseconds(300), bind(&getCertificateTtl, cache, name2, true));
48 scheduler.scheduleEvent(time::milliseconds(600), bind(&getCertificateTtl, cache, name1, false));
49 scheduler.scheduleEvent(time::milliseconds(600), bind(&getCertificateTtl, cache, name2, true));
50 scheduler.scheduleEvent(time::milliseconds(600), bind(&CertificateCache::insertCertificate, &*cache, cert2));
51 scheduler.scheduleEvent(time::milliseconds(1300), bind(&getCertificateTtl, cache, name2, true));
52 scheduler.scheduleEvent(time::milliseconds(1700), bind(&getCertificateTtl, cache, name2, false));
Yingdi Yu7640cb32014-01-29 20:00:50 -080053
54 io->run();
55}
56
57BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080058
59} // namespace ndn