blob: d7cb506d16d886692639bdf2c4b67d3e3a45499f [file] [log] [blame]
Zhiyi Zhang9829da92020-09-30 16:19:34 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2017-2019, Regents of the University of California.
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
21#include "configuration.hpp"
22#include "protocol-detail/info.hpp"
23#include "test-common.hpp"
24
25namespace ndn {
26namespace ndncert {
27namespace tests {
28
29BOOST_FIXTURE_TEST_SUITE(TestConfig, IdentityManagementFixture)
30
31BOOST_AUTO_TEST_CASE(CAConfigFile)
32{
33 CaConfig config;
34 config.load("tests/unit-tests/config-files/config-ca-1");
35 BOOST_CHECK_EQUAL(config.m_caItem.m_caPrefix, "/ndn");
36 BOOST_CHECK_EQUAL(config.m_caItem.m_caInfo, "ndn testbed ca");
37 BOOST_CHECK_EQUAL(config.m_caItem.m_maxValidityPeriod, time::seconds(864000));
38 BOOST_CHECK_EQUAL(*config.m_caItem.m_maxSuffixLength, 3);
39 BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.size(), 1);
40 BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.front(), "full name");
41 BOOST_CHECK_EQUAL(config.m_caItem.m_supportedChallenges.size(), 1);
42 BOOST_CHECK_EQUAL(config.m_caItem.m_supportedChallenges.front(), "pin");
43
44 config.load("tests/unit-tests/config-files/config-ca-2");
45 BOOST_CHECK_EQUAL(config.m_caItem.m_caPrefix, "/ndn");
46 BOOST_CHECK_EQUAL(config.m_caItem.m_caInfo, "missing max validity period, max suffix length, and probe");
47 BOOST_CHECK_EQUAL(config.m_caItem.m_maxValidityPeriod, time::seconds(86400));
48 BOOST_CHECK(!config.m_caItem.m_maxSuffixLength);
49 BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.size(), 0);
Zhiyi Zhangb940aa12020-09-30 16:38:57 -070050 BOOST_CHECK_EQUAL(config.m_caItem.m_supportedChallenges.size(), 2);
Zhiyi Zhang9829da92020-09-30 16:19:34 -070051 BOOST_CHECK_EQUAL(config.m_caItem.m_supportedChallenges.front(), "pin");
52 BOOST_CHECK_EQUAL(config.m_caItem.m_supportedChallenges.back(), "email");
Zhiyi Zhangfde50112020-10-01 16:36:33 -070053
54 config.load("tests/unit-tests/config-files/config-ca-5");
Zhiyi Zhange537dd52020-10-01 18:02:24 -070055 BOOST_CHECK_EQUAL(config.m_redirection->at(0)->getName(),
Zhiyi Zhangfde50112020-10-01 16:36:33 -070056 "/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
Zhiyi Zhang9829da92020-09-30 16:19:34 -070057}
58
59BOOST_AUTO_TEST_CASE(CAConfigFileWithErrors)
60{
61 CaConfig config;
62 // nonexistent file
63 BOOST_CHECK_THROW(config.load("tests/unit-tests/config-files/Nonexist"), std::runtime_error);
64 // missing challenge
65 BOOST_CHECK_THROW(config.load("tests/unit-tests/config-files/config-ca-3"), std::runtime_error);
66 // unsupported challenge
67 BOOST_CHECK_THROW(config.load("tests/unit-tests/config-files/config-ca-4"), std::runtime_error);
68}
69
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070070BOOST_AUTO_TEST_CASE(RequesterCaCacheFile)
Zhiyi Zhang9829da92020-09-30 16:19:34 -070071{
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070072 RequesterCaCache config;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070073 config.load("tests/unit-tests/config-files/config-client-1");
74 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
75
76 auto& config1 = config.m_caItems.front();
Zhiyi Zhangb940aa12020-09-30 16:38:57 -070077 BOOST_CHECK_EQUAL(config1.m_caPrefix, "/ndn/edu/ucla");
Zhiyi Zhang9829da92020-09-30 16:19:34 -070078 BOOST_CHECK_EQUAL(config1.m_caInfo, "ndn testbed ca");
79 BOOST_CHECK_EQUAL(config1.m_maxValidityPeriod, time::seconds(864000));
80 BOOST_CHECK_EQUAL(*config1.m_maxSuffixLength, 3);
81 BOOST_CHECK_EQUAL(config1.m_probeParameterKeys.size(), 1);
82 BOOST_CHECK_EQUAL(config1.m_probeParameterKeys.front(), "email");
83 BOOST_CHECK_EQUAL(config1.m_cert->getName(),
84 "/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
85
Zhiyi Zhangb940aa12020-09-30 16:38:57 -070086 auto& config2 = config.m_caItems.back();
87 BOOST_CHECK_EQUAL(config2.m_caPrefix, "/ndn/edu/ucla/zhiyi");
88 BOOST_CHECK_EQUAL(config2.m_caInfo, "");
Zhiyi Zhang9829da92020-09-30 16:19:34 -070089 BOOST_CHECK_EQUAL(config2.m_maxValidityPeriod, time::seconds(86400));
90 BOOST_CHECK(!config2.m_maxSuffixLength);
91 BOOST_CHECK_EQUAL(config2.m_probeParameterKeys.size(), 0);
92 BOOST_CHECK_EQUAL(config2.m_cert->getName(),
93 "/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
94}
95
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070096BOOST_AUTO_TEST_CASE(RequesterCaCacheFileWithErrors)
Zhiyi Zhang9829da92020-09-30 16:19:34 -070097{
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070098 RequesterCaCache config;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070099 // nonexistent file
100 BOOST_CHECK_THROW(config.load("tests/unit-tests/config-files/Nonexist"), std::runtime_error);
101 // missing certificate
102 BOOST_CHECK_THROW(config.load("tests/unit-tests/config-files/config-client-2"), std::runtime_error);
103 // missing ca prefix
104 BOOST_CHECK_THROW(config.load("tests/unit-tests/config-files/config-client-3"), std::runtime_error);
105}
106
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700107BOOST_AUTO_TEST_CASE(RequesterCaCacheFileAddAndremoveCaProfile)
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700108{
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700109 RequesterCaCache config;
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700110 config.load("tests/unit-tests/config-files/config-client-1");
111
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700112 CaProfile item;
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700113 item.m_caPrefix = Name("/test");
114 item.m_caInfo = "test";
115
116 config.m_caItems.push_back(item);
117 BOOST_CHECK_EQUAL(config.m_caItems.size(), 3);
118 auto lastItem = config.m_caItems.back();
119 BOOST_CHECK_EQUAL(lastItem.m_caPrefix, "/test");
120
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700121 config.removeCaProfile(Name("/test"));
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700122 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
123 lastItem = config.m_caItems.back();
124 BOOST_CHECK_EQUAL(lastItem.m_caPrefix, "/ndn/edu/ucla/zhiyi");
125}
126
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700127BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
128
129} // namespace tests
130} // namespace ndncert
131} // namespace ndn