blob: 881a0402ffa455c20550b34853748c80d893f1a5 [file] [log] [blame]
Zhiyi Zhange537dd52020-10-01 18:02:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017-2020, 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 "protocol-detail/info.hpp"
22#include "protocol-detail/probe.hpp"
23#include "protocol-detail/new-renew-revoke.hpp"
24#include "protocol-detail/challenge.hpp"
25#include "test-common.hpp"
26
27namespace ndn {
28namespace ndncert {
29namespace tests {
30
31BOOST_FIXTURE_TEST_SUITE(TestProtocolDetail, IdentityManagementTimeFixture)
32
33BOOST_AUTO_TEST_CASE(TestInfo)
34{
35 CaConfig config;
36 config.load("tests/unit-tests/config-files/config-ca-1");
37
38 const auto& identity = addIdentity("/test");
39 const auto& cert = identity.getDefaultKey().getDefaultCertificate();
40 auto encoded = INFO::encodeDataContent(config.m_caItem, cert);
41 auto decoded = INFO::decodeDataContent(encoded);
42 BOOST_CHECK_EQUAL(config.m_caItem.m_caPrefix, decoded.m_caPrefix);
43 BOOST_CHECK_EQUAL(config.m_caItem.m_caInfo, decoded.m_caInfo);
44 BOOST_CHECK_EQUAL(config.m_caItem.m_maxValidityPeriod, decoded.m_maxValidityPeriod);
45 BOOST_CHECK_EQUAL(*config.m_caItem.m_maxSuffixLength, *decoded.m_maxSuffixLength);
46 BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size());
47 BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front());
48 BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_cert->wireEncode());
49}
50
51BOOST_AUTO_TEST_CASE(TestProbe)
52{
53 std::vector<std::tuple<std::string, std::string>> parameters;
54 parameters.push_back(std::make_tuple("email", "zhiyi@cs.ucla.edu"));
55 auto appParametersTlv = PROBE::encodeApplicationParameters(std::move(parameters));
56 auto decodedParameters = PROBE::decodeApplicationParameters(appParametersTlv);
57 BOOST_CHECK_EQUAL(std::get<0>(decodedParameters[0]), "email");
58 BOOST_CHECK_EQUAL(std::get<1>(decodedParameters[0]), "zhiyi@cs.ucla.edu");
59 BOOST_CHECK_EQUAL(decodedParameters.size(), 1);
60
61 CaConfig config;
62 config.load("tests/unit-tests/config-files/config-ca-5");
63 std::vector<Name> ids;
64 ids.push_back(Name("/example"));
65 auto contentTlv = PROBE::encodeDataContent(ids, 2, config.m_redirection);
66 std::vector<Name> decodedIds, decodedRedirectionItems;
67 PROBE::decodeDataContent(contentTlv, decodedIds, decodedRedirectionItems);
68 BOOST_CHECK_EQUAL(decodedIds[0], Name("/example"));
69 BOOST_CHECK_EQUAL(decodedRedirectionItems[0], config.m_redirection->at(0)->getFullName());
70}
71
72BOOST_AUTO_TEST_SUITE_END() // TestProtocolDetail
73
74} // namespace tests
75} // namespace ndncert
76} // namespace ndn