Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 914d05f | 2019-07-13 16:20:19 -0400 | [diff] [blame] | 2 | /* |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2019, Regents of the University of California. |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 21 | #include "ca-config.hpp" |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 22 | #include "protocol-detail/info.hpp" |
Zhiyi Zhang | 5d80e1e | 2020-09-25 11:34:54 -0700 | [diff] [blame] | 23 | #include "test-common.hpp" |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 24 | |
| 25 | namespace ndn { |
| 26 | namespace ndncert { |
| 27 | namespace tests { |
| 28 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 29 | BOOST_FIXTURE_TEST_SUITE(TestCaConfig, IdentityManagementFixture) |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 30 | |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 31 | BOOST_AUTO_TEST_CASE(ReadConfigFile) |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 32 | { |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 33 | CaConfig config; |
| 34 | config.load("tests/unit-tests/ca.conf.test"); |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 35 | BOOST_CHECK_EQUAL(config.m_caPrefix, "/ndn"); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 36 | BOOST_CHECK_EQUAL(config.m_caInfo, "ndn testbed ca"); |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 37 | BOOST_CHECK_EQUAL(config.m_maxValidityPeriod, time::seconds(86400)); |
| 38 | BOOST_CHECK_EQUAL(config.m_probeParameterKeys.size(), 1); |
| 39 | BOOST_CHECK_EQUAL(config.m_probeParameterKeys.front(), "full name"); |
| 40 | BOOST_CHECK_EQUAL(config.m_supportedChallenges.size(), 1); |
| 41 | BOOST_CHECK_EQUAL(config.m_supportedChallenges.front(), "pin"); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 44 | BOOST_AUTO_TEST_CASE(ReadNonexistConfigFile) |
| 45 | { |
| 46 | CaConfig config; |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 47 | BOOST_CHECK_THROW(config.load("tests/unit-tests/Nonexist"), std::runtime_error); |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE(ReadConfigFileWithoutCaPrefix) |
| 51 | { |
| 52 | CaConfig config; |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 53 | BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test2"), std::runtime_error); |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(ReadConfigFileWithChallengeNotSupported) |
| 57 | { |
| 58 | CaConfig config; |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 59 | BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test3"), std::runtime_error); |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 62 | BOOST_AUTO_TEST_CASE(InfoContentEncodingDecoding) |
| 63 | { |
| 64 | CaConfig config; |
| 65 | config.load("tests/unit-tests/ca.conf.test"); |
| 66 | |
| 67 | const auto& identity = addIdentity("/test"); |
| 68 | const auto& cert = identity.getDefaultKey().getDefaultCertificate(); |
Zhiyi Zhang | 61c43a6 | 2020-09-28 12:56:01 -0700 | [diff] [blame] | 69 | auto encoded = INFO::encodeDataContent(config, cert); |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 70 | auto decoded = INFO::decodeClientConfigFromContent(encoded); |
| 71 | BOOST_CHECK_EQUAL(config.m_caPrefix, decoded.m_caPrefix); |
| 72 | BOOST_CHECK_EQUAL(config.m_caInfo, decoded.m_caInfo); |
| 73 | BOOST_CHECK_EQUAL(config.m_maxValidityPeriod, decoded.m_maxValidityPeriod); |
| 74 | BOOST_CHECK_EQUAL(config.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size()); |
| 75 | BOOST_CHECK_EQUAL(config.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front()); |
| 76 | BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_anchor.wireEncode()); |
| 77 | } |
| 78 | |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 79 | BOOST_AUTO_TEST_SUITE_END() // TestCaConfig |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 80 | |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 81 | } // namespace tests |
| 82 | } // namespace ndncert |
| 83 | } // namespace ndn |