blob: e8dccafe9404c3d46e76483957896f1b9d672c6d [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/*
swa770de007bc2020-03-24 21:26:21 -07003 * Copyright (c) 2017-2020, 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"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070024#include "test-common.hpp"
Zhiyi Zhang23564c82017-03-01 10:22:22 -080025
26namespace ndn {
27namespace ndncert {
28namespace tests {
29
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070030BOOST_FIXTURE_TEST_SUITE(TestClientModule, IdentityManagementTimeFixture)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080031
32BOOST_AUTO_TEST_CASE(ClientModuleInitialize)
33{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070034 ClientModule client(m_keyChain);
Zhiyi Zhang9829da92020-09-30 16:19:34 -070035 client.getClientConf().load("tests/unit-tests/config-files/config-client-1");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080036 BOOST_CHECK_EQUAL(client.getClientConf().m_caItems.size(), 2);
37}
38
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070039BOOST_AUTO_TEST_CASE(Probe)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080040{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070041 ClientModule client(m_keyChain);
Zhiyi Zhang9829da92020-09-30 16:19:34 -070042 client.getClientConf().load("tests/unit-tests/config-files/config-client-1");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080043
Zhiyi Zhang10130782018-02-01 18:28:49 -080044 auto identity = addIdentity(Name("/site"));
Zhiyi Zhang23564c82017-03-01 10:22:22 -080045 auto key = identity.getDefaultKey();
46 auto cert = key.getDefaultCertificate();
47
Zhiyi Zhang9829da92020-09-30 16:19:34 -070048 CaConfigItem item;
49 item.m_probeParameterKeys.push_back("email");
50 item.m_probeParameterKeys.push_back("uid");
51 item.m_probeParameterKeys.push_back("name");
Suyong Won256c9062020-05-11 02:45:56 -070052 item.m_caPrefix = Name("/site");
Zhiyi Zhang9829da92020-09-30 16:19:34 -070053 item.m_cert = std::make_shared<security::v2::Certificate>(cert);
Zhiyi Zhang23564c82017-03-01 10:22:22 -080054 client.getClientConf().m_caItems.push_back(item);
55
Zhiyi Zhang9829da92020-09-30 16:19:34 -070056 std::vector<std::tuple<std::string, std::string>> probeParams;
57 probeParams.push_back(std::make_tuple("email", "zhiyi@cs.ucla.edu"));
58 probeParams.push_back(std::make_tuple("uid", "987654321"));
59 probeParams.push_back(std::make_tuple("name", "Zhiyi Zhang"));
60 auto firstInterest = client.generateProbeInterest(item, std::move(probeParams));
Davide Pesavento914d05f2019-07-13 16:20:19 -040061 BOOST_CHECK(firstInterest->getName().at(-1).isParametersSha256Digest());
62 // ignore the last name component (ParametersSha256Digest)
swa770de007bc2020-03-24 21:26:21 -070063 BOOST_CHECK_EQUAL(firstInterest->getName().getPrefix(-1), "/site/CA/PROBE");
Suyong Won7968f7a2020-05-12 01:01:25 -070064 BOOST_CHECK_EQUAL(readString(firstInterest->getApplicationParameters().get(tlv_parameter_value)),
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070065 "zhiyi@cs.ucla.edu");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080066}
67
Zhiyi Zhangef6b36a2020-09-22 21:20:59 -070068// BOOST_AUTO_TEST_CASE(GenProbeRequestJson)
69// {
70// ClientModule client(m_keyChain);
Zhiyi Zhang9829da92020-09-30 16:19:34 -070071// client.getClientConf().load("tests/unit-tests/config-files/config-client-1");
Yufeng Zhang424d0362019-06-12 16:48:27 -070072
Zhiyi Zhangef6b36a2020-09-22 21:20:59 -070073// auto identity = addIdentity(Name("/site"));
74// auto key = identity.getDefaultKey();
75// auto cert = key.getDefaultCertificate();
Yufeng Zhang424d0362019-06-12 16:48:27 -070076
Zhiyi Zhang9829da92020-09-30 16:19:34 -070077// CaConfigItem item;
Zhiyi Zhangef6b36a2020-09-22 21:20:59 -070078// item.m_probe = "email:uid:name";
79// item.m_caPrefix = Name("/site");
Zhiyi Zhang9829da92020-09-30 16:19:34 -070080// item.m_cert = std::make_shared<security::v2::Certificate>(cert);
Zhiyi Zhangef6b36a2020-09-22 21:20:59 -070081// client.getClientConf().m_caItems.push_back(item);
Yufeng Zhang424d0362019-06-12 16:48:27 -070082
Zhiyi Zhangef6b36a2020-09-22 21:20:59 -070083// 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// }
Yufeng Zhang424d0362019-06-12 16:48:27 -070088
Zhiyi Zhang23564c82017-03-01 10:22:22 -080089BOOST_AUTO_TEST_SUITE_END() // TestClientModule
90
91} // namespace tests
92} // namespace ndncert
93} // namespace ndn