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);
312 testcase(
"stress test");
316 onAccept(
Session& session, boost::asio::ip::tcp::endpoint endpoint)
326 boost::asio::ip::tcp::endpoint remote_address)
335 boost::asio::ip::tcp::endpoint remote_address)
353 onClose(
Session& session, boost::system::error_code
const&)
367 for (
int i = 0; i < 1000; ++i)
372 serverPort.
back().ip =
374 serverPort.
back().port = 0;
375 serverPort.
back().protocol.insert(
"http");
376 s->ports(serverPort);
384 testcase(
"Server config - invalid options");
385 using namespace test::jtx;
393 (*cfg).deprecatedClearSection(
"port_rpc");
396 std::make_unique<CaptureLogs>(&messages)};
399 messages.
find(
"Missing 'ip' in [port_rpc]") != std::string::npos);
405 (*cfg).deprecatedClearSection(
"port_rpc");
409 std::make_unique<CaptureLogs>(&messages)};
412 messages.
find(
"Missing 'port' in [port_rpc]") != std::string::npos);
418 (*cfg).deprecatedClearSection(
"port_rpc");
420 (*cfg)[
"port_rpc"].set(
"port",
"0");
423 std::make_unique<CaptureLogs>(&messages)};
426 messages.
find(
"Invalid value '0' for key 'port' in [port_rpc]") !=
433 (*cfg).deprecatedClearSection(
"port_rpc");
435 (*cfg)[
"port_rpc"].set(
"port",
"8081");
436 (*cfg)[
"port_rpc"].set(
"protocol",
"");
439 std::make_unique<CaptureLogs>(&messages)};
442 messages.
find(
"Missing 'protocol' in [port_rpc]") !=
452 cfg = std::make_unique<Config>();
457 cfg->deprecatedClearSection(
459 cfg->legacy(
"database_path",
"");
460 cfg->setupControl(
true,
true,
true);
462 (*cfg)[
"port_peer"].set(
"port",
"8080");
463 (*cfg)[
"port_peer"].set(
"protocol",
"peer");
465 (*cfg)[
"port_rpc"].set(
"port",
"8081");
466 (*cfg)[
"port_rpc"].set(
"protocol",
"http,ws2");
469 (*cfg)[
"port_ws"].set(
"port",
"8082");
470 (*cfg)[
"port_ws"].set(
"protocol",
"ws");
474 std::make_unique<CaptureLogs>(&messages)};
477 messages.
find(
"Required section [server] is missing") !=
486 cfg = std::make_unique<Config>();
491 cfg->deprecatedClearSection(
493 cfg->legacy(
"database_path",
"");
494 cfg->setupControl(
true,
true,
true);
495 (*cfg)[
"server"].append(
"port_peer");
496 (*cfg)[
"server"].append(
"port_rpc");
497 (*cfg)[
"server"].append(
"port_ws");
500 std::make_unique<CaptureLogs>(&messages)};
503 messages.
find(
"Missing section: [port_peer]") != std::string::npos);