comparison tests/src/libirccd/command-server-connect/main.cpp @ 796:1a6152af0866

misc: use ipv4 as option rather than family Now, all sections and JSON options that require a IP family will take ipv4 and ipv6 boolean options for convenience. It reduces parsing complexity and is more convenient for the user. Examples: # IPv6 server only [server] name = example port = 6667 hostname = example.org ipv4 = false ipv6 = true # IPv4 transport only [transport] type = ip ipv4 = true ipv6 = false port = 3320 If both options are defined (default everywhere), both protocols will be tried or bound.
author David Demelier <markand@malikania.fr>
date Sun, 11 Nov 2018 14:56:04 +0100
parents 3c090c1ff4f0
children 5a421b20a4f4
comparison
equal deleted inserted replaced
795:d42e8415e477 796:1a6152af0866
49 #if defined(IRCCD_HAVE_SSL) 49 #if defined(IRCCD_HAVE_SSL)
50 50
51 BOOST_AUTO_TEST_CASE(full) 51 BOOST_AUTO_TEST_CASE(full)
52 { 52 {
53 const auto [json, code] = request({ 53 const auto [json, code] = request({
54 { "command", "server-connect" }, 54 { "command", "server-connect" },
55 { "name", "local2" }, 55 { "name", "local2" },
56 { "hostname", "irc.example2.org" }, 56 { "hostname", "irc.example2.org" },
57 { "password", "nonono" }, 57 { "password", "nonono" },
58 { "nickname", "francis" }, 58 { "nickname", "francis" },
59 { "realname", "the_francis" }, 59 { "realname", "the_francis" },
60 { "username", "frc" }, 60 { "username", "frc" },
61 { "family", { "ipv6" } }, 61 { "ipv4", false },
62 { "ctcpVersion", "ultra bot" }, 62 { "ipv6", true },
63 { "commandChar", "::" }, 63 { "ctcpVersion", "ultra bot" },
64 { "port", 18000 }, 64 { "commandChar", "::" },
65 { "ssl", true }, 65 { "port", 18000 },
66 { "sslVerify", true }, 66 { "ssl", true },
67 { "autoRejoin", true }, 67 { "sslVerify", true },
68 { "joinInvite", true } 68 { "autoRejoin", true },
69 { "joinInvite", true }
69 }); 70 });
70 71
71 const auto s = irccd_.servers().get("local2"); 72 const auto s = irccd_.servers().get("local2");
72 73
73 BOOST_TEST(!code); 74 BOOST_TEST(!code);
96 BOOST_AUTO_TEST_CASE(already_exists) 97 BOOST_AUTO_TEST_CASE(already_exists)
97 { 98 {
98 irccd_.servers().add(std::make_unique<mock_server>(ctx_, "local")); 99 irccd_.servers().add(std::make_unique<mock_server>(ctx_, "local"));
99 100
100 const auto [json, code] = request({ 101 const auto [json, code] = request({
101 { "command", "server-connect" }, 102 { "command", "server-connect" },
102 { "name", "local" }, 103 { "name", "local" },
103 { "hostname", "127.0.0.1" } 104 { "hostname", "127.0.0.1" }
104 }); 105 });
105 106
106 BOOST_TEST(code == server_error::already_exists); 107 BOOST_TEST(code == server_error::already_exists);
107 BOOST_TEST(json["error"].get<int>() == server_error::already_exists); 108 BOOST_TEST(json["error"].get<int>() == server_error::already_exists);
108 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 109 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
109 } 110 }
110 111
111 BOOST_AUTO_TEST_CASE(invalid_hostname_1) 112 BOOST_AUTO_TEST_CASE(invalid_hostname_1)
112 { 113 {
113 const auto [json, code] = request({ 114 const auto [json, code] = request({
114 { "command", "server-connect" }, 115 { "command", "server-connect" },
115 { "name", "new" }, 116 { "name", "new" },
116 }); 117 });
117 118
118 BOOST_TEST(code == server_error::invalid_hostname); 119 BOOST_TEST(code == server_error::invalid_hostname);
119 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); 120 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname);
120 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 121 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
121 } 122 }
122 123
123 BOOST_AUTO_TEST_CASE(invalid_hostname_2) 124 BOOST_AUTO_TEST_CASE(invalid_hostname_2)
124 { 125 {
125 const auto [json, code] = request({ 126 const auto [json, code] = request({
126 { "command", "server-connect" }, 127 { "command", "server-connect" },
127 { "name", "new" }, 128 { "name", "new" },
128 { "hostname", 123456 } 129 { "hostname", 123456 }
129 }); 130 });
130 131
131 BOOST_TEST(code == server_error::invalid_hostname); 132 BOOST_TEST(code == server_error::invalid_hostname);
132 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname); 133 BOOST_TEST(json["error"].get<int>() == server_error::invalid_hostname);
133 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 134 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
134 } 135 }
135 136
136 BOOST_AUTO_TEST_CASE(invalid_identifier_1) 137 BOOST_AUTO_TEST_CASE(invalid_identifier_1)
137 { 138 {
138 const auto [json, code] = request({ 139 const auto [json, code] = request({
139 { "command", "server-connect" }, 140 { "command", "server-connect" },
140 { "name", "" }, 141 { "name", "" },
141 { "hostname", "127.0.0.1" } 142 { "hostname", "127.0.0.1" }
142 }); 143 });
143 144
144 BOOST_TEST(code == server_error::invalid_identifier); 145 BOOST_TEST(code == server_error::invalid_identifier);
145 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); 146 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier);
146 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 147 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
147 } 148 }
148 149
149 BOOST_AUTO_TEST_CASE(invalid_identifier_2) 150 BOOST_AUTO_TEST_CASE(invalid_identifier_2)
150 { 151 {
151 const auto [json, code] = request({ 152 const auto [json, code] = request({
152 { "command", "server-connect" }, 153 { "command", "server-connect" },
153 { "name", 123456 }, 154 { "name", 123456 },
154 { "hostname", "127.0.0.1" } 155 { "hostname", "127.0.0.1" }
155 }); 156 });
156 157
157 BOOST_TEST(code == server_error::invalid_identifier); 158 BOOST_TEST(code == server_error::invalid_identifier);
158 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier); 159 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier);
159 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 160 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
160 } 161 }
161 162
162 BOOST_AUTO_TEST_CASE(invalid_port_1) 163 BOOST_AUTO_TEST_CASE(invalid_port_1)
163 { 164 {
164 const auto [json, code] = request({ 165 const auto [json, code] = request({
165 { "command", "server-connect" }, 166 { "command", "server-connect" },
166 { "name", "new" }, 167 { "name", "new" },
167 { "hostname", "127.0.0.1" }, 168 { "hostname", "127.0.0.1" },
168 { "port", "notaint" } 169 { "port", "notaint" }
169 }); 170 });
170 171
171 BOOST_TEST(code == server_error::invalid_port); 172 BOOST_TEST(code == server_error::invalid_port);
172 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); 173 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port);
173 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 174 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
174 } 175 }
175 176
176 BOOST_AUTO_TEST_CASE(invalid_port_2) 177 BOOST_AUTO_TEST_CASE(invalid_port_2)
177 { 178 {
178 const auto [json, code] = request({ 179 const auto [json, code] = request({
179 { "command", "server-connect" }, 180 { "command", "server-connect" },
180 { "name", "new" }, 181 { "name", "new" },
181 { "hostname", "127.0.0.1" }, 182 { "hostname", "127.0.0.1" },
182 { "port", -123 } 183 { "port", -123 }
183 }); 184 });
184 185
185 BOOST_TEST(code == server_error::invalid_port); 186 BOOST_TEST(code == server_error::invalid_port);
186 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); 187 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port);
187 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 188 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
188 } 189 }
189 190
190 BOOST_AUTO_TEST_CASE(invalid_port_3) 191 BOOST_AUTO_TEST_CASE(invalid_port_3)
191 { 192 {
192 const auto [json, code] = request({ 193 const auto [json, code] = request({
193 { "command", "server-connect" }, 194 { "command", "server-connect" },
194 { "name", "new" }, 195 { "name", "new" },
195 { "hostname", "127.0.0.1" }, 196 { "hostname", "127.0.0.1" },
196 { "port", 1000000 } 197 { "port", 1000000 }
197 }); 198 });
198 199
199 BOOST_TEST(code == server_error::invalid_port); 200 BOOST_TEST(code == server_error::invalid_port);
200 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port); 201 BOOST_TEST(json["error"].get<int>() == server_error::invalid_port);
201 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 202 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
204 #if !defined(IRCCD_HAVE_SSL) 205 #if !defined(IRCCD_HAVE_SSL)
205 206
206 BOOST_AUTO_TEST_CASE(ssl_disabled) 207 BOOST_AUTO_TEST_CASE(ssl_disabled)
207 { 208 {
208 const auto [json, code] = request({ 209 const auto [json, code] = request({
209 { "command", "server-connect" }, 210 { "command", "server-connect" },
210 { "name", "new" }, 211 { "name", "new" },
211 { "hostname", "127.0.0.1" }, 212 { "hostname", "127.0.0.1" },
212 { "ssl", true } 213 { "ssl", true }
213 }); 214 });
214 215
215 BOOST_TEST(code == server_error::ssl_disabled); 216 BOOST_TEST(code == server_error::ssl_disabled);
216 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled); 217 BOOST_TEST(json["error"].get<int>() == server_error::ssl_disabled);
217 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 218 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
220 #endif 221 #endif
221 222
222 BOOST_AUTO_TEST_CASE(invalid_family_1) 223 BOOST_AUTO_TEST_CASE(invalid_family_1)
223 { 224 {
224 const auto [json, code] = request({ 225 const auto [json, code] = request({
225 { "command", "server-connect" }, 226 { "command", "server-connect" },
226 { "name", "new" }, 227 { "name", "new" },
227 { "hostname", "127.0.0.1" }, 228 { "hostname", "127.0.0.1" },
228 { "port", 1000000 }, 229 { "port", 6667 },
229 { "family", "invalid" } 230 { "ipv4", "invalid" }
230 }); 231 });
231 232
232 BOOST_TEST(code == server_error::invalid_family); 233 BOOST_TEST(code == server_error::invalid_family);
233 BOOST_TEST(json["error"].get<int>() == server_error::invalid_family); 234 BOOST_TEST(json["error"].get<int>() == server_error::invalid_family);
234 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 235 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
235 } 236 }
236 237
237 BOOST_AUTO_TEST_CASE(invalid_family_2) 238 BOOST_AUTO_TEST_CASE(invalid_family_2)
238 { 239 {
239 const auto [json, code] = request({ 240 const auto [json, code] = request({
240 { "command", "server-connect" }, 241 { "command", "server-connect" },
241 { "name", "new" }, 242 { "name", "new" },
242 { "hostname", "127.0.0.1" }, 243 { "hostname", "127.0.0.1" },
243 { "port", 1000000 }, 244 { "port", 6667 },
244 { "family", { 123, 456 } } 245 { "ipv6", 1234 }
245 }); 246 });
246 247
247 BOOST_TEST(code == server_error::invalid_family); 248 BOOST_TEST(code == server_error::invalid_family);
248 BOOST_TEST(json["error"].get<int>() == server_error::invalid_family); 249 BOOST_TEST(json["error"].get<int>() == server_error::invalid_family);
249 BOOST_TEST(json["errorCategory"].get<std::string>() == "server"); 250 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");