blob: 61a74e50bef9439906fbb7b9ebb3279d2d1b61c5 [file] [log] [blame]
Zhiyi Zhang19768a52017-01-18 14:44:15 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
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 Zhang3b267e62017-02-09 17:59:34 -080021#include "boost-test.hpp"
Zhiyi Zhang19768a52017-01-18 14:44:15 -080022#include "json-helper.hpp"
23
24namespace ndn {
25namespace ndncert {
26namespace tests {
27
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080028BOOST_AUTO_TEST_SUITE(TestJsonHelper)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080029
30BOOST_AUTO_TEST_CASE(GenerateProbeJson)
31{
32 auto result = genResponseProbeJson(Name("/ndn/edu/ucla/cs/zhiyi/macbook"),
33 Name("/ndn/edu/ucla/cs/zhiyi/ca-info"));
34 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_IDNENTIFIER), "/ndn/edu/ucla/cs/zhiyi/macbook");
35 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CA_INFO), "/ndn/edu/ucla/cs/zhiyi/ca-info");
36}
37
38BOOST_AUTO_TEST_CASE(GenerateNewResponseJson)
39{
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080040 std::list<std::string> challenges;
41 challenges.push_back("PIN");
42 challenges.push_back("EMAIL");
43 auto result = genResponseNewJson("598234759", challenges);
Zhiyi Zhang19768a52017-01-18 14:44:15 -080044
Zhiyi Zhang19768a52017-01-18 14:44:15 -080045 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_REQUEST_ID), "598234759");
46 auto child = result.get_child(JSON_CHALLENGES);
47 auto it = child.begin();
48 BOOST_CHECK_EQUAL(it->second.get<std::string>(JSON_CHALLENGE_TYPE), "PIN");
Zhiyi Zhang19768a52017-01-18 14:44:15 -080049 it++;
50 BOOST_CHECK_EQUAL(it->second.get<std::string>(JSON_CHALLENGE_TYPE), "EMAIL");
Zhiyi Zhang19768a52017-01-18 14:44:15 -080051}
52
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080053BOOST_AUTO_TEST_CASE(GenerateChallengeResponseJson)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080054{
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080055 auto result = genResponseChallengeJson("598234759", "EMAIL", "need-code");
Zhiyi Zhang19768a52017-01-18 14:44:15 -080056
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080057 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_REQUEST_ID), "598234759");
58 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_TYPE), "EMAIL");
59 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "need-code");
Zhiyi Zhang19768a52017-01-18 14:44:15 -080060
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080061 result = genResponseChallengeJson("598234759", "EMAIL", "need-code", Name("/ndn/test"));
62
63 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_REQUEST_ID), "598234759");
64 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CHALLENGE_TYPE), "EMAIL");
65 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "need-code");
66 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_CERTIFICATE), "/ndn/test");
Zhiyi Zhang19768a52017-01-18 14:44:15 -080067}
68
69BOOST_AUTO_TEST_CASE(GenerateErrorJson)
70{
71 auto result = genErrorJson("The certificate name already exists");
72 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_STATUS), "error");
73 BOOST_CHECK_EQUAL(result.get<std::string>(JSON_ERROR_INFO),
74 "The certificate name already exists");
75}
76
77BOOST_AUTO_TEST_SUITE_END() // TestJsonHelper
78
79} // namespace tests
80} // namespace ndncert
81} // namespace ndn