blob: 79baee25ea104d4217cf9d4237ea0ec49304f589 [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
tylerliu36d97f52020-09-30 22:32:54 -070033BOOST_AUTO_TEST_CASE(ErrorHandling)
34{
35 auto identity = addIdentity(Name("/site"));
36 auto key = identity.getDefaultKey();
37 auto cert = key.getDefaultCertificate();
38
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070039 CaProfile item;
tylerliu36d97f52020-09-30 22:32:54 -070040 item.m_caPrefix = Name("/site");
41 item.m_cert = std::make_shared<security::v2::Certificate>(cert);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070042 RequesterState state(m_keyChain, item, RequestType::NEW);
tylerliu36d97f52020-09-30 22:32:54 -070043
44 Data errorPacket;
45 errorPacket.setName(Name("/site/pretend/this/is/error/packet"));
46 errorPacket.setFreshnessPeriod(time::seconds(100));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070047 errorPacket.setContent(ErrorTLV::encodeDataContent(ErrorCode::INVALID_PARAMETER, "This is a test."));
tylerliu36d97f52020-09-30 22:32:54 -070048 m_keyChain.sign(errorPacket, signingByIdentity(identity));
49
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070050 std::vector<Name> ids, cas;
51 BOOST_CHECK_THROW(Requester::onProbeResponse(errorPacket, item, ids, cas), std::runtime_error);
52 BOOST_CHECK_THROW(Requester::onNewRenewRevokeResponse(state, errorPacket), std::runtime_error);
53 BOOST_CHECK_THROW(Requester::onChallengeResponse(state, errorPacket), std::runtime_error);
tylerliu36d97f52020-09-30 22:32:54 -070054}
55
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070056BOOST_AUTO_TEST_SUITE_END() // TestRequester
Zhiyi Zhang23564c82017-03-01 10:22:22 -080057
58} // namespace tests
59} // namespace ndncert
60} // namespace ndn