blob: 3c125d87a29380a39e0727108855cc892ecc6283 [file] [log] [blame]
Zhiyi Zhang23564c82017-03-01 10:22:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento914d05f2019-07-13 16:20:19 -04002/*
swa770de007bc2020-03-24 21:26:21 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhang23564c82017-03-01 10:22:22 -08004 *
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
tylerliu36d97f52020-09-30 22:32:54 -070021#include <protocol-detail/error.hpp>
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070022#include "requester.hpp"
Zhiyi Zhang23564c82017-03-01 10:22:22 -080023#include "challenge-module.hpp"
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070024#include "ca-module.hpp"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070025#include "test-common.hpp"
Zhiyi Zhang23564c82017-03-01 10:22:22 -080026
27namespace ndn {
28namespace ndncert {
29namespace tests {
30
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070031BOOST_FIXTURE_TEST_SUITE(TestRequester, IdentityManagementTimeFixture)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080032
Suyong Won699e4692020-10-04 03:26:42 +090033/* PROBE */
34BOOST_AUTO_TEST_CASE(GenProbeInterest)
35{
36 auto identity = addIdentity(Name("/site"));
37 auto key = identity.getDefaultKey();
38 auto cert = key.getDefaultCertificate();
39
40 CaProfile ca_profile;
41 ca_profile.m_probeParameterKeys.push_back("email");
Zhiyi Zhang122fcfc2020-10-03 21:46:30 -070042 ca_profile.m_probeParameterKeys.push_back("uid");
Suyong Won699e4692020-10-04 03:26:42 +090043 ca_profile.m_probeParameterKeys.push_back("name");
44 ca_profile.m_caPrefix = Name("/site");
45 ca_profile.m_cert = std::make_shared<security::v2::Certificate>(cert);
46
47 std::vector<std::tuple<std::string, std::string>> probeParams;
48 probeParams.push_back(std::make_tuple("email", "zhiyi@cs.ucla.edu"));
49 probeParams.push_back(std::make_tuple("uid", "987654321"));
50 probeParams.push_back(std::make_tuple("name", "Zhiyi Zhang"));
Zhiyi Zhang122fcfc2020-10-03 21:46:30 -070051 auto firstInterest = Requester::genProbeInterest(ca_profile, std::move(probeParams));
Suyong Won699e4692020-10-04 03:26:42 +090052
53 BOOST_CHECK(firstInterest->getName().at(-1).isParametersSha256Digest());
54 // ignore the last name component (ParametersSha256Digest)
55 BOOST_CHECK_EQUAL(firstInterest->getName().getPrefix(-1), "/site/CA/PROBE");
56 BOOST_CHECK_EQUAL(readString(firstInterest->getApplicationParameters().get(tlv_parameter_value)), "zhiyi@cs.ucla.edu");
57}
58
59BOOST_AUTO_TEST_CASE(OnProbeResponse){}
60
61BOOST_AUTO_TEST_CASE(OnProbeResponseProbeRedirection){}
62
tylerliu36d97f52020-09-30 22:32:54 -070063BOOST_AUTO_TEST_CASE(ErrorHandling)
64{
65 auto identity = addIdentity(Name("/site"));
66 auto key = identity.getDefaultKey();
67 auto cert = key.getDefaultCertificate();
68
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070069 CaProfile item;
tylerliu36d97f52020-09-30 22:32:54 -070070 item.m_caPrefix = Name("/site");
71 item.m_cert = std::make_shared<security::v2::Certificate>(cert);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070072 RequesterState state(m_keyChain, item, RequestType::NEW);
tylerliu36d97f52020-09-30 22:32:54 -070073
74 Data errorPacket;
75 errorPacket.setName(Name("/site/pretend/this/is/error/packet"));
76 errorPacket.setFreshnessPeriod(time::seconds(100));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070077 errorPacket.setContent(ErrorTLV::encodeDataContent(ErrorCode::INVALID_PARAMETER, "This is a test."));
tylerliu36d97f52020-09-30 22:32:54 -070078 m_keyChain.sign(errorPacket, signingByIdentity(identity));
79
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070080 std::vector<Name> ids, cas;
81 BOOST_CHECK_THROW(Requester::onProbeResponse(errorPacket, item, ids, cas), std::runtime_error);
82 BOOST_CHECK_THROW(Requester::onNewRenewRevokeResponse(state, errorPacket), std::runtime_error);
83 BOOST_CHECK_THROW(Requester::onChallengeResponse(state, errorPacket), std::runtime_error);
tylerliu36d97f52020-09-30 22:32:54 -070084}
85
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070086BOOST_AUTO_TEST_SUITE_END() // TestRequester
Zhiyi Zhang23564c82017-03-01 10:22:22 -080087
88} // namespace tests
89} // namespace ndncert
90} // namespace ndn