Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, 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" |
| 22 | #include "detail/ca-sqlite.hpp" |
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 | |
| 25 | namespace ndn { |
| 26 | namespace ndncert { |
| 27 | namespace tests { |
| 28 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 29 | using namespace ca; |
| 30 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 31 | BOOST_FIXTURE_TEST_SUITE(TestCaMemory, IdentityManagementFixture) |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 32 | |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 33 | BOOST_AUTO_TEST_CASE(RequestOperations) |
| 34 | { |
| 35 | CaMemory storage; |
| 36 | |
| 37 | auto identity1 = addIdentity(Name("/ndn/site1")); |
| 38 | auto key1 = identity1.getDefaultKey(); |
| 39 | auto cert1 = key1.getDefaultCertificate(); |
| 40 | |
| 41 | // add operation |
Zhiyi Zhang | 8059302 | 2020-11-17 10:55:48 -0800 | [diff] [blame] | 42 | RequestId requestId = {{1,2,3,4,5,6,7,8}}; |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 43 | std::array<uint8_t, 16> aesKey1; |
| 44 | RequestState request1(Name("/ndn/site1"), requestId, RequestType::NEW, |
| 45 | Status::BEFORE_CHALLENGE, cert1, std::move(aesKey1)); |
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); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 50 | BOOST_CHECK_EQUAL(request1.m_cert, result.m_cert); |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 51 | BOOST_CHECK(request1.m_status == result.m_status); |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(request1.m_caPrefix, result.m_caPrefix); |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL_COLLECTIONS(request1.m_encryptionKey.begin(), request1.m_encryptionKey.end(), |
| 54 | result.m_encryptionKey.begin(), result.m_encryptionKey.end()); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 55 | |
| 56 | JsonSection json; |
| 57 | json.put("code", "1234"); |
| 58 | |
| 59 | // update operation |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 60 | std::array<uint8_t, 16> aesKey2; |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 61 | RequestState request2(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert1, |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 62 | "email", "test", time::system_clock::now(), 3, time::seconds(3600), |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 63 | std::move(json), std::move(aesKey2), 0); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 64 | storage.updateRequest(request2); |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 65 | result = storage.getRequest(requestId); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(request2.m_cert, result.m_cert); |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 67 | BOOST_CHECK(request2.m_status == result.m_status); |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(request2.m_caPrefix, result.m_caPrefix); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 69 | |
| 70 | auto identity2 = addIdentity(Name("/ndn/site2")); |
| 71 | auto key2 = identity2.getDefaultKey(); |
| 72 | auto cert2 = key2.getDefaultCertificate(); |
Zhiyi Zhang | 8059302 | 2020-11-17 10:55:48 -0800 | [diff] [blame] | 73 | RequestId requestId2 = {{8,7,6,5,4,3,2,1}}; |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 74 | std::array<uint8_t, 16> aesKey3; |
| 75 | RequestState request3(Name("/ndn/site2"), requestId2, RequestType::NEW, Status::BEFORE_CHALLENGE, |
| 76 | cert2, std::move(aesKey3)); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 77 | storage.addRequest(request3); |
| 78 | |
| 79 | // list operation |
| 80 | auto allRequests = storage.listAllRequests(); |
| 81 | BOOST_CHECK_EQUAL(allRequests.size(), 2); |
| 82 | |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 83 | storage.deleteRequest(requestId2); |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 84 | allRequests = storage.listAllRequests(); |
| 85 | BOOST_CHECK_EQUAL(allRequests.size(), 1); |
| 86 | } |
| 87 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 88 | BOOST_AUTO_TEST_SUITE_END() // TestCaModule |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 89 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 90 | } // namespace tests |
| 91 | } // namespace ndncert |
| 92 | } // namespace ndn |