blob: 0f8aa9511fd743a9649892b26c8eb04cab0b070f [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"
22
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080023#include "boost-test.hpp"
24
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080025namespace ndn {
26namespace ndncert {
27namespace tests {
28
29BOOST_AUTO_TEST_SUITE(TestClientConfig)
30
31BOOST_AUTO_TEST_CASE(ReadConfigFile)
32{
33 ClientConfig config;
34 config.load("tests/unit-tests/client.conf.test");
35 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
36
37 const auto& item = config.m_caItems.front();
Davide Pesavento914d05f2019-07-13 16:20:19 -040038 BOOST_CHECK_EQUAL(item.m_caName, "/ndn/edu/ucla");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080039 BOOST_CHECK_EQUAL(item.m_caInfo, "UCLA's ceritificate authority, located in BH4805.");
Zhiyi Zhanga1fc6232019-06-13 14:56:59 -070040 BOOST_CHECK_EQUAL(item.m_probe, "email");
Davide Pesavento914d05f2019-07-13 16:20:19 -040041 BOOST_CHECK_EQUAL(item.m_anchor.getName(),
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080042 "/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 +080043
44 BOOST_CHECK_EQUAL(config.m_localNdncertAnchor, "/usr/local/etc/ndncert/anchor.key");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080045}
46
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080047BOOST_AUTO_TEST_CASE(ReadNonexistConfigFile)
48{
49 ClientConfig config;
50 BOOST_CHECK_THROW(config.load("tests/unit-tests/nonexist"), ClientConfig::Error);
51}
52
53BOOST_AUTO_TEST_CASE(ReadConfigFileWithInvalidCert)
54{
55 ClientConfig config;
56 BOOST_CHECK_THROW(config.load("tests/unit-tests/client.conf.test2"), ClientConfig::Error);
57}
58
59BOOST_AUTO_TEST_CASE(ReadConfigFileWithoutCaPrefix)
60{
61 ClientConfig config;
62 BOOST_CHECK_THROW(config.load("tests/unit-tests/client.conf.test3"), ClientConfig::Error);
63}
64
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080065BOOST_AUTO_TEST_CASE(AddAndRemoveCaItem)
66{
67 ClientConfig config;
68 config.load("tests/unit-tests/client.conf.test");
69
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080070 ClientCaItem item;
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080071 item.m_caName = Name("/test");
72 item.m_caInfo = "test";
73 item.m_probe = "test";
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080074
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080075 config.m_caItems.push_back(item);
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080076 BOOST_CHECK_EQUAL(config.m_caItems.size(), 3);
77 auto lastItem = config.m_caItems.back();
Davide Pesavento914d05f2019-07-13 16:20:19 -040078 BOOST_CHECK_EQUAL(lastItem.m_caName, "/test");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080079
80 config.removeCaItem(Name("/test"));
81 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
82 lastItem = config.m_caItems.back();
Davide Pesavento914d05f2019-07-13 16:20:19 -040083 BOOST_CHECK_EQUAL(lastItem.m_caName, "/ndn/edu/ucla/zhiyi");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080084}
85
86BOOST_AUTO_TEST_SUITE_END() // TestClientConfig
87
88} // namespace tests
89} // namespace ndncert
90} // namespace ndn