blob: 496d7aea04d01f44b3ab896181a271e433d90864 [file] [log] [blame]
Zhiyi Zhang91c846b2017-04-12 14:16:31 -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-sqlite.hpp"
23
24namespace ndn {
25namespace ndncert {
26namespace tests {
27
28BOOST_FIXTURE_TEST_SUITE(TestCaSqlite, IdentityManagementV2TimeFixture)
29
30BOOST_AUTO_TEST_CASE(Initialization)
31{
32 BOOST_CHECK_NO_THROW(CaSqlite storage);
33}
34
35BOOST_AUTO_TEST_CASE(CertificateOperations)
36{
37 CaSqlite storage;
38
39 auto identity = addIdentity(Name("/ndn/site1"));
40 auto key = identity.getDefaultKey();
41 auto cert = key.getDefaultCertificate();
42
43 BOOST_CHECK_NO_THROW(storage.addCertificate("123", cert));
44 auto result = storage.getCertificate("123");
45 BOOST_CHECK_EQUAL(cert, result);
46}
47
48BOOST_AUTO_TEST_CASE(RequestOperations)
49{
50 CaSqlite storage;
51
52 auto identity = addIdentity(Name("/ndn/site2"));
53 auto key = identity.getDefaultKey();
54 auto cert = key.getDefaultCertificate();
55
56 CertificateRequest request1(Name("/ndn/site2"), "123", cert);
57 BOOST_CHECK_NO_THROW(storage.addRequest(request1));
58 auto result = storage.getRequest("123");
59 BOOST_CHECK_EQUAL(request1.getCert(), result.getCert());
60 BOOST_CHECK_EQUAL(request1.getStatus(), result.getStatus());
61 BOOST_CHECK_EQUAL(request1.getCaName(), result.getCaName());
62
63 JsonSection json;
64 json.put("code", "1234");
65 std::stringstream ss;
66 boost::property_tree::write_json(ss, json);
67 std::string jsonValue = ss.str();
68
69 CertificateRequest request2(Name("/ndn/site2"), "123", "need-verify", "EMAIL", jsonValue, cert);
70 storage.updateRequest(request2);
71 result = storage.getRequest("123");
72 BOOST_CHECK_EQUAL(request2.getCert(), result.getCert());
73 BOOST_CHECK_EQUAL(request2.getStatus(), result.getStatus());
74 BOOST_CHECK_EQUAL(request2.getCaName(), result.getCaName());
75}
76
77BOOST_AUTO_TEST_SUITE_END() // TestCaModule
78
79} // namespace tests
80} // namespace ndncert
81} // namespace ndn