20 #include <ripple/basics/make_SSLContext.h>
21 #include <ripple/beast/rfc2616.h>
22 #include <ripple/beast/unit_test.h>
23 #include <ripple/core/ConfigSections.h>
24 #include <ripple/server/Server.h>
25 #include <ripple/server/Session.h>
28 #include <test/jtx/CaptureLogs.h>
29 #include <test/jtx/envconfig.h>
30 #include <test/unit_test/SuiteJournal.h>
32 #include <boost/asio.hpp>
33 #include <boost/beast/core/tcp_stream.hpp>
34 #include <boost/beast/ssl/ssl_stream.hpp>
35 #include <boost/utility/in_place_factory.hpp>
61 ,
thread_([&]() { this->io_service_.run(); })
71 boost::asio::io_service&
85 explicit TestSink(beast::unit_test::suite& suite)
116 boost::asio::ip::tcp::endpoint remote_address)
125 boost::asio::ip::tcp::endpoint remote_address)
161 template <
class Socket>
163 connect(Socket& s,
typename Socket::endpoint_type
const& ep)
180 template <
class SyncWriteStream>
186 boost::asio::write(s, boost::asio::buffer(text));
198 template <
class SyncReadStream>
202 boost::asio::streambuf b(1000);
205 auto const n = boost::asio::read_until(s, b,
'\n');
206 if (BEAST_EXPECT(n == match.size()))
210 boost::asio::buffer_copy(
211 boost::asio::buffer(&got[0], n), b.data());
212 return BEAST_EXPECT(got == match);
229 boost::asio::io_service ios;
230 using socket = boost::asio::ip::tcp::socket;
239 "Connection: close\r\n"
246 boost::system::error_code ec;
247 s.shutdown(socket::shutdown_both, ec);
255 boost::asio::io_service ios;
256 using socket = boost::asio::ip::tcp::socket;
265 "Connection: Keep-Alive\r\n"
275 "Connection: close\r\n"
282 boost::system::error_code ec;
283 s.shutdown(socket::shutdown_both, ec);
289 testcase(
"Basic client/server");
292 sink.threshold(beast::severities::Severity::kAll);
297 serverPort.
back().ip =
299 serverPort.
back().port = 0;
300 serverPort.
back().protocol.insert(
"http");
301 auto eps = s->ports(serverPort);
302 log <<
"server listening on port " << eps[0].port() <<
std::endl;
313 testcase(
"stress test");
317 onAccept(
Session& session, boost::asio::ip::tcp::endpoint endpoint)
327 boost::asio::ip::tcp::endpoint remote_address)
336 boost::asio::ip::tcp::endpoint remote_address)
354 onClose(
Session& session, boost::system::error_code
const&)
368 for (
int i = 0; i < 1000; ++i)
373 serverPort.
back().ip =
375 serverPort.
back().port = 0;
376 serverPort.
back().protocol.insert(
"http");
377 s->ports(serverPort);
385 testcase(
"Server config - invalid options");
386 using namespace test::jtx;
394 (*cfg).deprecatedClearSection(
"port_rpc");
397 std::make_unique<CaptureLogs>(&messages)};
400 messages.
find(
"Missing 'ip' in [port_rpc]") != std::string::npos);
406 (*cfg).deprecatedClearSection(
"port_rpc");
410 std::make_unique<CaptureLogs>(&messages)};
413 messages.
find(
"Missing 'port' in [port_rpc]") != std::string::npos);
419 (*cfg).deprecatedClearSection(
"port_rpc");
421 (*cfg)[
"port_rpc"].set(
"port",
"0");
424 std::make_unique<CaptureLogs>(&messages)};
427 messages.
find(
"Invalid value '0' for key 'port' in [port_rpc]") !=
434 (*cfg).deprecatedClearSection(
"port_rpc");
436 (*cfg)[
"port_rpc"].set(
"port",
"8081");
437 (*cfg)[
"port_rpc"].set(
"protocol",
"");
440 std::make_unique<CaptureLogs>(&messages)};
443 messages.
find(
"Missing 'protocol' in [port_rpc]") !=
453 cfg = std::make_unique<Config>();
458 cfg->deprecatedClearSection(
460 cfg->legacy(
"database_path",
"");
461 cfg->setupControl(
true,
true,
true);
463 (*cfg)[
"port_peer"].set(
"port",
"8080");
464 (*cfg)[
"port_peer"].set(
"protocol",
"peer");
466 (*cfg)[
"port_rpc"].set(
"port",
"8081");
467 (*cfg)[
"port_rpc"].set(
"protocol",
"http,ws2");
470 (*cfg)[
"port_ws"].set(
"port",
"8082");
471 (*cfg)[
"port_ws"].set(
"protocol",
"ws");
475 std::make_unique<CaptureLogs>(&messages)};
478 messages.
find(
"Required section [server] is missing") !=
487 cfg = std::make_unique<Config>();
492 cfg->deprecatedClearSection(
494 cfg->legacy(
"database_path",
"");
495 cfg->setupControl(
true,
true,
true);
496 (*cfg)[
"server"].append(
"port_peer");
497 (*cfg)[
"server"].append(
"port_rpc");
498 (*cfg)[
"server"].append(
"port_ws");
501 std::make_unique<CaptureLogs>(&messages)};
504 messages.
find(
"Missing section: [port_peer]") != std::string::npos);