Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library 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 Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "management/nfd-command-options.hpp" |
Junxiao Shi | c6acc7a | 2015-06-23 10:03:56 -0700 | [diff] [blame] | 23 | #include "security/signing-helpers.hpp" |
| 24 | |
| 25 | #ifdef NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
| 26 | #include "security/identity-certificate.hpp" |
| 27 | #endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 28 | |
| 29 | #include "boost-test.hpp" |
| 30 | |
| 31 | namespace ndn { |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(ManagementNfdCommandOptions) |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 36 | |
| 37 | BOOST_AUTO_TEST_CASE(Timeout) |
| 38 | { |
| 39 | CommandOptions co; |
| 40 | BOOST_CHECK_EQUAL(co.getTimeout(), CommandOptions::DEFAULT_TIMEOUT); |
| 41 | |
| 42 | co.setTimeout(time::milliseconds(7414)); |
| 43 | BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(7414)); |
| 44 | |
| 45 | BOOST_CHECK_THROW(co.setTimeout(time::milliseconds::zero()), std::out_of_range); |
| 46 | BOOST_CHECK_THROW(co.setTimeout(time::milliseconds(-1)), std::out_of_range); |
| 47 | BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(7414)); // unchanged after throw |
| 48 | |
| 49 | co.setTimeout(time::milliseconds(1)); |
| 50 | BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(1)); |
| 51 | } |
| 52 | |
| 53 | BOOST_AUTO_TEST_CASE(Prefix) |
| 54 | { |
| 55 | CommandOptions co; |
| 56 | BOOST_CHECK_EQUAL(co.getPrefix(), CommandOptions::DEFAULT_PREFIX); |
| 57 | |
| 58 | co.setPrefix(Name()); // empty Name is okay |
| 59 | BOOST_CHECK_EQUAL(co.getPrefix(), Name()); |
| 60 | |
| 61 | co.setPrefix("ndn:/localhop/net/example/nfd"); |
| 62 | BOOST_CHECK_EQUAL(co.getPrefix(), Name("ndn:/localhop/net/example/nfd")); |
| 63 | } |
| 64 | |
Junxiao Shi | c6acc7a | 2015-06-23 10:03:56 -0700 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(SigningInfo) |
| 66 | { |
| 67 | CommandOptions co; |
| 68 | BOOST_CHECK_EQUAL(co.getSigningInfo().getSignerType(), security::SigningInfo::SIGNER_TYPE_NULL); |
| 69 | |
| 70 | co.setSigningInfo(signingByIdentity("ndn:/tmp/identity")); |
| 71 | BOOST_CHECK_EQUAL(co.getSigningInfo().getSignerType(), security::SigningInfo::SIGNER_TYPE_ID); |
| 72 | BOOST_CHECK_EQUAL(co.getSigningInfo().getSignerName(), "ndn:/tmp/identity"); |
| 73 | } |
| 74 | |
| 75 | #ifdef NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 76 | BOOST_AUTO_TEST_CASE(SigningParams) |
| 77 | { |
| 78 | CommandOptions co; |
| 79 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 80 | |
| 81 | co.setSigningIdentity("ndn:/tmp/identity"); |
| 82 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_IDENTITY); |
| 83 | BOOST_CHECK_EQUAL(co.getSigningIdentity(), Name("ndn:/tmp/identity")); |
| 84 | |
| 85 | co.setSigningDefault(); // reset |
| 86 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 87 | |
| 88 | co.setSigningIdentity(Name()); // empty Name is valid identity Name |
| 89 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_IDENTITY); |
| 90 | BOOST_CHECK_EQUAL(co.getSigningIdentity(), Name()); |
| 91 | |
| 92 | co.setSigningDefault(); // reset |
| 93 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 94 | |
| 95 | co.setSigningCertificate("ndn:/tmp/KEY/identity/dsk-1/ID-CERT/%FD%01"); |
| 96 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_CERTIFICATE); |
| 97 | BOOST_CHECK_EQUAL(co.getSigningCertificate(), |
| 98 | Name("ndn:/tmp/KEY/identity/dsk-1/ID-CERT/%FD%01")); |
| 99 | |
| 100 | co.setSigningDefault(); // reset |
| 101 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 102 | |
| 103 | co.setSigningCertificate("ndn:/KEY/dsk-1/ID-CERT/%FD%01"); // minimal certificateName |
| 104 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_CERTIFICATE); |
| 105 | BOOST_CHECK_EQUAL(co.getSigningCertificate(), Name("ndn:/KEY/dsk-1/ID-CERT/%FD%01")); |
| 106 | |
| 107 | co.setSigningDefault(); // reset |
| 108 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 109 | |
| 110 | BOOST_CHECK_THROW(co.setSigningCertificate(IdentityCertificate()), // invalid certificate |
| 111 | std::invalid_argument); |
| 112 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), |
| 113 | CommandOptions::SIGNING_PARAMS_DEFAULT); // unchanged after throw |
| 114 | } |
Junxiao Shi | c6acc7a | 2015-06-23 10:03:56 -0700 | [diff] [blame] | 115 | #endif // NDN_MANAGEMENT_NFD_COMMAND_OPTIONS_KEEP_DEPRECATED_SIGNING_PARAMS |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 116 | |
| 117 | BOOST_AUTO_TEST_SUITE_END() |
| 118 | |
| 119 | } // namespace tests |
| 120 | } // namespace nfd |
| 121 | } // namespace ndn |