Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 3 | * Copyright (c) 2017-2022, Regents of the University of California. |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [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 | |
Zhiyi Zhang | 062be6d | 2020-10-14 17:13:43 -0700 | [diff] [blame] | 21 | #include "detail/ca-memory.hpp" |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 22 | |
Zhiyi Zhang | 5d80e1e | 2020-09-25 11:34:54 -0700 | [diff] [blame] | 23 | #include "test-common.hpp" |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 25 | namespace ndncert::tests { |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 26 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 27 | using namespace ca; |
| 28 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 29 | BOOST_FIXTURE_TEST_SUITE(TestCaMemory, IdentityManagementFixture) |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 30 | |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 31 | BOOST_AUTO_TEST_CASE(RequestOperations) |
| 32 | { |
| 33 | CaMemory storage; |
| 34 | |
| 35 | auto identity1 = addIdentity(Name("/ndn/site1")); |
| 36 | auto key1 = identity1.getDefaultKey(); |
| 37 | auto cert1 = key1.getDefaultCertificate(); |
| 38 | |
| 39 | // add operation |
Zhiyi Zhang | 1f5e86e | 2020-12-04 15:07:57 -0800 | [diff] [blame] | 40 | RequestId requestId = {{101}}; |
| 41 | RequestState request1; |
| 42 | request1.caPrefix = Name("/ndn/site1"); |
| 43 | request1.requestId = requestId; |
| 44 | request1.requestType = RequestType::NEW; |
| 45 | request1.cert = cert1; |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 46 | BOOST_CHECK_NO_THROW(storage.addRequest(request1)); |
| 47 | |
| 48 | // get operation |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 49 | auto result = storage.getRequest(requestId); |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 50 | BOOST_CHECK_EQUAL(request1.cert, result.cert); |
| 51 | BOOST_CHECK(request1.status == result.status); |
| 52 | BOOST_CHECK_EQUAL(request1.caPrefix, result.caPrefix); |
| 53 | BOOST_CHECK_EQUAL_COLLECTIONS(request1.encryptionKey.begin(), request1.encryptionKey.end(), |
| 54 | result.encryptionKey.begin(), result.encryptionKey.end()); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 55 | |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 56 | // update operation |
Zhiyi Zhang | 1f5e86e | 2020-12-04 15:07:57 -0800 | [diff] [blame] | 57 | RequestState request2; |
| 58 | request2.caPrefix = Name("/ndn/site1"); |
| 59 | request2.requestId = requestId; |
| 60 | request2.requestType = RequestType::NEW; |
| 61 | request2.cert = cert1; |
| 62 | request2.challengeType = "email"; |
| 63 | JsonSection secret; |
| 64 | secret.add("code", "1234"); |
| 65 | request2.challengeState = ChallengeState("test", time::system_clock::now(), 3, |
| 66 | time::seconds(3600), std::move(secret)); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 67 | storage.updateRequest(request2); |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 68 | result = storage.getRequest(requestId); |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(request2.cert, result.cert); |
| 70 | BOOST_CHECK(request2.status == result.status); |
| 71 | BOOST_CHECK_EQUAL(request2.caPrefix, result.caPrefix); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 72 | |
Zhiyi Zhang | 1f5e86e | 2020-12-04 15:07:57 -0800 | [diff] [blame] | 73 | // another add operation |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 74 | auto identity2 = addIdentity(Name("/ndn/site2")); |
| 75 | auto key2 = identity2.getDefaultKey(); |
| 76 | auto cert2 = key2.getDefaultCertificate(); |
Zhiyi Zhang | 1f5e86e | 2020-12-04 15:07:57 -0800 | [diff] [blame] | 77 | RequestId requestId2 = {{102}}; |
| 78 | RequestState request3; |
| 79 | request3.caPrefix = Name("/ndn/site2"); |
| 80 | request3.requestId = requestId2; |
| 81 | request3.requestType = RequestType::NEW; |
| 82 | request3.cert = cert2; |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 83 | storage.addRequest(request3); |
| 84 | |
| 85 | // list operation |
| 86 | auto allRequests = storage.listAllRequests(); |
| 87 | BOOST_CHECK_EQUAL(allRequests.size(), 2); |
| 88 | |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 89 | storage.deleteRequest(requestId2); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 90 | allRequests = storage.listAllRequests(); |
| 91 | BOOST_CHECK_EQUAL(allRequests.size(), 1); |
| 92 | } |
| 93 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 94 | BOOST_AUTO_TEST_SUITE_END() // TestCaMemory |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 95 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 96 | } // namespace ndncert::tests |