Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 914d05f | 2019-07-13 16:20:19 -0400 | [diff] [blame] | 2 | /* |
swa770 | de007bc | 2020-03-24 21:26:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 4 | * |
| 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 | |
tylerliu | 36d97f5 | 2020-09-30 22:32:54 -0700 | [diff] [blame] | 21 | #include <protocol-detail/error.hpp> |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 22 | #include "requester.hpp" |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 23 | #include "challenge-module.hpp" |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 24 | #include "ca-module.hpp" |
Zhiyi Zhang | 5d80e1e | 2020-09-25 11:34:54 -0700 | [diff] [blame] | 25 | #include "test-common.hpp" |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | namespace tests { |
| 30 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 31 | BOOST_FIXTURE_TEST_SUITE(TestRequester, IdentityManagementTimeFixture) |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 32 | |
tylerliu | 36d97f5 | 2020-09-30 22:32:54 -0700 | [diff] [blame] | 33 | BOOST_AUTO_TEST_CASE(ErrorHandling) |
| 34 | { |
| 35 | auto identity = addIdentity(Name("/site")); |
| 36 | auto key = identity.getDefaultKey(); |
| 37 | auto cert = key.getDefaultCertificate(); |
| 38 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 39 | CaProfile item; |
tylerliu | 36d97f5 | 2020-09-30 22:32:54 -0700 | [diff] [blame] | 40 | item.m_caPrefix = Name("/site"); |
| 41 | item.m_cert = std::make_shared<security::v2::Certificate>(cert); |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 42 | RequesterState state(m_keyChain, item, RequestType::NEW); |
tylerliu | 36d97f5 | 2020-09-30 22:32:54 -0700 | [diff] [blame] | 43 | |
| 44 | Data errorPacket; |
| 45 | errorPacket.setName(Name("/site/pretend/this/is/error/packet")); |
| 46 | errorPacket.setFreshnessPeriod(time::seconds(100)); |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 47 | errorPacket.setContent(ErrorTLV::encodeDataContent(ErrorCode::INVALID_PARAMETER, "This is a test.")); |
tylerliu | 36d97f5 | 2020-09-30 22:32:54 -0700 | [diff] [blame] | 48 | m_keyChain.sign(errorPacket, signingByIdentity(identity)); |
| 49 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 50 | 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); |
tylerliu | 36d97f5 | 2020-09-30 22:32:54 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame^] | 56 | BOOST_AUTO_TEST_SUITE_END() // TestRequester |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 57 | |
| 58 | } // namespace tests |
| 59 | } // namespace ndncert |
| 60 | } // namespace ndn |