blob: 9dde9ddfdcd6703962d96f14415ccc167f79e516 [file] [log] [blame]
Zhiyi Zhang23564c82017-03-01 10:22:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento914d05f2019-07-13 16:20:19 -04002/*
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07003 * Copyright (c) 2017-2019, Regents of the University of California.
Zhiyi Zhang23564c82017-03-01 10:22:22 -08004 *
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 Zhang23564c82017-03-01 10:22:22 -080021#include "client-module.hpp"
22#include "challenge-module.hpp"
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070023#include "ca-module.hpp"
Davide Pesavento914d05f2019-07-13 16:20:19 -040024
25#include "identity-management-fixture.hpp"
26
Zhiyi Zhang23564c82017-03-01 10:22:22 -080027#include <ndn-cxx/util/dummy-client-face.hpp>
28#include <ndn-cxx/security/signing-helpers.hpp>
29#include <ndn-cxx/security/transform/public-key.hpp>
30#include <ndn-cxx/security/verification-helpers.hpp>
31
32namespace ndn {
33namespace ndncert {
34namespace tests {
35
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070036BOOST_FIXTURE_TEST_SUITE(TestClientModule, IdentityManagementTimeFixture)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080037
38BOOST_AUTO_TEST_CASE(ClientModuleInitialize)
39{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070040 ClientModule client(m_keyChain);
Zhiyi Zhang23564c82017-03-01 10:22:22 -080041 client.getClientConf().load("tests/unit-tests/client.conf.test");
42 BOOST_CHECK_EQUAL(client.getClientConf().m_caItems.size(), 2);
43}
44
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070045BOOST_AUTO_TEST_CASE(Probe)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080046{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070047 ClientModule client(m_keyChain);
Zhiyi Zhang23564c82017-03-01 10:22:22 -080048 client.getClientConf().load("tests/unit-tests/client.conf.test");
49
Zhiyi Zhang10130782018-02-01 18:28:49 -080050 auto identity = addIdentity(Name("/site"));
Zhiyi Zhang23564c82017-03-01 10:22:22 -080051 auto key = identity.getDefaultKey();
52 auto cert = key.getDefaultCertificate();
53
54 ClientCaItem item;
Yufeng Zhang424d0362019-06-12 16:48:27 -070055 item.m_probe = "email:uid:name";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070056 item.m_caName = Name("/site");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080057 item.m_anchor = cert;
58 client.getClientConf().m_caItems.push_back(item);
59
Yufeng Zhang424d0362019-06-12 16:48:27 -070060 auto firstInterest = client.generateProbeInterest(item, "zhiyi@cs.ucla.edu:987654321:Zhiyi Zhang");
Davide Pesavento914d05f2019-07-13 16:20:19 -040061 BOOST_CHECK(firstInterest->getName().at(-1).isParametersSha256Digest());
62 // ignore the last name component (ParametersSha256Digest)
63 BOOST_CHECK_EQUAL(firstInterest->getName().getPrefix(-1), "/site/CA/_PROBE");
Yufeng Zhang424d0362019-06-12 16:48:27 -070064 BOOST_CHECK_EQUAL(CaModule::jsonFromBlock(firstInterest->getApplicationParameters()).get<std::string>("email"),
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070065 "zhiyi@cs.ucla.edu");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080066}
67
Davide Pesavento914d05f2019-07-13 16:20:19 -040068BOOST_AUTO_TEST_CASE(GenProbeRequestJson)
Yufeng Zhang424d0362019-06-12 16:48:27 -070069{
70 ClientModule client(m_keyChain);
71 client.getClientConf().load("tests/unit-tests/client.conf.test");
72
73 auto identity = addIdentity(Name("/site"));
74 auto key = identity.getDefaultKey();
75 auto cert = key.getDefaultCertificate();
76
77 ClientCaItem item;
78 item.m_probe = "email:uid:name";
79 item.m_caName = Name("/site");
80 item.m_anchor = cert;
81 client.getClientConf().m_caItems.push_back(item);
82
83 auto interestPacket = client.genProbeRequestJson(item, "yufeng@ucla.edu:123456789:Yufeng Zhang");
84 BOOST_CHECK_EQUAL(interestPacket.get("email", ""), "yufeng@ucla.edu");
85 BOOST_CHECK_EQUAL(interestPacket.get("uid", ""), "123456789");
86 BOOST_CHECK_EQUAL(interestPacket.get("name", ""), "Yufeng Zhang");
87}
88
Zhiyi Zhang23564c82017-03-01 10:22:22 -080089BOOST_AUTO_TEST_SUITE_END() // TestClientModule
90
91} // namespace tests
92} // namespace ndncert
93} // namespace ndn