Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | adc7184 | 2017-01-26 22:17:58 -0500 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
| 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 "security/command-interest-signer.hpp" |
| 23 | #include "security/signing-helpers.hpp" |
| 24 | |
| 25 | #include "boost-test.hpp" |
| 26 | #include "../identity-management-time-fixture.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace security { |
| 30 | namespace tests { |
| 31 | |
| 32 | using namespace ndn::tests; |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(Security) |
Alexander Afanasyev | adc7184 | 2017-01-26 22:17:58 -0500 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(TestCommandInterestSigner, IdentityManagementTimeFixture) |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 36 | |
| 37 | BOOST_AUTO_TEST_CASE(Basic) |
| 38 | { |
| 39 | addIdentity("/test"); |
| 40 | |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 41 | CommandInterestSigner signer(m_keyChain); |
| 42 | Interest i1 = signer.makeCommandInterest("/hello/world"); |
| 43 | BOOST_CHECK_EQUAL(i1.getName().size(), 6); |
Alexander Afanasyev | 70244f4 | 2017-01-04 12:47:12 -0800 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_SIG_VALUE).blockFromValue().type(), tlv::SignatureValue); |
| 45 | BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_SIG_INFO).blockFromValue().type(), tlv::SignatureInfo); |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 46 | |
| 47 | time::milliseconds timestamp = toUnixTimestamp(time::system_clock::now()); |
Alexander Afanasyev | 70244f4 | 2017-01-04 12:47:12 -0800 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_TIMESTAMP).toNumber(), timestamp.count()); |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 49 | |
| 50 | Interest i2 = signer.makeCommandInterest("/hello/world/!", signingByIdentity("/test")); |
| 51 | BOOST_CHECK_EQUAL(i2.getName().size(), 7); |
Alexander Afanasyev | 70244f4 | 2017-01-04 12:47:12 -0800 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(i2.getName().at(command_interest::POS_SIG_VALUE).blockFromValue().type(), tlv::SignatureValue); |
| 53 | BOOST_CHECK_EQUAL(i2.getName().at(command_interest::POS_SIG_INFO).blockFromValue().type(), tlv::SignatureInfo); |
| 54 | BOOST_CHECK_GT(i2.getName().at(command_interest::POS_TIMESTAMP), i1.getName().at(command_interest::POS_TIMESTAMP)); |
| 55 | BOOST_CHECK_NE(i2.getName().at(command_interest::POS_RANDOM_VAL), |
| 56 | i1.getName().at(command_interest::POS_RANDOM_VAL)); // this sometimes can fail |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 57 | |
| 58 | advanceClocks(time::seconds(100)); |
| 59 | |
| 60 | i2 = signer.makeCommandInterest("/hello/world/!"); |
Alexander Afanasyev | 70244f4 | 2017-01-04 12:47:12 -0800 | [diff] [blame] | 61 | BOOST_CHECK_GT(i2.getName().at(command_interest::POS_TIMESTAMP), i1.getName().at(command_interest::POS_TIMESTAMP)); |
Alexander Afanasyev | 1b58a03 | 2017-01-04 14:00:47 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | BOOST_AUTO_TEST_SUITE_END() // TestCommandInterestSigner |
| 65 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 66 | |
| 67 | } // namespace tests |
| 68 | } // namespace security |
| 69 | } // namespace ndn |