blob: 4c95293ce685d01aa73e68475e57d931ae77f4bf [file] [log] [blame]
Alexander Afanasyev1b58a032017-01-04 14:00:47 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevadc71842017-01-26 22:17:58 -05002/*
Alexander Afanasyev1b58a032017-01-04 14:00:47 -08003 * 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
28namespace ndn {
29namespace security {
30namespace tests {
31
32using namespace ndn::tests;
33
34BOOST_AUTO_TEST_SUITE(Security)
Alexander Afanasyevadc71842017-01-26 22:17:58 -050035BOOST_FIXTURE_TEST_SUITE(TestCommandInterestSigner, IdentityManagementTimeFixture)
Alexander Afanasyev1b58a032017-01-04 14:00:47 -080036
37BOOST_AUTO_TEST_CASE(Basic)
38{
39 addIdentity("/test");
40
Alexander Afanasyev1b58a032017-01-04 14:00:47 -080041 CommandInterestSigner signer(m_keyChain);
42 Interest i1 = signer.makeCommandInterest("/hello/world");
43 BOOST_CHECK_EQUAL(i1.getName().size(), 6);
Alexander Afanasyev70244f42017-01-04 12:47:12 -080044 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 Afanasyev1b58a032017-01-04 14:00:47 -080046
47 time::milliseconds timestamp = toUnixTimestamp(time::system_clock::now());
Alexander Afanasyev70244f42017-01-04 12:47:12 -080048 BOOST_CHECK_EQUAL(i1.getName().at(command_interest::POS_TIMESTAMP).toNumber(), timestamp.count());
Alexander Afanasyev1b58a032017-01-04 14:00:47 -080049
50 Interest i2 = signer.makeCommandInterest("/hello/world/!", signingByIdentity("/test"));
51 BOOST_CHECK_EQUAL(i2.getName().size(), 7);
Alexander Afanasyev70244f42017-01-04 12:47:12 -080052 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 Afanasyev1b58a032017-01-04 14:00:47 -080057
58 advanceClocks(time::seconds(100));
59
60 i2 = signer.makeCommandInterest("/hello/world/!");
Alexander Afanasyev70244f42017-01-04 12:47:12 -080061 BOOST_CHECK_GT(i2.getName().at(command_interest::POS_TIMESTAMP), i1.getName().at(command_interest::POS_TIMESTAMP));
Alexander Afanasyev1b58a032017-01-04 14:00:47 -080062}
63
64BOOST_AUTO_TEST_SUITE_END() // TestCommandInterestSigner
65BOOST_AUTO_TEST_SUITE_END() // Security
66
67} // namespace tests
68} // namespace security
69} // namespace ndn