blob: 1da13ce17e442a59da391fdde64450a4eb082e50 [file] [log] [blame]
Zhiyi Zhang23564c82017-03-01 10:22:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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"
Zhiyi Zhang10130782018-02-01 18:28:49 -080022#include "identity-management-fixture.hpp"
Zhiyi Zhang23564c82017-03-01 10:22:22 -080023#include "challenge-module.hpp"
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070024#include "ca-module.hpp"
Zhiyi Zhang23564c82017-03-01 10:22:22 -080025#include <ndn-cxx/util/dummy-client-face.hpp>
26#include <ndn-cxx/security/signing-helpers.hpp>
27#include <ndn-cxx/security/transform/public-key.hpp>
28#include <ndn-cxx/security/verification-helpers.hpp>
29
30namespace ndn {
31namespace ndncert {
32namespace tests {
33
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070034BOOST_FIXTURE_TEST_SUITE(TestClientModule, IdentityManagementTimeFixture)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080035
36BOOST_AUTO_TEST_CASE(ClientModuleInitialize)
37{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070038 ClientModule client(m_keyChain);
Zhiyi Zhang23564c82017-03-01 10:22:22 -080039 client.getClientConf().load("tests/unit-tests/client.conf.test");
40 BOOST_CHECK_EQUAL(client.getClientConf().m_caItems.size(), 2);
41}
42
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070043BOOST_AUTO_TEST_CASE(Probe)
Zhiyi Zhang23564c82017-03-01 10:22:22 -080044{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070045 ClientModule client(m_keyChain);
Zhiyi Zhang23564c82017-03-01 10:22:22 -080046 client.getClientConf().load("tests/unit-tests/client.conf.test");
47
Zhiyi Zhang10130782018-02-01 18:28:49 -080048 auto identity = addIdentity(Name("/site"));
Zhiyi Zhang23564c82017-03-01 10:22:22 -080049 auto key = identity.getDefaultKey();
50 auto cert = key.getDefaultCertificate();
51
52 ClientCaItem item;
Yufeng Zhang424d0362019-06-12 16:48:27 -070053 item.m_probe = "email:uid:name";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070054 item.m_caName = Name("/site");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080055 item.m_anchor = cert;
56 client.getClientConf().m_caItems.push_back(item);
57
Yufeng Zhang424d0362019-06-12 16:48:27 -070058 auto firstInterest = client.generateProbeInterest(item, "zhiyi@cs.ucla.edu:987654321:Zhiyi Zhang");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070059 BOOST_CHECK_EQUAL(firstInterest->getName().toUri(), "/site/CA/_PROBE");
Yufeng Zhang424d0362019-06-12 16:48:27 -070060 BOOST_CHECK_EQUAL(CaModule::jsonFromBlock(firstInterest->getApplicationParameters()).get<std::string>("email"),
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070061 "zhiyi@cs.ucla.edu");
Zhiyi Zhang23564c82017-03-01 10:22:22 -080062}
63
Yufeng Zhang424d0362019-06-12 16:48:27 -070064BOOST_AUTO_TEST_CASE(genProbeRequestJson)
65{
66 ClientModule client(m_keyChain);
67 client.getClientConf().load("tests/unit-tests/client.conf.test");
68
69 auto identity = addIdentity(Name("/site"));
70 auto key = identity.getDefaultKey();
71 auto cert = key.getDefaultCertificate();
72
73 ClientCaItem item;
74 item.m_probe = "email:uid:name";
75 item.m_caName = Name("/site");
76 item.m_anchor = cert;
77 client.getClientConf().m_caItems.push_back(item);
78
79 auto interestPacket = client.genProbeRequestJson(item, "yufeng@ucla.edu:123456789:Yufeng Zhang");
80 BOOST_CHECK_EQUAL(interestPacket.get("email", ""), "yufeng@ucla.edu");
81 BOOST_CHECK_EQUAL(interestPacket.get("uid", ""), "123456789");
82 BOOST_CHECK_EQUAL(interestPacket.get("name", ""), "Yufeng Zhang");
83}
84
Zhiyi Zhang23564c82017-03-01 10:22:22 -080085BOOST_AUTO_TEST_SUITE_END() // TestClientModule
86
87} // namespace tests
88} // namespace ndncert
89} // namespace ndn