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