blob: fa1ddd86e6a8d7543206bf3af55859f6493cb751 [file] [log] [blame]
Zhiyi Zhangae123bf2017-04-14 12:24:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0dc02012021-11-23 22:55:03 -05002/*
Davide Pesavento0d1d11c2022-04-11 22:11:34 -04003 * Copyright (c) 2017-2022, Regents of the University of California.
Zhiyi Zhangae123bf2017-04-14 12:24:53 -07004 *
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 Zhang062be6d2020-10-14 17:13:43 -070021#include "detail/ca-memory.hpp"
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040022
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070023#include "test-common.hpp"
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070024
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040025namespace ndncert::tests {
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070026
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070027using namespace ca;
28
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070029BOOST_FIXTURE_TEST_SUITE(TestCaMemory, IdentityManagementFixture)
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070030
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070031BOOST_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 Zhang1f5e86e2020-12-04 15:07:57 -080040 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 Zhangae123bf2017-04-14 12:24:53 -070046 BOOST_CHECK_NO_THROW(storage.addRequest(request1));
47
48 // get operation
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070049 auto result = storage.getRequest(requestId);
tylerliu7b9185c2020-11-24 12:15:18 -080050 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 Zhangae123bf2017-04-14 12:24:53 -070055
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070056 // update operation
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -080057 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 Zhangae123bf2017-04-14 12:24:53 -070067 storage.updateRequest(request2);
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070068 result = storage.getRequest(requestId);
tylerliu7b9185c2020-11-24 12:15:18 -080069 BOOST_CHECK_EQUAL(request2.cert, result.cert);
70 BOOST_CHECK(request2.status == result.status);
71 BOOST_CHECK_EQUAL(request2.caPrefix, result.caPrefix);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070072
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -080073 // another add operation
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070074 auto identity2 = addIdentity(Name("/ndn/site2"));
75 auto key2 = identity2.getDefaultKey();
76 auto cert2 = key2.getDefaultCertificate();
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -080077 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 Zhangae123bf2017-04-14 12:24:53 -070083 storage.addRequest(request3);
84
85 // list operation
86 auto allRequests = storage.listAllRequests();
87 BOOST_CHECK_EQUAL(allRequests.size(), 2);
88
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070089 storage.deleteRequest(requestId2);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070090 allRequests = storage.listAllRequests();
91 BOOST_CHECK_EQUAL(allRequests.size(), 1);
92}
93
Davide Pesavento0dc02012021-11-23 22:55:03 -050094BOOST_AUTO_TEST_SUITE_END() // TestCaMemory
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070095
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040096} // namespace ndncert::tests