blob: fcfcaa273535051092e4022e63cea6a79df6d49f [file] [log] [blame]
Alexander Afanasyev1b58a032017-01-04 14:00:47 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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
28namespace ndn {
29namespace security {
30namespace tests {
31
32using namespace ndn::tests;
33
34BOOST_AUTO_TEST_SUITE(Security)
35BOOST_FIXTURE_TEST_SUITE(TestCommandInterestSigner, IdentityManagementV2TimeFixture)
36
37BOOST_AUTO_TEST_CASE(Basic)
38{
39 addIdentity("/test");
40
41 // @TODO replace signed_interest::* with command_interest::*
42
43 CommandInterestSigner signer(m_keyChain);
44 Interest i1 = signer.makeCommandInterest("/hello/world");
45 BOOST_CHECK_EQUAL(i1.getName().size(), 6);
46 BOOST_CHECK_EQUAL(i1.getName().at(signed_interest::POS_SIG_VALUE).blockFromValue().type(), tlv::SignatureValue);
47 BOOST_CHECK_EQUAL(i1.getName().at(signed_interest::POS_SIG_INFO).blockFromValue().type(), tlv::SignatureInfo);
48
49 time::milliseconds timestamp = toUnixTimestamp(time::system_clock::now());
50 BOOST_CHECK_EQUAL(i1.getName().at(signed_interest::POS_TIMESTAMP).toNumber(), timestamp.count());
51
52 Interest i2 = signer.makeCommandInterest("/hello/world/!", signingByIdentity("/test"));
53 BOOST_CHECK_EQUAL(i2.getName().size(), 7);
54 BOOST_CHECK_EQUAL(i2.getName().at(signed_interest::POS_SIG_VALUE).blockFromValue().type(), tlv::SignatureValue);
55 BOOST_CHECK_EQUAL(i2.getName().at(signed_interest::POS_SIG_INFO).blockFromValue().type(), tlv::SignatureInfo);
56 BOOST_CHECK_GT(i2.getName().at(signed_interest::POS_TIMESTAMP), i1.getName().at(signed_interest::POS_TIMESTAMP));
57 BOOST_CHECK_NE(i2.getName().at(signed_interest::POS_RANDOM_VAL),
58 i1.getName().at(signed_interest::POS_RANDOM_VAL)); // this sometimes can fail
59
60 advanceClocks(time::seconds(100));
61
62 i2 = signer.makeCommandInterest("/hello/world/!");
63 BOOST_CHECK_GT(i2.getName().at(signed_interest::POS_TIMESTAMP), i1.getName().at(signed_interest::POS_TIMESTAMP));
64}
65
66BOOST_AUTO_TEST_SUITE_END() // TestCommandInterestSigner
67BOOST_AUTO_TEST_SUITE_END() // Security
68
69} // namespace tests
70} // namespace security
71} // namespace ndn