blob: 2e054cb9025a0ca21d496af1b51a548e50e136c3 [file] [log] [blame]
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -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 Zhangdaf2fd72017-01-19 11:31:35 -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 Zhangdaf2fd72017-01-19 11:31:35 -080021#include "ca-config.hpp"
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070022#include "protocol-detail/info.hpp"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070023#include "test-common.hpp"
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080024
25namespace ndn {
26namespace ndncert {
27namespace tests {
28
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070029BOOST_FIXTURE_TEST_SUITE(TestCaConfig, IdentityManagementFixture)
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080030
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080031BOOST_AUTO_TEST_CASE(ReadConfigFile)
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080032{
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080033 CaConfig config;
34 config.load("tests/unit-tests/ca.conf.test");
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070035 BOOST_CHECK_EQUAL(config.m_caPrefix, "/ndn");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070036 BOOST_CHECK_EQUAL(config.m_caInfo, "ndn testbed ca");
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070037 BOOST_CHECK_EQUAL(config.m_maxValidityPeriod, time::seconds(86400));
38 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.size(), 1);
39 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.front(), "full name");
40 BOOST_CHECK_EQUAL(config.m_supportedChallenges.size(), 1);
41 BOOST_CHECK_EQUAL(config.m_supportedChallenges.front(), "pin");
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080042}
43
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080044BOOST_AUTO_TEST_CASE(ReadNonexistConfigFile)
45{
46 CaConfig config;
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070047 BOOST_CHECK_THROW(config.load("tests/unit-tests/Nonexist"), std::runtime_error);
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080048}
49
50BOOST_AUTO_TEST_CASE(ReadConfigFileWithoutCaPrefix)
51{
52 CaConfig config;
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070053 BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test2"), std::runtime_error);
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080054}
55
56BOOST_AUTO_TEST_CASE(ReadConfigFileWithChallengeNotSupported)
57{
58 CaConfig config;
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070059 BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test3"), std::runtime_error);
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080060}
61
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070062BOOST_AUTO_TEST_CASE(InfoContentEncodingDecoding)
63{
64 CaConfig config;
65 config.load("tests/unit-tests/ca.conf.test");
66
67 const auto& identity = addIdentity("/test");
68 const auto& cert = identity.getDefaultKey().getDefaultCertificate();
Zhiyi Zhang61c43a62020-09-28 12:56:01 -070069 auto encoded = INFO::encodeDataContent(config, cert);
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070070 auto decoded = INFO::decodeClientConfigFromContent(encoded);
71 BOOST_CHECK_EQUAL(config.m_caPrefix, decoded.m_caPrefix);
72 BOOST_CHECK_EQUAL(config.m_caInfo, decoded.m_caInfo);
73 BOOST_CHECK_EQUAL(config.m_maxValidityPeriod, decoded.m_maxValidityPeriod);
74 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size());
75 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front());
76 BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_anchor.wireEncode());
77}
78
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070079BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080080
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070081} // namespace tests
82} // namespace ndncert
83} // namespace ndn