Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 914d05f | 2019-07-13 16:20:19 -0400 | [diff] [blame] | 2 | /* |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2019, Regents of the University of California. |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 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 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 21 | #include "client-module.hpp" |
| 22 | #include "challenge-module.hpp" |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 23 | #include "ca-module.hpp" |
Davide Pesavento | 914d05f | 2019-07-13 16:20:19 -0400 | [diff] [blame] | 24 | |
| 25 | #include "identity-management-fixture.hpp" |
| 26 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 27 | #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 | |
| 32 | namespace ndn { |
| 33 | namespace ndncert { |
| 34 | namespace tests { |
| 35 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 36 | BOOST_FIXTURE_TEST_SUITE(TestClientModule, IdentityManagementTimeFixture) |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 37 | |
| 38 | BOOST_AUTO_TEST_CASE(ClientModuleInitialize) |
| 39 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 40 | ClientModule client(m_keyChain); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 41 | client.getClientConf().load("tests/unit-tests/client.conf.test"); |
| 42 | BOOST_CHECK_EQUAL(client.getClientConf().m_caItems.size(), 2); |
| 43 | } |
| 44 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 45 | BOOST_AUTO_TEST_CASE(Probe) |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 46 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 47 | ClientModule client(m_keyChain); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 48 | client.getClientConf().load("tests/unit-tests/client.conf.test"); |
| 49 | |
Zhiyi Zhang | 1013078 | 2018-02-01 18:28:49 -0800 | [diff] [blame] | 50 | auto identity = addIdentity(Name("/site")); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 51 | auto key = identity.getDefaultKey(); |
| 52 | auto cert = key.getDefaultCertificate(); |
| 53 | |
| 54 | ClientCaItem item; |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 55 | item.m_probe = "email:uid:name"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 56 | item.m_caName = Name("/site"); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 57 | item.m_anchor = cert; |
| 58 | client.getClientConf().m_caItems.push_back(item); |
| 59 | |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 60 | auto firstInterest = client.generateProbeInterest(item, "zhiyi@cs.ucla.edu:987654321:Zhiyi Zhang"); |
Davide Pesavento | 914d05f | 2019-07-13 16:20:19 -0400 | [diff] [blame] | 61 | 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 Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 64 | BOOST_CHECK_EQUAL(CaModule::jsonFromBlock(firstInterest->getApplicationParameters()).get<std::string>("email"), |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 65 | "zhiyi@cs.ucla.edu"); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Davide Pesavento | 914d05f | 2019-07-13 16:20:19 -0400 | [diff] [blame] | 68 | BOOST_AUTO_TEST_CASE(GenProbeRequestJson) |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 69 | { |
| 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 Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 89 | BOOST_AUTO_TEST_SUITE_END() // TestClientModule |
| 90 | |
| 91 | } // namespace tests |
| 92 | } // namespace ndncert |
| 93 | } // namespace ndn |