Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 1 | /** |
| 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 | |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 7 | #include "security/certificate-cache-ttl.hpp" |
| 8 | #include "face.hpp" |
| 9 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 10 | #include "boost-test.hpp" |
| 11 | |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 12 | using namespace std; |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 14 | namespace ndn { |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 15 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 16 | BOOST_AUTO_TEST_SUITE(SecurityTestCertificateCache) |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 17 | |
| 18 | void |
| 19 | getCertificateTtl(shared_ptr<CertificateCacheTtl> cache, const Name &name, bool cached) |
| 20 | { |
| 21 | BOOST_CHECK_EQUAL(static_cast<bool>(cache->getCertificate(name)), cached); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | BOOST_AUTO_TEST_CASE (Ttl) |
| 26 | { |
| 27 | shared_ptr<boost::asio::io_service> io = make_shared<boost::asio::io_service>(); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 28 | shared_ptr<CertificateCacheTtl> cache = make_shared<CertificateCacheTtl>(io, time::seconds(1)); |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 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); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 34 | cert1->setFreshnessPeriod(time::milliseconds(500)); |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 35 | shared_ptr<IdentityCertificate> cert2 = make_shared<IdentityCertificate>(); |
| 36 | Name certName2("/tmp/KEY/ksk-2/ID-CERT/2"); |
| 37 | cert2->setName(certName2); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 38 | cert2->setFreshnessPeriod(time::milliseconds(1000)); |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 39 | |
| 40 | Name name1 = certName1.getPrefix(-1); |
| 41 | Name name2 = certName2.getPrefix(-1); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 42 | |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 43 | cache->insertCertificate(cert1); |
| 44 | cache->insertCertificate(cert2); |
| 45 | |
Alexander Afanasyev | fcb4f6d | 2014-04-08 00:20:08 -0700 | [diff] [blame] | 46 | scheduler.scheduleEvent(time::milliseconds(200), bind(&getCertificateTtl, cache, name1, true)); |
| 47 | scheduler.scheduleEvent(time::milliseconds(200), bind(&getCertificateTtl, cache, name2, true)); |
| 48 | scheduler.scheduleEvent(time::milliseconds(900), bind(&getCertificateTtl, cache, name1, false)); |
| 49 | scheduler.scheduleEvent(time::milliseconds(900), bind(&getCertificateTtl, cache, name2, true)); |
| 50 | scheduler.scheduleEvent(time::milliseconds(900), bind(&CertificateCache::insertCertificate, cache, cert2)); |
| 51 | scheduler.scheduleEvent(time::milliseconds(1500), bind(&getCertificateTtl, cache, name2, true)); |
| 52 | scheduler.scheduleEvent(time::milliseconds(2500), bind(&getCertificateTtl, cache, name2, false)); |
Yingdi Yu | 7640cb3 | 2014-01-29 20:00:50 -0800 | [diff] [blame] | 53 | |
| 54 | io->run(); |
| 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 58 | |
| 59 | } // namespace ndn |