Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2020 Regents of the University of California. |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 22 | #include "ndn-cxx/security/certificate-cache.hpp" |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
| 25 | #include "tests/unit/identity-management-time-fixture.hpp" |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace security { |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 29 | inline namespace v2 { |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 30 | namespace tests { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(Security) |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 33 | |
| 34 | class CertificateCacheFixture : public ndn::tests::IdentityManagementTimeFixture |
| 35 | { |
| 36 | public: |
| 37 | CertificateCacheFixture() |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 38 | : certCache(10_s) |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 39 | { |
| 40 | identity = addIdentity("/TestCertificateCache/"); |
| 41 | cert = identity.getDefaultKey().getDefaultCertificate(); |
| 42 | } |
| 43 | |
| 44 | public: |
| 45 | CertificateCache certCache; |
| 46 | Identity identity; |
| 47 | Certificate cert; |
| 48 | }; |
| 49 | |
| 50 | BOOST_FIXTURE_TEST_SUITE(TestCertificateCache, CertificateCacheFixture) |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(RemovalTime) |
| 53 | { |
| 54 | // Cache lifetime is capped to 10 seconds during cache construction |
| 55 | |
| 56 | BOOST_CHECK_NO_THROW(certCache.insert(cert)); |
| 57 | BOOST_CHECK(certCache.find(cert.getName()) != nullptr); |
| 58 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 59 | advanceClocks(11_s, 1); |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 60 | BOOST_CHECK(certCache.find(cert.getName()) == nullptr); |
| 61 | |
| 62 | BOOST_CHECK_NO_THROW(certCache.insert(cert)); |
| 63 | BOOST_CHECK(certCache.find(cert.getName()) != nullptr); |
| 64 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 65 | advanceClocks(5_s); |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 66 | BOOST_CHECK(certCache.find(cert.getName()) != nullptr); |
| 67 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 68 | advanceClocks(15_s); |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 69 | BOOST_CHECK(certCache.find(cert.getName()) == nullptr); |
| 70 | } |
| 71 | |
| 72 | BOOST_AUTO_TEST_CASE(FindByInterest) |
| 73 | { |
| 74 | BOOST_CHECK_NO_THROW(certCache.insert(cert)); |
| 75 | |
| 76 | // Find by interest |
| 77 | BOOST_CHECK(certCache.find(Interest(cert.getIdentity())) != nullptr); |
| 78 | BOOST_CHECK(certCache.find(Interest(cert.getKeyName())) != nullptr); |
| 79 | BOOST_CHECK(certCache.find(Interest(Name(cert.getName()).appendVersion())) == nullptr); |
| 80 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 81 | advanceClocks(12_s); |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 82 | BOOST_CHECK(certCache.find(Interest(cert.getIdentity())) == nullptr); |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_SUITE_END() // TestCertificateCache |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 86 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 87 | |
| 88 | } // namespace tests |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 89 | } // inline namespace v2 |
Qiuhan Ding | 609f061 | 2015-11-04 14:07:14 -0800 | [diff] [blame] | 90 | } // namespace security |
| 91 | } // namespace ndn |