blob: c0570234893533e09c82cb4804aa92012e365582 [file] [log] [blame]
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang916ba2d2018-02-01 18:16:27 -08003 * Copyright (c) 2017-2018, 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();
38 BOOST_CHECK_EQUAL(item.m_caName.toUri(), "/ndn/edu/ucla/CA");
39 BOOST_CHECK_EQUAL(item.m_caInfo, "UCLA's ceritificate authority, located in BH4805.");
40 BOOST_CHECK_EQUAL(item.m_probe, "Please use your email address to apply a namespace first. UCLA email is preferred.");
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080041 BOOST_CHECK_EQUAL(item.m_targetedList, "Use your email address (edu preferred) as input");
Zhiyi Zhang916ba2d2018-02-01 18:16:27 -080042 BOOST_CHECK_EQUAL(item.m_isListEnabled, true);
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080043 BOOST_CHECK_EQUAL(item.m_anchor.getName().toUri(),
44 "/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 +080045
46 BOOST_CHECK_EQUAL(config.m_localNdncertAnchor, "/usr/local/etc/ndncert/anchor.key");
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080047}
48
49BOOST_AUTO_TEST_CASE(AddAndRemoveCaItem)
50{
51 ClientConfig config;
52 config.load("tests/unit-tests/client.conf.test");
53
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080054 ClientCaItem item;
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080055 item.m_caName = Name("/test");
56 item.m_caInfo = "test";
57 item.m_probe = "test";
Zhiyi Zhang916ba2d2018-02-01 18:16:27 -080058 item.m_isListEnabled = false;
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080059
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080060 config.m_caItems.push_back(item);
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080061 BOOST_CHECK_EQUAL(config.m_caItems.size(), 3);
62 auto lastItem = config.m_caItems.back();
63 BOOST_CHECK_EQUAL(lastItem.m_caName.toUri(), "/test");
64
65 config.removeCaItem(Name("/test"));
66 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
67 lastItem = config.m_caItems.back();
68 BOOST_CHECK_EQUAL(lastItem.m_caName.toUri(), "/ndn/edu/ucla/zhiyi/CA");
69}
70
71BOOST_AUTO_TEST_SUITE_END() // TestClientConfig
72
73} // namespace tests
74} // namespace ndncert
75} // namespace ndn