Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 1 | /* -*- 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 "identity-management-fixture.hpp" |
| 22 | #include "ca-config.hpp" |
| 23 | #include <ndn-cxx/security/transform/base64-encode.hpp> |
| 24 | #include <ndn-cxx/security/transform/buffer-source.hpp> |
| 25 | #include <ndn-cxx/security/transform/stream-sink.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_FIXTURE_TEST_SUITE(TestCaConfig, IdentityManagementV2Fixture) |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(ReadConfigFileWithFileAnchor) |
| 34 | { |
| 35 | CaConfig config("tests/unit-tests/ca.conf.test"); |
| 36 | BOOST_CHECK_EQUAL(config.m_caName.toUri(), "/ndn/edu/ucla/cs/zhiyi"); |
| 37 | BOOST_CHECK_EQUAL(config.m_freshPeriod, 720); |
| 38 | BOOST_CHECK_EQUAL(config.m_anchor->getName().toUri(), |
| 39 | "/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5"); |
| 40 | BOOST_CHECK_EQUAL(config.m_availableChallenges.size(), 1); |
| 41 | } |
| 42 | |
| 43 | BOOST_AUTO_TEST_CASE(ReadConfigFileWithBase64Anchor) |
| 44 | { |
| 45 | auto identity = addIdentity(Name("/ndn/site1")); |
| 46 | auto key = identity.getDefaultKey(); |
| 47 | auto cert = key.getDefaultCertificate(); |
| 48 | |
| 49 | using namespace security::transform; |
| 50 | std::stringstream ss; |
| 51 | bufferSource(cert.wireEncode().wire(), cert.wireEncode().size()) >> base64Encode() >> streamSink(ss); |
| 52 | |
| 53 | const std::string certBase64 = ss.str(); |
| 54 | |
| 55 | CaConfig config("tests/unit-tests/ca.conf.test"); |
| 56 | config.m_config.put("ca-anchor.type", "base64"); |
| 57 | config.m_config.put("ca-anchor.value", certBase64); |
| 58 | config.load(); |
| 59 | BOOST_CHECK_EQUAL(*(config.m_anchor), cert); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_SUITE_END() // TestCaConfig |
| 63 | |
| 64 | } // namespace tests |
| 65 | } // namespace ndncert |
| 66 | } // namespace ndn |