Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/websocket-factory.hpp" |
| 27 | |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 28 | #include "face-system-fixture.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 32 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 33 | namespace tests { |
| 34 | |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 35 | namespace ip = boost::asio::ip; |
| 36 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 37 | using WebSocketFactoryFixture = FaceSystemFactoryFixture<WebSocketFactory>; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 39 | BOOST_AUTO_TEST_SUITE(Face) |
| 40 | BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, WebSocketFactoryFixture) |
| 41 | |
| 42 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 43 | |
| 44 | BOOST_AUTO_TEST_CASE(Normal) |
| 45 | { |
| 46 | const std::string CONFIG = R"CONFIG( |
| 47 | face_system |
| 48 | { |
| 49 | websocket |
| 50 | { |
| 51 | listen yes |
| 52 | port 9696 |
| 53 | enable_v4 yes |
| 54 | enable_v6 yes |
| 55 | } |
| 56 | } |
| 57 | )CONFIG"; |
| 58 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 59 | parseConfig(CONFIG, true); |
| 60 | parseConfig(CONFIG, false); |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 61 | |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 62 | checkChannelListEqual(factory, {"ws://[::]:9696"}); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(EnableIpv4Only) |
| 66 | { |
| 67 | const std::string CONFIG = R"CONFIG( |
| 68 | face_system |
| 69 | { |
| 70 | websocket |
| 71 | { |
| 72 | listen yes |
| 73 | port 9696 |
| 74 | enable_v4 yes |
| 75 | enable_v6 no |
| 76 | } |
| 77 | } |
| 78 | )CONFIG"; |
| 79 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 80 | parseConfig(CONFIG, true); |
| 81 | parseConfig(CONFIG, false); |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 82 | |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 83 | checkChannelListEqual(factory, {"ws://0.0.0.0:9696"}); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(UnsupportedIpv6Only) |
| 87 | { |
| 88 | const std::string CONFIG = R"CONFIG( |
| 89 | face_system |
| 90 | { |
| 91 | websocket |
| 92 | { |
| 93 | listen yes |
| 94 | port 9696 |
| 95 | enable_v4 no |
| 96 | enable_v6 yes |
| 97 | } |
| 98 | } |
| 99 | )CONFIG"; |
| 100 | |
| 101 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 102 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 103 | } |
| 104 | |
| 105 | BOOST_AUTO_TEST_CASE(ChannelsDisabled) |
| 106 | { |
| 107 | const std::string CONFIG = R"CONFIG( |
| 108 | face_system |
| 109 | { |
| 110 | websocket |
| 111 | { |
| 112 | listen yes |
| 113 | port 9696 |
| 114 | enable_v4 no |
| 115 | enable_v6 no |
| 116 | } |
| 117 | } |
| 118 | )CONFIG"; |
| 119 | |
| 120 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 121 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 122 | } |
| 123 | |
| 124 | BOOST_AUTO_TEST_CASE(NoListen) |
| 125 | { |
| 126 | const std::string CONFIG = R"CONFIG( |
| 127 | face_system |
| 128 | { |
| 129 | websocket |
| 130 | { |
| 131 | listen no |
| 132 | port 9696 |
| 133 | enable_v4 yes |
| 134 | enable_v6 yes |
| 135 | } |
| 136 | } |
| 137 | )CONFIG"; |
| 138 | |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 140 | } |
| 141 | |
| 142 | BOOST_AUTO_TEST_CASE(ChangeEndpoint) |
| 143 | { |
| 144 | const std::string CONFIG1 = R"CONFIG( |
| 145 | face_system |
| 146 | { |
| 147 | websocket |
| 148 | { |
| 149 | port 9001 |
| 150 | } |
| 151 | } |
| 152 | )CONFIG"; |
| 153 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 154 | parseConfig(CONFIG1, false); |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 155 | checkChannelListEqual(factory, {"ws://[::]:9001"}); |
| 156 | |
| 157 | const std::string CONFIG2 = R"CONFIG( |
| 158 | face_system |
| 159 | { |
| 160 | websocket |
| 161 | { |
| 162 | port 9002 |
| 163 | } |
| 164 | } |
| 165 | )CONFIG"; |
| 166 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 167 | parseConfig(CONFIG2, false); |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 168 | checkChannelListEqual(factory, {"ws://[::]:9001", "ws://[::]:9002"}); |
| 169 | } |
| 170 | |
| 171 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 172 | |
| 173 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 174 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 175 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 176 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 177 | std::set<std::string> expected; |
| 178 | expected.insert(factory.createChannel("127.0.0.1", "20070")->getUri().toString()); |
| 179 | expected.insert(factory.createChannel("127.0.0.1", "20071")->getUri().toString()); |
| 180 | expected.insert(factory.createChannel("::1", "20071")->getUri().toString()); |
| 181 | checkChannelListEqual(factory, expected); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 184 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 185 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 186 | createFace(factory, |
| 187 | FaceUri("ws://127.0.0.1:20070"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 188 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 189 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 190 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 191 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 192 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 193 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 194 | createFace(factory, |
| 195 | FaceUri("ws://127.0.0.1:20070"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 196 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 197 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 198 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 199 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 200 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 201 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 202 | createFace(factory, |
| 203 | FaceUri("ws://127.0.0.1:20070"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 204 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 205 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 206 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 207 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 208 | {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | BOOST_AUTO_TEST_SUITE_END() // TestWebSocketFactory |
| 212 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 213 | |
| 214 | } // namespace tests |
Junxiao Shi | 3409cd3 | 2017-01-18 15:31:27 +0000 | [diff] [blame] | 215 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 216 | } // namespace nfd |