blob: a717e31ef58e5324653a344b000dbf36cbff0866 [file] [log] [blame]
Zhiyi Zhangae123bf2017-04-14 12:24:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
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
21#include "identity-management-fixture.hpp"
22#include "ca-detail/ca-memory.hpp"
23#include "ca-detail/ca-sqlite.hpp"
24
25namespace ndn {
26namespace ndncert {
27namespace tests {
28
29BOOST_FIXTURE_TEST_SUITE(TestCaMemory, IdentityManagementV2TimeFixture)
30
31BOOST_AUTO_TEST_CASE(Initialization)
32{
33 BOOST_CHECK_NO_THROW(CaMemory storage);
34}
35
36BOOST_AUTO_TEST_CASE(CertificateOperations)
37{
38 CaMemory storage;
39
40 auto identity1 = addIdentity(Name("/ndn/site1"));
41 auto key1 = identity1.getDefaultKey();
42 auto cert1 = key1.getDefaultCertificate();
43
44 // add operation
45 BOOST_CHECK_NO_THROW(storage.addCertificate("123", cert1));
46
47 // get operation
48 BOOST_CHECK_EQUAL(storage.getCertificate("123"), cert1);
49
50 // list operation
51 auto allCerts = storage.listAllIssuedCertificates();
52 BOOST_CHECK_EQUAL(allCerts.size(), 1);
53
54 auto identity2 = addIdentity(Name("/ndn/site2"));
55 auto key2 = identity2.getDefaultKey();
56 auto cert2 = key2.getDefaultCertificate();
57 storage.addCertificate("456", cert2);
58
59 allCerts = storage.listAllIssuedCertificates();
60 BOOST_CHECK_EQUAL(allCerts.size(), 2);
61
62 BOOST_CHECK_NO_THROW(storage.deleteCertificate("123"));
63
64 allCerts = storage.listAllIssuedCertificates();
65 BOOST_CHECK_EQUAL(allCerts.size(), 1);
66
67 auto identity3 = addIdentity(Name("/ndn/site3"));
68 auto key3 = identity3.getDefaultKey();
69 auto cert3 = key3.getDefaultCertificate();
70
71 // update operation
72 BOOST_CHECK_NO_THROW(storage.updateCertificate("456", cert3));
73 BOOST_CHECK_EQUAL(storage.getCertificate("456"), cert3);
74}
75
76BOOST_AUTO_TEST_CASE(RequestOperations)
77{
78 CaMemory storage;
79
80 auto identity1 = addIdentity(Name("/ndn/site1"));
81 auto key1 = identity1.getDefaultKey();
82 auto cert1 = key1.getDefaultCertificate();
83
84 // add operation
85 CertificateRequest request1(Name("/ndn/site1"), "123", cert1);
86 BOOST_CHECK_NO_THROW(storage.addRequest(request1));
87
88 // get operation
89 auto result = storage.getRequest("123");
90 BOOST_CHECK_EQUAL(request1.getCert(), result.getCert());
91 BOOST_CHECK_EQUAL(request1.getStatus(), result.getStatus());
92 BOOST_CHECK_EQUAL(request1.getCaName(), result.getCaName());
93
94 JsonSection json;
95 json.put("code", "1234");
96
97 // update operation
98 CertificateRequest request2(Name("/ndn/site1"), "123", "need-verify", "EMAIL",
99 CaSqlite::convertJson2String(json), cert1);
100 storage.updateRequest(request2);
101 result = storage.getRequest("123");
102 BOOST_CHECK_EQUAL(request2.getCert(), result.getCert());
103 BOOST_CHECK_EQUAL(request2.getStatus(), result.getStatus());
104 BOOST_CHECK_EQUAL(request2.getCaName(), result.getCaName());
105
106 auto identity2 = addIdentity(Name("/ndn/site2"));
107 auto key2 = identity2.getDefaultKey();
108 auto cert2 = key2.getDefaultCertificate();
109 CertificateRequest request3(Name("/ndn/site2"), "456", cert2);
110 storage.addRequest(request3);
111
112 // list operation
113 auto allRequests = storage.listAllRequests();
114 BOOST_CHECK_EQUAL(allRequests.size(), 2);
115
116 storage.deleteRequest("456");
117 allRequests = storage.listAllRequests();
118 BOOST_CHECK_EQUAL(allRequests.size(), 1);
119}
120
121BOOST_AUTO_TEST_SUITE_END() // TestCaModule
122
123} // namespace tests
124} // namespace ndncert
125} // namespace ndn