blob: 3a69e0bff396d2f76469de46bc7da1549829e564 [file] [log] [blame]
Zhiyi Zhangae123bf2017-04-14 12:24:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
tylerliu182bc532020-09-25 01:54:45 -07003 * Copyright (c) 2017-2020, 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"
22#include "detail/ca-sqlite.hpp"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070023#include "test-common.hpp"
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070024
25namespace ndn {
26namespace ndncert {
27namespace tests {
28
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070029using namespace ca;
30
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070031BOOST_FIXTURE_TEST_SUITE(TestCaMemory, IdentityManagementFixture)
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070032
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070033BOOST_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 Zhang80593022020-11-17 10:55:48 -080042 RequestId requestId = {{1,2,3,4,5,6,7,8}};
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -070043 std::array<uint8_t, 16> aesKey1;
44 RequestState request1(Name("/ndn/site1"), requestId, RequestType::NEW,
45 Status::BEFORE_CHALLENGE, cert1, std::move(aesKey1));
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
56 JsonSection json;
57 json.put("code", "1234");
58
59 // update operation
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -070060 std::array<uint8_t, 16> aesKey2;
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070061 RequestState request2(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert1,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070062 "email", "test", time::system_clock::now(), 3, time::seconds(3600),
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -070063 std::move(json), std::move(aesKey2), 0);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070064 storage.updateRequest(request2);
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070065 result = storage.getRequest(requestId);
tylerliu7b9185c2020-11-24 12:15:18 -080066 BOOST_CHECK_EQUAL(request2.cert, result.cert);
67 BOOST_CHECK(request2.status == result.status);
68 BOOST_CHECK_EQUAL(request2.caPrefix, result.caPrefix);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070069
70 auto identity2 = addIdentity(Name("/ndn/site2"));
71 auto key2 = identity2.getDefaultKey();
72 auto cert2 = key2.getDefaultCertificate();
Zhiyi Zhang80593022020-11-17 10:55:48 -080073 RequestId requestId2 = {{8,7,6,5,4,3,2,1}};
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -070074 std::array<uint8_t, 16> aesKey3;
75 RequestState request3(Name("/ndn/site2"), requestId2, RequestType::NEW, Status::BEFORE_CHALLENGE,
76 cert2, std::move(aesKey3));
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070077 storage.addRequest(request3);
78
79 // list operation
80 auto allRequests = storage.listAllRequests();
81 BOOST_CHECK_EQUAL(allRequests.size(), 2);
82
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070083 storage.deleteRequest(requestId2);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070084 allRequests = storage.listAllRequests();
85 BOOST_CHECK_EQUAL(allRequests.size(), 1);
86}
87
Zhiyi Zhang48f23782020-09-28 12:11:24 -070088BOOST_AUTO_TEST_SUITE_END() // TestCaModule
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070089
Zhiyi Zhange4891b72020-10-10 15:11:57 -070090} // namespace tests
91} // namespace ndncert
92} // namespace ndn