blob: 977461048a06b25ce6179e0896fd89c752b6d147 [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 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 Zhang8fdb36b2020-10-18 11:58:51 -070040 RequestID requestId = {1,2,3,4,5,6,7,8};
41 CaState request1(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert1, makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070042 BOOST_CHECK_NO_THROW(storage.addRequest(request1));
43
44 // get operation
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070045 auto result = storage.getRequest(requestId);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070046 BOOST_CHECK_EQUAL(request1.m_cert, result.m_cert);
Zhiyi Zhang48f23782020-09-28 12:11:24 -070047 BOOST_CHECK(request1.m_status == result.m_status);
Suyong Won256c9062020-05-11 02:45:56 -070048 BOOST_CHECK_EQUAL(request1.m_caPrefix, result.m_caPrefix);
tylerliu8e170d62020-09-30 01:31:53 -070049 BOOST_CHECK_EQUAL(request1.m_encryptionKey, result.m_encryptionKey);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070050
51 JsonSection json;
52 json.put("code", "1234");
53
54 // update operation
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070055 CaState request2(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert1,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070056 "email", "test", time::system_clock::now(), 3, time::seconds(3600),
57 std::move(json), makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"), 0);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070058 storage.updateRequest(request2);
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070059 result = storage.getRequest(requestId);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070060 BOOST_CHECK_EQUAL(request2.m_cert, result.m_cert);
Zhiyi Zhang48f23782020-09-28 12:11:24 -070061 BOOST_CHECK(request2.m_status == result.m_status);
Suyong Won256c9062020-05-11 02:45:56 -070062 BOOST_CHECK_EQUAL(request2.m_caPrefix, result.m_caPrefix);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070063
64 auto identity2 = addIdentity(Name("/ndn/site2"));
65 auto key2 = identity2.getDefaultKey();
66 auto cert2 = key2.getDefaultCertificate();
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070067 RequestID requestId2 = {8,7,6,5,4,3,2,1};
68 CaState request3(Name("/ndn/site2"), requestId2, RequestType::NEW, Status::BEFORE_CHALLENGE, cert2, makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070069 storage.addRequest(request3);
70
71 // list operation
72 auto allRequests = storage.listAllRequests();
73 BOOST_CHECK_EQUAL(allRequests.size(), 2);
74
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070075 storage.deleteRequest(requestId2);
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070076 allRequests = storage.listAllRequests();
77 BOOST_CHECK_EQUAL(allRequests.size(), 1);
78}
79
Zhiyi Zhang48f23782020-09-28 12:11:24 -070080BOOST_AUTO_TEST_SUITE_END() // TestCaModule
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070081
Zhiyi Zhange4891b72020-10-10 15:11:57 -070082} // namespace tests
83} // namespace ndncert
84} // namespace ndn