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>
26 #include <boost/asio.hpp>
27 #include <boost/beast/core/tcp_stream.hpp>
28 #include <boost/beast/ssl/ssl_stream.hpp>
29 #include <boost/optional.hpp>
30 #include <boost/utility/in_place_factory.hpp>
34 #include <test/jtx/CaptureLogs.h>
35 #include <test/jtx/envconfig.h>
36 #include <test/unit_test/SuiteJournal.h>
52 boost::optional<boost::asio::io_service::work>
work_;
58 ,
thread_([&]() { this->io_service_.run(); })
68 boost::asio::io_service&
82 explicit TestSink(beast::unit_test::suite& suite)
113 boost::asio::ip::tcp::endpoint remote_address)
122 boost::asio::ip::tcp::endpoint remote_address)
158 template <
class Socket>
160 connect(Socket& s,
typename Socket::endpoint_type
const& ep)
177 template <
class SyncWriteStream>
183 boost::asio::write(s, boost::asio::buffer(text));
195 template <
class SyncReadStream>
199 boost::asio::streambuf b(1000);
202 auto const n = boost::asio::read_until(s, b,
'\n');
203 if (BEAST_EXPECT(n == match.size()))
207 boost::asio::buffer_copy(
208 boost::asio::buffer(&got[0], n), b.data());
209 return BEAST_EXPECT(got == match);
226 boost::asio::io_service ios;
227 using socket = boost::asio::ip::tcp::socket;
236 "Connection: close\r\n"
243 boost::system::error_code ec;
244 s.shutdown(socket::shutdown_both, ec);
252 boost::asio::io_service ios;
253 using socket = boost::asio::ip::tcp::socket;
262 "Connection: Keep-Alive\r\n"
272 "Connection: close\r\n"
279 boost::system::error_code ec;
280 s.shutdown(socket::shutdown_both, ec);
286 testcase(
"Basic client/server");
289 sink.threshold(beast::severities::Severity::kAll);
294 serverPort.
back().ip =
296 serverPort.
back().port = 0;
297 serverPort.
back().protocol.insert(
"http");
298 auto eps = s->ports(serverPort);
299 log <<
"server listening on port " << eps[0].port() <<
std::endl;
310 testcase(
"stress test");
314 onAccept(
Session& session, boost::asio::ip::tcp::endpoint endpoint)
324 boost::asio::ip::tcp::endpoint remote_address)
333 boost::asio::ip::tcp::endpoint remote_address)
351 onClose(
Session& session, boost::system::error_code
const&)
365 for (
int i = 0; i < 1000; ++i)
370 serverPort.
back().ip =
372 serverPort.
back().port = 0;
373 serverPort.
back().protocol.insert(
"http");
374 s->ports(serverPort);
382 testcase(
"Server config - invalid options");
383 using namespace test::jtx;
391 (*cfg).deprecatedClearSection(
"port_rpc");
394 std::make_unique<CaptureLogs>(&messages)};
397 messages.
find(
"Missing 'ip' in [port_rpc]") != std::string::npos);
403 (*cfg).deprecatedClearSection(
"port_rpc");
407 std::make_unique<CaptureLogs>(&messages)};
410 messages.
find(
"Missing 'port' in [port_rpc]") != std::string::npos);
416 (*cfg).deprecatedClearSection(
"port_rpc");
418 (*cfg)[
"port_rpc"].set(
"port",
"0");
421 std::make_unique<CaptureLogs>(&messages)};
424 messages.
find(
"Invalid value '0' for key 'port' in [port_rpc]") !=
431 (*cfg).deprecatedClearSection(
"port_rpc");
433 (*cfg)[
"port_rpc"].set(
"port",
"8081");
434 (*cfg)[
"port_rpc"].set(
"protocol",
"");
437 std::make_unique<CaptureLogs>(&messages)};
440 messages.
find(
"Missing 'protocol' in [port_rpc]") !=
450 cfg = std::make_unique<Config>();
455 cfg->deprecatedClearSection(
457 cfg->legacy(
"database_path",
"");
458 cfg->setupControl(
true,
true,
true);
460 (*cfg)[
"port_peer"].set(
"port",
"8080");
461 (*cfg)[
"port_peer"].set(
"protocol",
"peer");
463 (*cfg)[
"port_rpc"].set(
"port",
"8081");
464 (*cfg)[
"port_rpc"].set(
"protocol",
"http,ws2");
467 (*cfg)[
"port_ws"].set(
"port",
"8082");
468 (*cfg)[
"port_ws"].set(
"protocol",
"ws");
472 std::make_unique<CaptureLogs>(&messages)};
475 messages.
find(
"Required section [server] is missing") !=
484 cfg = std::make_unique<Config>();
489 cfg->deprecatedClearSection(
491 cfg->legacy(
"database_path",
"");
492 cfg->setupControl(
true,
true,
true);
493 (*cfg)[
"server"].append(
"port_peer");
494 (*cfg)[
"server"].append(
"port_rpc");
495 (*cfg)[
"server"].append(
"port_ws");
498 std::make_unique<CaptureLogs>(&messages)};
501 messages.
find(
"Missing section: [port_peer]") != std::string::npos);