20 #include <ripple/basics/make_SSLContext.h>
21 #include <ripple/beast/rfc2616.h>
22 #include <ripple/server/Server.h>
23 #include <ripple/server/Session.h>
24 #include <ripple/beast/unit_test.h>
25 #include <ripple/core/ConfigSections.h>
27 #include <test/jtx/envconfig.h>
28 #include <test/unit_test/SuiteJournal.h>
29 #include <boost/asio.hpp>
30 #include <boost/optional.hpp>
31 #include <boost/utility/in_place_factory.hpp>
32 #include <boost/beast/core/tcp_stream.hpp>
33 #include <boost/beast/ssl/ssl_stream.hpp>
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)
83 :
Sink (
beast::severities::kWarning, false)
105 boost::asio::ip::tcp::endpoint endpoint)
114 boost::asio::ip::tcp::endpoint remote_address)
121 boost::asio::ip::tcp::endpoint remote_address)
133 session.
close (
true);
144 boost::system::error_code
const&)
157 template <
class Socket>
159 connect (Socket& s,
typename Socket::endpoint_type
const& ep)
176 template <
class SyncWriteStream>
182 boost::asio::write (s, boost::asio::buffer (text));
194 template <
class SyncReadStream>
198 boost::asio::streambuf b (1000);
201 auto const n = boost::asio::read_until (s, b,
'\n');
202 if (BEAST_EXPECT(n == match.size()))
206 boost::asio::buffer_copy (boost::asio::buffer (
207 &got[0], n), b.data());
208 return BEAST_EXPECT(got == match);
225 boost::asio::io_service ios;
226 using socket = boost::asio::ip::tcp::socket;
234 "Connection: close\r\n"
241 boost::system::error_code ec;
242 s.shutdown(socket::shutdown_both, ec);
250 boost::asio::io_service ios;
251 using socket = boost::asio::ip::tcp::socket;
259 "Connection: Keep-Alive\r\n"
268 "Connection: close\r\n"
275 boost::system::error_code ec;
276 s.shutdown(socket::shutdown_both, ec);
281 testcase(
"Basic client/server");
284 sink.threshold (beast::severities::Severity::kAll);
290 serverPort.
back().ip =
292 serverPort.
back().port = 0;
293 serverPort.
back().protocol.insert(
"http");
294 auto eps = s->ports (serverPort);
295 log <<
"server listening on port " << eps[0].port() <<
std::endl;
305 testcase(
"stress test");
310 boost::asio::ip::tcp::endpoint endpoint)
319 boost::asio::ip::tcp::endpoint remote_address)
326 boost::asio::ip::tcp::endpoint remote_address)
344 boost::system::error_code
const&)
349 onStopped (
Server& server)
358 for(
int i = 0; i < 1000; ++i)
364 serverPort.
back().ip =
366 serverPort.
back().port = 0;
367 serverPort.
back().protocol.insert(
"http");
368 s->ports (serverPort);
428 testcase (
"Server config - invalid options");
429 using namespace test::jtx;
437 (*cfg).deprecatedClearSection(
"port_rpc");
440 std::make_unique<CaptureLogs>(messages)};
443 messages.
find (
"Missing 'ip' in [port_rpc]")
444 != std::string::npos);
450 (*cfg).deprecatedClearSection(
"port_rpc");
454 std::make_unique<CaptureLogs>(messages)};
457 messages.
find (
"Missing 'port' in [port_rpc]")
458 != std::string::npos);
464 (*cfg).deprecatedClearSection(
"port_rpc");
466 (*cfg)[
"port_rpc"].set(
"port",
"0");
469 std::make_unique<CaptureLogs>(messages)};
472 messages.
find (
"Invalid value '0' for key 'port' in [port_rpc]")
473 != std::string::npos);
479 (*cfg).deprecatedClearSection(
"port_rpc");
481 (*cfg)[
"port_rpc"].set(
"port",
"8081");
482 (*cfg)[
"port_rpc"].set(
"protocol",
"");
485 std::make_unique<CaptureLogs>(messages)};
488 messages.
find (
"Missing 'protocol' in [port_rpc]")
489 != std::string::npos);
496 cfg = std::make_unique<Config>();
501 cfg->deprecatedClearSection (
503 cfg->legacy(
"database_path",
"");
504 cfg->setupControl(
true,
true,
true);
506 (*cfg)[
"port_peer"].set(
"port",
"8080");
507 (*cfg)[
"port_peer"].set(
"protocol",
"peer");
509 (*cfg)[
"port_rpc"].set(
"port",
"8081");
510 (*cfg)[
"port_rpc"].set(
"protocol",
"http,ws2");
513 (*cfg)[
"port_ws"].set(
"port",
"8082");
514 (*cfg)[
"port_ws"].set(
"protocol",
"ws");
518 std::make_unique<CaptureLogs>(messages)};
521 messages.
find (
"Required section [server] is missing")
522 != std::string::npos);
529 cfg = std::make_unique<Config>();
533 cfg->legacy(
"database_path",
"");
534 cfg->setupControl(
true,
true,
true);
535 (*cfg)[
"server"].append(
"port_peer");
536 (*cfg)[
"server"].append(
"port_rpc");
537 (*cfg)[
"server"].append(
"port_ws");
540 std::make_unique<CaptureLogs>(messages)};
543 messages.
find (
"Missing section: [port_peer]")
544 != std::string::npos);
Abstraction for the underlying message destination.
std::unique_ptr< Server > make_Server(Handler &handler, boost::asio::io_service &io_service, beast::Journal journal)
Create the HTTP server using the specified handler.
BEAST_DEFINE_TESTSUITE(AccountDelete, app, ripple)
Manages partitions for logging.
Handoff onHandoff(Session &session, http_request_type &&request, boost::asio::ip::tcp::endpoint remote_address)
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
boost::beast::tcp_stream socket_type
static std::string importNodeDatabase()
std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::severities::Severity threshold) override
A namespace for easy access to logging severity values.
boost::asio::io_service & get_io_service()
void onRequest(Session &session)
bool onAccept(Session &session, boost::asio::ip::tcp::endpoint endpoint)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Persistent state information for a connection session.
void write(std::string const &s)
Send a copy of data asynchronously.
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
TestSink(beast::unit_test::suite &suite)
CaptureLogs(std::string &result)
const char * getEnvLocalhostAddr()
beast::unit_test::suite & suite_
bool is_keep_alive(boost::beast::http::message< isRequest, Body, Fields > const &m)
Log manager for CaptureSinks.
bool expect_read(SyncReadStream &s, std::string const &match)
boost::optional< boost::asio::io_service::work > work_
bool connect(Socket &s, typename Socket::endpoint_type const &ep)
virtual http_request_type & request()=0
Returns the current HTTP request.
void test_keepalive(boost::asio::ip::tcp::endpoint const &ep)
bool write(SyncWriteStream &s, std::string const &text)
A generic endpoint for log messages.
virtual void complete()=0
Indicate that the response is complete.
boost::asio::io_service io_service_
sink for writing all log messages to a stringstream
void onClose(Session &session, boost::system::error_code const &)
CaptureSink(beast::severities::Severity threshold, std::stringstream &strm)
beast::severities::Severity threshold() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Severity
Severity level / threshold of a Journal message.
virtual void close(bool graceful)=0
Close the session.
Used to indicate the result of a server connection handoff.
void onWSMessage(std::shared_ptr< WSSession > session, std::vector< boost::asio::const_buffer > const &)
std::stringstream & strm_
Handoff onHandoff(Session &session, std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint remote_address)
void test_request(boost::asio::ip::tcp::endpoint const &ep)
boost::beast::ssl_stream< socket_type > stream_type
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
void onStopped(Server &server)
A transaction testing environment.
static std::string nodeDatabase()