blob: f9c75305b472243987b70ad53377c747b0bceb8d [file] [log] [blame]
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, 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 "boost-test.hpp"
22#include "client-config.hpp"
23
24namespace 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();
37 BOOST_CHECK_EQUAL(item.m_caName.toUri(), "/ndn/edu/ucla/CA");
38 BOOST_CHECK_EQUAL(item.m_caInfo, "UCLA's ceritificate authority, located in BH4805.");
39 BOOST_CHECK_EQUAL(item.m_probe, "Please use your email address to apply a namespace first. UCLA email is preferred.");
40 BOOST_CHECK_EQUAL(item.m_supportedChallenges.size(), 2);
41 BOOST_CHECK_EQUAL(item.m_supportedChallenges.front(), "PIN");
42}
43
44BOOST_AUTO_TEST_CASE(AddAndRemoveCaItem)
45{
46 ClientConfig config;
47 config.load("tests/unit-tests/client.conf.test");
48
49 CaItem item;
50 item.m_caName = Name("/test");
51 item.m_caInfo = "test";
52 item.m_probe = "test";
53 std::list<std::string> list;
54 list.push_back("TEST");
55 item.m_supportedChallenges = list;
56
57 config.addNewCaItem(item);
58 BOOST_CHECK_EQUAL(config.m_caItems.size(), 3);
59 auto lastItem = config.m_caItems.back();
60 BOOST_CHECK_EQUAL(lastItem.m_caName.toUri(), "/test");
61
62 config.removeCaItem(Name("/test"));
63 BOOST_CHECK_EQUAL(config.m_caItems.size(), 2);
64 lastItem = config.m_caItems.back();
65 BOOST_CHECK_EQUAL(lastItem.m_caName.toUri(), "/ndn/edu/ucla/zhiyi/CA");
66}
67
68BOOST_AUTO_TEST_SUITE_END() // TestClientConfig
69
70} // namespace tests
71} // namespace ndncert
72} // namespace ndn