blob: f23f502089d458e5c2466f242241b22ea7a7711d [file] [log] [blame]
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento914d05f2019-07-13 16:20:19 -04002/*
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07003 * Copyright (c) 2017-2019, Regents of the University of California.
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -08004 *
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 Zhang32dbb9f2017-02-16 15:15:10 -080021#include "client-config.hpp"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070022#include "test-common.hpp"
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080023
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080024namespace ndn {
25namespace ndncert {
26namespace tests {
27
28BOOST_AUTO_TEST_SUITE(TestClientConfig)
29
30BOOST_AUTO_TEST_CASE(ReadConfigFile)
31{
32 ClientConfig config;
33 config.load("tests/unit-tests/client.conf.test");
34 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
35
36 const auto& item = config.m_caItems.front();
Suyong Won256c9062020-05-11 02:45:56 -070037 BOOST_CHECK_EQUAL(item.m_caPrefix, "/ndn/edu/ucla");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080038 BOOST_CHECK_EQUAL(item.m_caInfo, "UCLA's ceritificate authority, located in BH4805.");
Zhiyi Zhanga1fc6232019-06-13 14:56:59 -070039 BOOST_CHECK_EQUAL(item.m_probe, "email");
Davide Pesavento914d05f2019-07-13 16:20:19 -040040 BOOST_CHECK_EQUAL(item.m_anchor.getName(),
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080041 "/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080042
43 BOOST_CHECK_EQUAL(config.m_localNdncertAnchor, "/usr/local/etc/ndncert/anchor.key");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080044}
45
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080046BOOST_AUTO_TEST_CASE(ReadNonexistConfigFile)
47{
48 ClientConfig config;
49 BOOST_CHECK_THROW(config.load("tests/unit-tests/nonexist"), ClientConfig::Error);
50}
51
52BOOST_AUTO_TEST_CASE(ReadConfigFileWithInvalidCert)
53{
54 ClientConfig config;
55 BOOST_CHECK_THROW(config.load("tests/unit-tests/client.conf.test2"), ClientConfig::Error);
56}
57
58BOOST_AUTO_TEST_CASE(ReadConfigFileWithoutCaPrefix)
59{
60 ClientConfig config;
61 BOOST_CHECK_THROW(config.load("tests/unit-tests/client.conf.test3"), ClientConfig::Error);
62}
63
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080064BOOST_AUTO_TEST_CASE(AddAndRemoveCaItem)
65{
66 ClientConfig config;
67 config.load("tests/unit-tests/client.conf.test");
68
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080069 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -070070 item.m_caPrefix = Name("/test");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080071 item.m_caInfo = "test";
72 item.m_probe = "test";
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080073
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080074 config.m_caItems.push_back(item);
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080075 BOOST_CHECK_EQUAL(config.m_caItems.size(), 3);
76 auto lastItem = config.m_caItems.back();
Suyong Won256c9062020-05-11 02:45:56 -070077 BOOST_CHECK_EQUAL(lastItem.m_caPrefix, "/test");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080078
79 config.removeCaItem(Name("/test"));
80 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
81 lastItem = config.m_caItems.back();
Suyong Won256c9062020-05-11 02:45:56 -070082 BOOST_CHECK_EQUAL(lastItem.m_caPrefix, "/ndn/edu/ucla/zhiyi");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080083}
84
85BOOST_AUTO_TEST_SUITE_END() // TestClientConfig
86
87} // namespace tests
88} // namespace ndncert
89} // namespace ndn