blob: 0de626bb523fb328d5e28554c32a257cf1328273 [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 Zhangad6cf932017-10-26 16:19:15 -070023#include "identity-management-fixture.hpp"
Davide Pesavento914d05f2019-07-13 16:20:19 -040024
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080025#include <ndn-cxx/security/transform/base64-encode.hpp>
26#include <ndn-cxx/security/transform/buffer-source.hpp>
27#include <ndn-cxx/security/transform/stream-sink.hpp>
28
29namespace ndn {
30namespace ndncert {
31namespace tests {
32
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070033BOOST_FIXTURE_TEST_SUITE(TestCaConfig, IdentityManagementFixture)
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080034
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080035BOOST_AUTO_TEST_CASE(ReadConfigFile)
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080036{
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080037 CaConfig config;
38 config.load("tests/unit-tests/ca.conf.test");
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070039 BOOST_CHECK_EQUAL(config.m_caPrefix, "/ndn");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070040 BOOST_CHECK_EQUAL(config.m_caInfo, "ndn testbed ca");
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070041 BOOST_CHECK_EQUAL(config.m_maxValidityPeriod, time::seconds(86400));
42 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.size(), 1);
43 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.front(), "full name");
44 BOOST_CHECK_EQUAL(config.m_supportedChallenges.size(), 1);
45 BOOST_CHECK_EQUAL(config.m_supportedChallenges.front(), "pin");
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080046}
47
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080048BOOST_AUTO_TEST_CASE(ReadNonexistConfigFile)
49{
50 CaConfig config;
51 BOOST_CHECK_THROW(config.load("tests/unit-tests/Nonexist"), CaConfig::Error);
52}
53
54BOOST_AUTO_TEST_CASE(ReadConfigFileWithoutCaPrefix)
55{
56 CaConfig config;
57 BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test2"), CaConfig::Error);
58}
59
60BOOST_AUTO_TEST_CASE(ReadConfigFileWithChallengeNotSupported)
61{
62 CaConfig config;
63 BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test3"), CaConfig::Error);
64}
65
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070066BOOST_AUTO_TEST_CASE(InfoContentEncodingDecoding)
67{
68 CaConfig config;
69 config.load("tests/unit-tests/ca.conf.test");
70
71 const auto& identity = addIdentity("/test");
72 const auto& cert = identity.getDefaultKey().getDefaultCertificate();
73 auto encoded = INFO::encodeContentFromCAConfig(config, cert);
74 auto decoded = INFO::decodeClientConfigFromContent(encoded);
75 BOOST_CHECK_EQUAL(config.m_caPrefix, decoded.m_caPrefix);
76 BOOST_CHECK_EQUAL(config.m_caInfo, decoded.m_caInfo);
77 BOOST_CHECK_EQUAL(config.m_maxValidityPeriod, decoded.m_maxValidityPeriod);
78 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size());
79 BOOST_CHECK_EQUAL(config.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front());
80 BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_anchor.wireEncode());
81}
82
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080083BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
84
85} // namespace tests
86} // namespace ndncert
87} // namespace ndn