Zhiyi Zhang | e537dd5 | 2020-10-01 18:02:24 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_FIXTURE_TEST_SUITE(TestProtocolDetail, IdentityManagementTimeFixture) |
| 32 | |
| 33 | BOOST_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); |
Zhiyi Zhang | e537dd5 | 2020-10-01 18:02:24 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size()); |
| 46 | BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front()); |
| 47 | BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_cert->wireEncode()); |
| 48 | } |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE(TestProbe) |
| 51 | { |
| 52 | std::vector<std::tuple<std::string, std::string>> parameters; |
| 53 | parameters.push_back(std::make_tuple("email", "zhiyi@cs.ucla.edu")); |
| 54 | auto appParametersTlv = PROBE::encodeApplicationParameters(std::move(parameters)); |
| 55 | auto decodedParameters = PROBE::decodeApplicationParameters(appParametersTlv); |
| 56 | BOOST_CHECK_EQUAL(std::get<0>(decodedParameters[0]), "email"); |
| 57 | BOOST_CHECK_EQUAL(std::get<1>(decodedParameters[0]), "zhiyi@cs.ucla.edu"); |
| 58 | BOOST_CHECK_EQUAL(decodedParameters.size(), 1); |
| 59 | |
| 60 | CaConfig config; |
| 61 | config.load("tests/unit-tests/config-files/config-ca-5"); |
| 62 | std::vector<Name> ids; |
| 63 | ids.push_back(Name("/example")); |
| 64 | auto contentTlv = PROBE::encodeDataContent(ids, 2, config.m_redirection); |
tylerliu | b47dad7 | 2020-10-08 21:36:55 -0700 | [diff] [blame] | 65 | std::vector<Name> decodedRedirectionItems; |
| 66 | std::vector<std::pair<Name, int>> decodedIds; |
Zhiyi Zhang | e537dd5 | 2020-10-01 18:02:24 -0700 | [diff] [blame] | 67 | PROBE::decodeDataContent(contentTlv, decodedIds, decodedRedirectionItems); |
tylerliu | b47dad7 | 2020-10-08 21:36:55 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(decodedIds[0].first, Name("/example")); |
| 69 | BOOST_CHECK_EQUAL(decodedIds[0].second, 2); |
Zhiyi Zhang | e537dd5 | 2020-10-01 18:02:24 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(decodedRedirectionItems[0], config.m_redirection->at(0)->getFullName()); |
| 71 | } |
| 72 | |
| 73 | BOOST_AUTO_TEST_SUITE_END() // TestProtocolDetail |
| 74 | |
| 75 | } // namespace tests |
| 76 | } // namespace ndncert |
| 77 | } // namespace ndn |