Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 87208f9 | 2022-08-30 19:51:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2022 Regents of the University of California. |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library 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 Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 22 | #include "ndn-cxx/security/validation-error.hpp" |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 25 | |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 26 | #include <boost/lexical_cast.hpp> |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace security { |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 30 | inline namespace v2 { |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 31 | namespace tests { |
| 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(Security) |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(TestValidationError) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Basic) |
| 37 | { |
Davide Pesavento | 87208f9 | 2022-08-30 19:51:23 -0400 | [diff] [blame] | 38 | ValidationError e1{ValidationError::INVALID_SIGNATURE}; |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 39 | BOOST_CHECK_EQUAL(e1.getCode(), 1); |
| 40 | BOOST_CHECK_EQUAL(e1.getInfo(), ""); |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 41 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e1), "Signature verification failed"); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 42 | |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 43 | ValidationError e2{ValidationError::MALFORMED_SIGNATURE, "message"}; |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL(e2.getCode(), 2); |
| 45 | BOOST_CHECK_EQUAL(e2.getInfo(), "message"); |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e2), "Missing or malformed signature (message)"); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 47 | |
| 48 | ValidationError e3{65535, "other message"}; |
| 49 | BOOST_CHECK_EQUAL(e3.getCode(), 65535); |
| 50 | BOOST_CHECK_EQUAL(e3.getInfo(), "other message"); |
| 51 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e3), "Custom error code 65535 (other message)"); |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 52 | |
| 53 | ValidationError e4{200}; |
| 54 | BOOST_CHECK_EQUAL(e4.getCode(), 200); |
| 55 | BOOST_CHECK_EQUAL(e4.getInfo(), ""); |
| 56 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e4), "Unknown error code 200"); |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | BOOST_AUTO_TEST_SUITE_END() // TestValidationError |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 60 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 61 | |
| 62 | } // namespace tests |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 63 | } // inline namespace v2 |
Alexander Afanasyev | 7e72141 | 2017-01-11 13:36:08 -0800 | [diff] [blame] | 64 | } // namespace security |
| 65 | } // namespace ndn |