xrpld
Loading...
Searching...
No Matches
ServerStatus_test.cpp
1#include <test/jtx/Env.h>
2#include <test/jtx/JSONRPCClient.h>
3#include <test/jtx/WSClient.h>
4#include <test/jtx/envconfig.h>
5
6#include <xrpld/app/ledger/LedgerMaster.h>
7
8#include <xrpl/basics/base64.h>
9#include <xrpl/beast/test/yield_to.h>
10#include <xrpl/beast/unit_test/suite.h>
11#include <xrpl/config/Constants.h>
12#include <xrpl/json/json_reader.h>
13#include <xrpl/json/json_value.h>
14#include <xrpl/json/to_string.h>
15#include <xrpl/protocol/ErrorCodes.h>
16#include <xrpl/protocol/jss.h>
17#include <xrpl/server/LoadFeeTrack.h>
18#include <xrpl/server/NetworkOPs.h>
19
20#include <boost/algorithm/string/predicate.hpp>
21#include <boost/asio/buffer.hpp>
22#include <boost/asio/connect.hpp>
23#include <boost/asio/io_context.hpp>
24#include <boost/asio/ip/tcp.hpp>
25#include <boost/asio/spawn.hpp>
26#include <boost/asio/ssl/context.hpp>
27#include <boost/asio/ssl/stream.hpp>
28#include <boost/asio/ssl/stream_base.hpp>
29#include <boost/asio/ssl/verify_mode.hpp>
30#include <boost/asio/write.hpp>
31#include <boost/beast/core/make_printable.hpp>
32#include <boost/beast/core/multi_buffer.hpp>
33#include <boost/beast/http/field.hpp>
34#include <boost/beast/http/status.hpp>
35#include <boost/beast/http/verb.hpp>
36#include <boost/beast/websocket/stream.hpp>
37#include <boost/lexical_cast.hpp>
38
39#include <array>
40#include <cstdint>
41#include <memory>
42#include <random>
43#include <regex>
44#include <string>
45#include <utility>
46#include <vector>
47
48namespace xrpl::test {
49
51{
52 class MyFields : public boost::beast::http::fields
53 {
54 };
55
56 static auto
57 makeConfig(std::string const& proto, bool admin = true, bool credentials = false)
58 {
59 auto const sectionName = proto.starts_with('h') ? Sections::kPortRpc : Sections::kPortWs;
60 auto p = jtx::envconfig();
61
62 p->overwrite(sectionName, Keys::kProtocol, proto);
63 if (!admin)
64 p->overwrite(sectionName, Keys::kAdmin, "");
65
66 if (credentials)
67 {
68 (*p)[sectionName].set(Keys::kAdminPassword, "p");
69 (*p)[sectionName].set(Keys::kAdminUser, "u");
70 }
71
72 p->overwrite(
75 proto.starts_with('h') ? "ws" : "http");
76
77 if (proto == "https")
78 {
79 // this port is here to allow the env to create its internal client,
80 // which requires an http endpoint to talk to. In the connection
81 // failure test, this endpoint should never be used
82 (*p)[Sections::kServer].append("port_alt");
83 (*p)["port_alt"].set(Keys::kIp, getEnvLocalhostAddr());
84 (*p)["port_alt"].set(Keys::kPort, "7099");
85 (*p)["port_alt"].set(Keys::kProtocol, "http");
86 (*p)["port_alt"].set(Keys::kAdmin, getEnvLocalhostAddr());
87 }
88
89 return p;
90 }
91
92 static auto
93 makeWSUpgrade(std::string const& host, uint16_t port)
94 {
95 using namespace boost::asio;
96 using namespace boost::beast::http;
97 request<string_body> req;
98
99 req.target("/");
100 req.version(11);
101 req.insert("Host", host + ":" + std::to_string(port));
102 req.insert("User-Agent", "test");
103 req.method(boost::beast::http::verb::get);
104 req.insert("Upgrade", "websocket");
105 {
106 // not secure, but OK for a testing
108 std::mt19937 e{rd()};
111 for (auto& v : key)
112 v = d(e);
113 req.insert("Sec-WebSocket-Key", base64Encode(key.data(), key.size()));
114 };
115 req.insert("Sec-WebSocket-Version", "13");
116 req.insert(boost::beast::http::field::connection, "upgrade");
117 return req;
118 }
119
120 static auto
122 std::string const& host,
123 uint16_t port,
124 std::string const& body,
125 MyFields const& fields)
126 {
127 using namespace boost::asio;
128 using namespace boost::beast::http;
129 request<string_body> req;
130
131 req.target("/");
132 req.version(11);
133 for (auto const& f : fields)
134 req.insert(f.name(), f.value());
135 req.insert("Host", host + ":" + std::to_string(port));
136 req.insert("User-Agent", "test");
137 if (body.empty())
138 {
139 req.method(boost::beast::http::verb::get);
140 }
141 else
142 {
143 req.method(boost::beast::http::verb::post);
144 req.insert("Content-Type", "application/json; charset=UTF-8");
145 req.body() = body;
146 }
147 req.prepare_payload();
148
149 return req;
150 }
151
152 void
154 boost::asio::yield_context& yield,
155 boost::beast::http::request<boost::beast::http::string_body> const& req,
156 std::string const& host,
157 uint16_t port,
158 bool secure,
159 boost::beast::http::response<boost::beast::http::string_body>& resp,
160 boost::system::error_code& ec)
161 {
162 using namespace boost::asio;
163 using namespace boost::beast::http;
164 io_context& ios = getIoContext();
165 ip::tcp::resolver r{ios};
166 boost::beast::multi_buffer sb;
167
168 auto const it = r.async_resolve(host, std::to_string(port), yield[ec]);
169 if (ec)
170 return;
171
172 resp.body().clear();
173 if (secure)
174 {
175 ssl::context ctx{ssl::context::sslv23};
176 ctx.set_verify_mode(ssl::verify_none);
177 ssl::stream<ip::tcp::socket> ss{ios, ctx};
178 async_connect(ss.next_layer(), it, yield[ec]);
179 if (ec)
180 return;
181 ss.async_handshake(ssl::stream_base::client, yield[ec]);
182 if (ec)
183 return;
184 boost::beast::http::async_write(ss, req, yield[ec]);
185 if (ec)
186 return;
187 async_read(ss, sb, resp, yield[ec]);
188 if (ec)
189 return;
190 }
191 else
192 {
193 ip::tcp::socket sock{ios};
194 async_connect(sock, it, yield[ec]);
195 if (ec)
196 return;
197 boost::beast::http::async_write(sock, req, yield[ec]);
198 if (ec)
199 return;
200 async_read(sock, sb, resp, yield[ec]);
201 if (ec)
202 return;
203 }
204 }
205
206 void
208 test::jtx::Env& env,
209 boost::asio::yield_context& yield,
210 bool secure,
211 boost::beast::http::response<boost::beast::http::string_body>& resp,
212 boost::system::error_code& ec)
213 {
214 auto const port = env.app().config()[Sections::kPortWs].get<std::uint16_t>(Keys::kPort);
215 auto ip = env.app().config()[Sections::kPortWs].get<std::string>(Keys::kIp);
216 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
217 doRequest(yield, makeWSUpgrade(*ip, *port), *ip, *port, secure, resp, ec);
218 }
219
220 void
222 test::jtx::Env& env,
223 boost::asio::yield_context& yield,
224 bool secure,
225 boost::beast::http::response<boost::beast::http::string_body>& resp,
226 boost::system::error_code& ec,
227 std::string const& body = "",
228 MyFields const& fields = {})
229 {
230 auto const port = env.app().config()[Sections::kPortRpc].get<std::uint16_t>(Keys::kPort);
231 auto const ip = env.app().config()[Sections::kPortRpc].get<std::string>(Keys::kIp);
232 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
233 doRequest(yield, makeHTTPRequest(*ip, *port, body, fields), *ip, *port, secure, resp, ec);
234 }
235
236 static auto
238 jtx::Env& env,
239 std::string const& proto,
240 std::string const& user,
241 std::string const& password,
242 bool subobject = false)
243 {
244 json::Value jrr;
245
247 if (!user.empty())
248 {
249 jp["admin_user"] = user;
250 if (subobject)
251 {
252 // special case of bad password..passed as object
254 jpi["admin_password"] = password;
255 jp["admin_password"] = jpi;
256 }
257 else
258 {
259 jp["admin_password"] = password;
260 }
261 }
262
263 if (proto.starts_with('h'))
264 {
265 auto jrc = makeJSONRPCClient(env.app().config());
266 jrr = jrc->invoke("ledger_accept", jp);
267 }
268 else
269 {
270 auto wsc = makeWSClient(env.app().config(), proto == "ws2");
271 jrr = wsc->invoke("ledger_accept", jp);
272 }
273
274 return jrr;
275 }
276
277 // ------------
278 // Test Cases
279 // ------------
280
281 void
282 testAdminRequest(std::string const& proto, bool admin, bool credentials)
283 {
284 testcase << "Admin request over " << proto << ", config "
285 << (admin ? "enabled" : "disabled") << ", credentials "
286 << (credentials ? "" : "not ") << "set";
287 using namespace jtx;
288 Env env{*this, makeConfig(proto, admin, credentials)};
289
290 json::Value jrr;
291 auto const protoWs = proto.starts_with('w');
292
293 // the set of checks we do are different depending
294 // on how the admin config options are set
295
296 if (admin && credentials)
297 {
298 auto const user = env.app()
301
302 auto const password = env.app()
305
306 // 1 - FAILS with wrong pass
307 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
308 jrr = makeAdminRequest(env, proto, *user, *password + "_")[jss::result];
309 if (protoWs)
310 {
311 BEAST_EXPECT(jrr[jss::error] == "forbidden");
312 BEAST_EXPECT(jrr[jss::error_code] == RpcForbidden);
313 BEAST_EXPECT(jrr[jss::error_message] == "Bad credentials.");
314 }
315 else
316 {
317 BEAST_EXPECT(jrr.isNull());
318 }
319
320 // 2 - FAILS with password in an object
321 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
322 jrr = makeAdminRequest(env, proto, *user, *password, true)[jss::result];
323 if (protoWs)
324 {
325 BEAST_EXPECT(jrr[jss::error] == "forbidden");
326 BEAST_EXPECT(jrr[jss::error_code] == RpcForbidden);
327 BEAST_EXPECT(jrr[jss::error_message] == "Bad credentials.");
328 }
329 else
330 {
331 BEAST_EXPECT(jrr.isNull());
332 }
333
334 // 3 - FAILS with wrong user
335 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
336 jrr = makeAdminRequest(env, proto, *user + "_", *password)[jss::result];
337 if (protoWs)
338 {
339 BEAST_EXPECT(jrr[jss::error] == "forbidden");
340 BEAST_EXPECT(jrr[jss::error_code] == RpcForbidden);
341 BEAST_EXPECT(jrr[jss::error_message] == "Bad credentials.");
342 }
343 else
344 {
345 BEAST_EXPECT(jrr.isNull());
346 }
347
348 // 4 - FAILS no credentials
349 jrr = makeAdminRequest(env, proto, "", "")[jss::result];
350 if (protoWs)
351 {
352 BEAST_EXPECT(jrr[jss::error] == "forbidden");
353 BEAST_EXPECT(jrr[jss::error_code] == RpcForbidden);
354 BEAST_EXPECT(jrr[jss::error_message] == "Bad credentials.");
355 }
356 else
357 {
358 BEAST_EXPECT(jrr.isNull());
359 }
360
361 // 5 - SUCCEEDS with proper credentials
362 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
363 jrr = makeAdminRequest(env, proto, *user, *password)[jss::result];
364 BEAST_EXPECT(jrr["status"] == "success");
365 }
366 else if (admin)
367 {
368 // 1 - SUCCEEDS with proper credentials
369 jrr = makeAdminRequest(env, proto, "u", "p")[jss::result];
370 BEAST_EXPECT(jrr["status"] == "success");
371
372 // 2 - SUCCEEDS without proper credentials
373 jrr = makeAdminRequest(env, proto, "", "")[jss::result];
374 BEAST_EXPECT(jrr["status"] == "success");
375 }
376 else
377 {
378 // 1 - FAILS - admin disabled
379 jrr = makeAdminRequest(env, proto, "", "")[jss::result];
380 if (protoWs)
381 {
382 BEAST_EXPECT(jrr[jss::error] == "forbidden");
383 BEAST_EXPECT(jrr[jss::error_code] == RpcForbidden);
384 BEAST_EXPECT(jrr[jss::error_message] == "Bad credentials.");
385 }
386 else
387 {
388 BEAST_EXPECT(jrr.isNull());
389 }
390 }
391 }
392
393 void
394 testWSClientToHttpServer(boost::asio::yield_context& yield)
395 {
396 testcase("WS client to http server fails");
397 using namespace jtx;
398 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
399 cfg->section(Sections::kPortWs).set(Keys::kProtocol, "http,https");
400 return cfg;
401 })};
402
403 // non-secure request
404 {
405 boost::system::error_code ec;
406 boost::beast::http::response<boost::beast::http::string_body> resp;
407 doWSRequest(env, yield, false, resp, ec);
408 if (!BEAST_EXPECTS(!ec, ec.message()))
409 return;
410 BEAST_EXPECT(resp.result() == boost::beast::http::status::unauthorized);
411 }
412
413 // secure request
414 {
415 boost::system::error_code ec;
416 boost::beast::http::response<boost::beast::http::string_body> resp;
417 doWSRequest(env, yield, true, resp, ec);
418 if (!BEAST_EXPECTS(!ec, ec.message()))
419 return;
420 BEAST_EXPECT(resp.result() == boost::beast::http::status::unauthorized);
421 }
422 }
423
424 void
425 testStatusRequest(boost::asio::yield_context& yield)
426 {
427 testcase("Status request");
428 using namespace jtx;
429 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
430 cfg->section(Sections::kPortRpc).set(Keys::kProtocol, "ws2,wss2");
431 cfg->section(Sections::kPortWs).set(Keys::kProtocol, "http");
432 return cfg;
433 })};
434
435 // non-secure request
436 {
437 boost::system::error_code ec;
438 boost::beast::http::response<boost::beast::http::string_body> resp;
439 doHTTPRequest(env, yield, false, resp, ec);
440 if (!BEAST_EXPECTS(!ec, ec.message()))
441 return;
442 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
443 }
444
445 // secure request
446 {
447 boost::system::error_code ec;
448 boost::beast::http::response<boost::beast::http::string_body> resp;
449 doHTTPRequest(env, yield, true, resp, ec);
450 if (!BEAST_EXPECTS(!ec, ec.message()))
451 return;
452 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
453 }
454 }
455
456 void
457 testTruncatedWSUpgrade(boost::asio::yield_context& yield)
458 {
459 testcase("Partial WS upgrade request");
460 using namespace jtx;
461 using namespace boost::asio;
462 using namespace boost::beast::http;
463 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
464 cfg->section(Sections::kPortWs).set(Keys::kProtocol, "ws2");
465 return cfg;
466 })};
467
468 auto const port = env.app().config()[Sections::kPortWs].get<std::uint16_t>(Keys::kPort);
469 auto const ip = env.app().config()[Sections::kPortWs].get<std::string>(Keys::kIp);
470
471 boost::system::error_code ec;
472 response<string_body> resp;
473 auto const req = makeWSUpgrade(*ip, *port); // NOLINT(bugprone-unchecked-optional-access)
474
475 // truncate the request message to near the value of the version header
476 auto reqString = boost::lexical_cast<std::string>(req);
477 reqString.erase(reqString.find_last_of("13"), std::string::npos);
478
479 io_context& ios = getIoContext();
480 ip::tcp::resolver r{ios};
481 boost::beast::multi_buffer sb;
482
483 auto const it = r.async_resolve(
484 *ip, std::to_string(*port), yield[ec]); // NOLINT(bugprone-unchecked-optional-access)
485 if (!BEAST_EXPECTS(!ec, ec.message()))
486 return;
487
488 ip::tcp::socket sock{ios};
489 async_connect(sock, it, yield[ec]);
490 if (!BEAST_EXPECTS(!ec, ec.message()))
491 return;
492 async_write(sock, boost::asio::buffer(reqString), yield[ec]);
493 if (!BEAST_EXPECTS(!ec, ec.message()))
494 return;
495 // since we've sent an incomplete request, the server will
496 // keep trying to read until it gives up (by timeout)
497 async_read(sock, sb, resp, yield[ec]);
498 BEAST_EXPECT(ec);
499 }
500
501 void
503 std::string const& clientProtocol,
504 std::string const& serverProtocol,
505 boost::asio::yield_context& yield)
506 {
507 // The essence of this test is to have a client and server configured
508 // out-of-phase with respect to ssl (secure client and insecure server
509 // or vice-versa)
510 testcase << "Connect fails: " << clientProtocol << " client to " << serverProtocol
511 << " server";
512 using namespace jtx;
513 Env env{*this, makeConfig(serverProtocol)};
514
515 boost::beast::http::response<boost::beast::http::string_body> resp;
516 boost::system::error_code ec;
517 if (clientProtocol.starts_with('h'))
518 {
519 doHTTPRequest(env, yield, clientProtocol == "https", resp, ec);
520 BEAST_EXPECT(ec);
521 }
522 else
523 {
524 doWSRequest(env, yield, clientProtocol == "wss" || clientProtocol == "wss2", resp, ec);
525 BEAST_EXPECT(ec);
526 }
527 }
528
529 void
530 testAuth(bool secure, boost::asio::yield_context& yield)
531 {
532 testcase << "Server with authorization, " << (secure ? "secure" : "non-secure");
533
534 using namespace test::jtx;
535 Env env{*this, envconfig([secure](std::unique_ptr<Config> cfg) {
536 (*cfg)[Sections::kPortRpc].set(Keys::kUser, "me");
537 (*cfg)[Sections::kPortRpc].set(Keys::kPassword, "secret");
538 (*cfg)[Sections::kPortRpc].set(Keys::kProtocol, secure ? "https" : "http");
539 if (secure)
540 (*cfg)[Sections::kPortWs].set(Keys::kProtocol, "http,ws");
541 return cfg;
542 })};
543
544 json::Value jr;
545 jr[jss::method] = "server_info";
546 boost::beast::http::response<boost::beast::http::string_body> resp;
547 boost::system::error_code ec;
548 doHTTPRequest(env, yield, secure, resp, ec, to_string(jr));
549 BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
550
551 MyFields auth;
552 auth.insert("Authorization", "");
553 doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth);
554 BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
555
556 auth.set("Authorization", "Basic NOT-VALID");
557 doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth);
558 BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
559
560 auth.set("Authorization", "Basic " + base64Encode("me:badpass"));
561 doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth);
562 BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
563
564 auto const section = env.app().config().section(Sections::kPortRpc);
565 // NOLINTBEGIN(bugprone-unchecked-optional-access)
566 auto const user = section.get<std::string>(Keys::kUser).value();
567 auto const pass = section.get<std::string>(Keys::kPassword).value();
568 // NOLINTEND(bugprone-unchecked-optional-access)
569
570 // try with the correct user/pass, but not encoded
571 auth.set("Authorization", "Basic " + user + ":" + pass);
572 doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth);
573 BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
574
575 // finally if we use the correct user/pass encoded, we should get a 200
576 auth.set("Authorization", "Basic " + base64Encode(user + ":" + pass));
577 doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth);
578 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
579 BEAST_EXPECT(!resp.body().empty());
580 }
581
582 void
583 testLimit(boost::asio::yield_context& yield, int limit)
584 {
585 testcase << "Server with connection limit of " << limit;
586
587 using namespace test::jtx;
588 using namespace boost::asio;
589 using namespace boost::beast::http;
590 // Run the server with a single io thread so disconnectClient() below
591 // can deterministically drain the server's io_context (see its docs).
594 return cfg;
595 }))};
596
597 auto const section = env.app().config().section(Sections::kPortRpc);
598 // NOLINTBEGIN(bugprone-unchecked-optional-access)
599 auto const port = section.get<std::uint16_t>(Keys::kPort).value();
600 auto const ip = section.get<std::string>(Keys::kIp).value();
601 // NOLINTEND(bugprone-unchecked-optional-access)
602
603 boost::system::error_code ec;
604 io_context& ios = getIoContext();
605 ip::tcp::resolver r{ios};
606
607 json::Value jr;
608 jr[jss::method] = "server_info";
609
610 auto const it = r.async_resolve(ip, std::to_string(port), yield[ec]);
611 BEAST_EXPECT(!ec);
612
614
615 // Env owns a persistent JSON-RPC HTTP client connection to port_rpc as
616 // part of startup, which counts against this port's connection limit.
617 // This test wants a known starting occupancy of zero, so for nonzero
618 // limits it deterministically drops that hidden client and waits for
619 // the server to register the disconnect before opening its own clients.
620 //
621 // Starting from zero is important because the port limit rejects once
622 // the incremented connection count reaches the configured limit. With a
623 // zero baseline and N = limit + 1 test-owned clients, exactly the last
624 // two requests should be rejected.
625 if (limit != 0)
626 BEAST_EXPECT(env.disconnectClient());
627
628 // For nonzero limits, go one past the limit. The port rejects at the
629 // limit, not only above it, so this yields the last two clients
630 // failing. For zero limit, pick an arbitrary nonzero number of clients
631 // and expect them all to succeed.
632
633 int const testTo = (limit == 0) ? 50 : limit + 1;
634 while (static_cast<int>(clients.size()) < testTo)
635 {
636 clients.emplace_back(ip::tcp::socket{ios}, boost::beast::multi_buffer{});
637 async_connect(clients.back().first, it, yield[ec]);
638 BEAST_EXPECT(!ec);
639 auto const req = makeHTTPRequest(ip, port, to_string(jr), {});
640 async_write(clients.back().first, req, yield[ec]);
641 BEAST_EXPECT(!ec);
642 }
643
644 int successfulReads = 0;
645 for (auto& [soc, buf] : clients)
646 {
647 boost::beast::http::response<boost::beast::http::string_body> resp;
648 async_read(soc, buf, resp, yield[ec]);
649 if (!ec)
650 ++successfulReads;
651 }
652
653 // This test cares about the exact number of accepted requests, not which
654 // specific client observed the rejection. With a zero baseline (the
655 // hidden Env client dropped above), the server accepts until the
656 // connection count reaches the limit: all clients for limit 0, else
657 // limit - 1 of the limit + 1 clients (the last two are rejected).
658 int const expectedReads = (limit == 0) ? static_cast<int>(clients.size()) : limit - 1;
659 BEAST_EXPECT(successfulReads == expectedReads);
660 }
661
662 void
663 testWSHandoff(boost::asio::yield_context& yield)
664 {
665 testcase("Connection with WS handoff");
666
667 using namespace test::jtx;
668 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
669 (*cfg)[Sections::kPortWs].set(Keys::kProtocol, "wss");
670 return cfg;
671 })};
672
673 auto const section = env.app().config().section(Sections::kPortWs);
674 // NOLINTBEGIN(bugprone-unchecked-optional-access)
675 auto const port = section.get<std::uint16_t>(Keys::kPort).value();
676 auto const ip = section.get<std::string>(Keys::kIp).value();
677 // NOLINTEND(bugprone-unchecked-optional-access)
678 boost::beast::http::response<boost::beast::http::string_body> resp;
679 boost::system::error_code ec;
680 doRequest(yield, makeWSUpgrade(ip, port), ip, port, true, resp, ec);
681 BEAST_EXPECT(resp.result() == boost::beast::http::status::switching_protocols);
682 BEAST_EXPECT(resp.contains("Upgrade") && resp["Upgrade"] == "websocket");
683 BEAST_EXPECT(resp.contains("Connection") && boost::iequals(resp["Connection"], "upgrade"));
684 }
685
686 void
687 testNoRPC(boost::asio::yield_context& yield)
688 {
689 testcase("Connection to port with no RPC enabled");
690
691 using namespace test::jtx;
692 Env env{*this};
693
694 auto const section = env.app().config().section(Sections::kPortWs);
695 // NOLINTBEGIN(bugprone-unchecked-optional-access)
696 auto const port = section.get<std::uint16_t>(Keys::kPort).value();
697 auto const ip = section.get<std::string>(Keys::kIp).value();
698 // NOLINTEND(bugprone-unchecked-optional-access)
699 boost::beast::http::response<boost::beast::http::string_body> resp;
700 boost::system::error_code ec;
701 // body content is required here to avoid being
702 // detected as a status request
703 doRequest(yield, makeHTTPRequest(ip, port, "foo", {}), ip, port, false, resp, ec);
704 BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
705 BEAST_EXPECT(resp.body() == "Forbidden\r\n");
706 }
707
708 void
709 testWSRequests(boost::asio::yield_context& yield)
710 {
711 testcase("WS client sends assorted input");
712
713 using namespace test::jtx;
714 using namespace boost::asio;
715 using namespace boost::beast::http;
716 Env env{*this};
717
718 auto const section = env.app().config().section(Sections::kPortWs);
719 // NOLINTBEGIN(bugprone-unchecked-optional-access)
720 auto const port = section.get<std::uint16_t>(Keys::kPort).value();
721 auto const ip = section.get<std::string>(Keys::kIp).value();
722 // NOLINTEND(bugprone-unchecked-optional-access)
723 boost::system::error_code ec;
724
725 io_context& ios = getIoContext();
726 ip::tcp::resolver r{ios};
727
728 auto const it = r.async_resolve(ip, std::to_string(port), yield[ec]);
729 if (!BEAST_EXPECT(!ec))
730 return;
731
732 ip::tcp::socket sock{ios};
733 async_connect(sock, it, yield[ec]);
734 if (!BEAST_EXPECT(!ec))
735 return;
736
737 boost::beast::websocket::stream<boost::asio::ip::tcp::socket&> ws{sock};
738 ws.handshake(ip + ":" + std::to_string(port), "/");
739
740 // helper lambda, used below
741 auto const sendAndParse = [&](std::string const& req) -> json::Value {
742 ws.async_write_some(true, buffer(req), yield[ec]);
743 if (!BEAST_EXPECT(!ec))
745
746 boost::beast::multi_buffer sb;
747 ws.async_read(sb, yield[ec]);
748 if (!BEAST_EXPECT(!ec))
750
751 json::Value resp;
752 json::Reader jr;
753 if (!BEAST_EXPECT(jr.parse(
754 boost::lexical_cast<std::string>(boost::beast::make_printable(sb.data())),
755 resp)))
757 sb.consume(sb.size());
758 return resp;
759 };
760
761 { // send invalid json
762 auto resp = sendAndParse("NOT JSON");
763 BEAST_EXPECT(resp[jss::error] == "jsonInvalid");
764 BEAST_EXPECT(!resp.isMember(jss::error_code));
765 BEAST_EXPECT(resp[jss::error_message].isNull());
766 BEAST_EXPECT(!resp.isMember(jss::status));
767 }
768
769 { // send incorrect json (method and command fields differ)
770 json::Value jv;
771 jv[jss::command] = "foo";
772 jv[jss::method] = "bar";
773 auto resp = sendAndParse(to_string(jv));
774 BEAST_EXPECT(resp[jss::status] == "error");
775 BEAST_EXPECT(resp[jss::error] == "missingCommand");
776 BEAST_EXPECT(!resp.isMember(jss::error_code));
777 BEAST_EXPECT(resp[jss::error_message].isNull());
778 }
779
780 { // send a ping (not an error)
781 json::Value jv;
782 jv[jss::command] = "ping";
783 auto resp = sendAndParse(to_string(jv));
784 BEAST_EXPECT(resp.isMember(jss::status) && resp[jss::status] == "success");
785 BEAST_EXPECT(
786 resp.isMember(jss::result) && resp[jss::result].isMember(jss::role) &&
787 resp[jss::result][jss::role] == "admin");
788 }
789 }
790
791 void
792 testAmendmentWarning(boost::asio::yield_context& yield)
793 {
794 testcase("Status request over WS and RPC with/without Amendment Warning");
795 using namespace jtx;
796 using namespace boost::asio;
797 using namespace boost::beast::http;
798 Env env{
799 *this,
800 validator(
802 cfg->section(Sections::kPortRpc).set(Keys::kProtocol, "http");
803 return cfg;
804 }),
805 "")};
806
807 env.close();
808
809 // advance the ledger so that server status
810 // sees a published ledger -- without this, we get a status
811 // failure message about no published ledgers
813
814 // make an RPC server info request and look for
815 // amendment warning status
816 auto si = env.rpc("server_info")[jss::result];
817 BEAST_EXPECT(si.isMember(jss::info));
818 BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
819 BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
820 BEAST_EXPECT(!si.isMember(jss::warnings));
821
822 // make an RPC server state request and look for
823 // amendment warning status
824 si = env.rpc("server_state")[jss::result];
825 BEAST_EXPECT(si.isMember(jss::state));
826 BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
827 BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
828 BEAST_EXPECT(!si[jss::state].isMember(jss::warnings));
829
830 auto const portWs = env.app().config()[Sections::kPortWs].get<std::uint16_t>(Keys::kPort);
831 auto const ipWs = env.app().config()[Sections::kPortWs].get<std::string>(Keys::kIp);
832
833 boost::system::error_code ec;
834 response<string_body> resp;
835
836 doRequest(
837 yield,
838 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
839 makeHTTPRequest(*ipWs, *portWs, "", {}),
840 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
841 *ipWs,
842 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
843 *portWs,
844 false,
845 resp,
846 ec);
847
848 if (!BEAST_EXPECTS(!ec, ec.message()))
849 return;
850 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
851 BEAST_EXPECT(resp.body().contains("connectivity is working."));
852
853 // mark the Network as having an Amendment Warning, but won't fail
854 env.app().getOPs().setAmendmentWarned();
855 env.app().getOPs().beginConsensus(env.closed()->header().hash, {});
856
857 // consensus doesn't change
858 BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
859
860 // RPC request server_info again, now unsupported majority should be
861 // returned
862 si = env.rpc("server_info")[jss::result];
863 BEAST_EXPECT(si.isMember(jss::info));
864 BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
865 BEAST_EXPECT(
866 si[jss::info].isMember(jss::warnings) && si[jss::info][jss::warnings].isArray() &&
867 si[jss::info][jss::warnings].size() == 1 &&
868 si[jss::info][jss::warnings][0u][jss::id].asInt() == WarnRpcUnsupportedMajority);
869
870 // RPC request server_state again, now unsupported majority should be
871 // returned
872 si = env.rpc("server_state")[jss::result];
873 BEAST_EXPECT(si.isMember(jss::state));
874 BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
875 BEAST_EXPECT(
876 si[jss::state].isMember(jss::warnings) && si[jss::state][jss::warnings].isArray() &&
877 si[jss::state][jss::warnings].size() == 1 &&
878 si[jss::state][jss::warnings][0u][jss::id].asInt() == WarnRpcUnsupportedMajority);
879
880 // but status does not indicate a problem
881 doRequest(
882 yield,
883 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
884 makeHTTPRequest(*ipWs, *portWs, "", {}),
885 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
886 *ipWs,
887 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
888 *portWs,
889 false,
890 resp,
891 ec);
892
893 if (!BEAST_EXPECTS(!ec, ec.message()))
894 return;
895 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
896 BEAST_EXPECT(resp.body().contains("connectivity is working."));
897
898 // with ELB_SUPPORT, status still does not indicate a problem
899 env.app().config().elbSupport = true;
900
901 doRequest(
902 yield,
903 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
904 makeHTTPRequest(*ipWs, *portWs, "", {}),
905 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
906 *ipWs,
907 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
908 *portWs,
909 false,
910 resp,
911 ec);
912
913 if (!BEAST_EXPECTS(!ec, ec.message()))
914 return;
915 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
916 BEAST_EXPECT(resp.body().contains("connectivity is working."));
917 }
918
919 void
920 testAmendmentBlock(boost::asio::yield_context& yield)
921 {
922 testcase("Status request over WS and RPC with/without Amendment Block");
923 using namespace jtx;
924 using namespace boost::asio;
925 using namespace boost::beast::http;
926 Env env{
927 *this,
928 validator(
930 cfg->section(Sections::kPortRpc).set(Keys::kProtocol, "http");
931 return cfg;
932 }),
933 "")};
934
935 env.close();
936
937 // advance the ledger so that server status
938 // sees a published ledger -- without this, we get a status
939 // failure message about no published ledgers
941
942 // make an RPC server info request and look for
943 // amendment_blocked status
944 auto si = env.rpc("server_info")[jss::result];
945 BEAST_EXPECT(si.isMember(jss::info));
946 BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
947 BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
948 BEAST_EXPECT(!si.isMember(jss::warnings));
949
950 // make an RPC server state request and look for
951 // amendment_blocked status
952 si = env.rpc("server_state")[jss::result];
953 BEAST_EXPECT(si.isMember(jss::state));
954 BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
955 BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
956 BEAST_EXPECT(!si[jss::state].isMember(jss::warnings));
957
958 auto const portWs = env.app().config()[Sections::kPortWs].get<std::uint16_t>(Keys::kPort);
959 auto const ipWs = env.app().config()[Sections::kPortWs].get<std::string>(Keys::kIp);
960
961 boost::system::error_code ec;
962 response<string_body> resp;
963
964 doRequest(
965 yield,
966 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
967 makeHTTPRequest(*ipWs, *portWs, "", {}),
968 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
969 *ipWs,
970 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
971 *portWs,
972 false,
973 resp,
974 ec);
975
976 if (!BEAST_EXPECTS(!ec, ec.message()))
977 return;
978 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
979 BEAST_EXPECT(resp.body().contains("connectivity is working."));
980
981 // mark the Network as Amendment Blocked, but still won't fail until
982 // ELB is enabled (next step)
984 env.app().getOPs().beginConsensus(env.closed()->header().hash, {});
985
986 // consensus now sees validation disabled
987 BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == false);
988
989 // RPC request server_info again, now AB should be returned
990 si = env.rpc("server_info")[jss::result];
991 BEAST_EXPECT(si.isMember(jss::info));
992 BEAST_EXPECT(
993 si[jss::info].isMember(jss::amendment_blocked) &&
994 si[jss::info][jss::amendment_blocked] == true);
995 BEAST_EXPECT(
996 si[jss::info].isMember(jss::warnings) && si[jss::info][jss::warnings].isArray() &&
997 si[jss::info][jss::warnings].size() == 1 &&
998 si[jss::info][jss::warnings][0u][jss::id].asInt() == WarnRpcAmendmentBlocked);
999
1000 // RPC request server_state again, now AB should be returned
1001 si = env.rpc("server_state")[jss::result];
1002 BEAST_EXPECT(
1003 si[jss::state].isMember(jss::amendment_blocked) &&
1004 si[jss::state][jss::amendment_blocked] == true);
1005 BEAST_EXPECT(
1006 si[jss::state].isMember(jss::warnings) && si[jss::state][jss::warnings].isArray() &&
1007 si[jss::state][jss::warnings].size() == 1 &&
1008 si[jss::state][jss::warnings][0u][jss::id].asInt() == WarnRpcAmendmentBlocked);
1009
1010 // but status does not indicate because it still relies on ELB
1011 // being enabled
1012 doRequest(
1013 yield,
1014 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1015 makeHTTPRequest(*ipWs, *portWs, "", {}),
1016 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1017 *ipWs,
1018 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1019 *portWs,
1020 false,
1021 resp,
1022 ec);
1023
1024 if (!BEAST_EXPECTS(!ec, ec.message()))
1025 return;
1026 BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
1027 BEAST_EXPECT(resp.body().contains("connectivity is working."));
1028
1029 env.app().config().elbSupport = true;
1030
1031 doRequest(
1032 yield,
1033 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1034 makeHTTPRequest(*ipWs, *portWs, "", {}),
1035 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1036 *ipWs,
1037 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1038 *portWs,
1039 false,
1040 resp,
1041 ec);
1042
1043 if (!BEAST_EXPECTS(!ec, ec.message()))
1044 return;
1045 BEAST_EXPECT(resp.result() == boost::beast::http::status::internal_server_error);
1046 BEAST_EXPECT(resp.body().contains("cannot accept clients:"));
1047 BEAST_EXPECT(resp.body().contains("Server version too old"));
1048 }
1049
1050 void
1051 testRPCRequests(boost::asio::yield_context& yield)
1052 {
1053 testcase("RPC client sends assorted input");
1054
1055 using namespace test::jtx;
1056 Env env{*this};
1057
1058 boost::system::error_code ec;
1059 {
1060 boost::beast::http::response<boost::beast::http::string_body> resp;
1061 doHTTPRequest(env, yield, false, resp, ec, "{}");
1062 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1063 BEAST_EXPECT(resp.body() == "Unable to parse request: \r\n");
1064 }
1065
1066 {
1067 boost::beast::http::response<boost::beast::http::string_body> resp;
1068 json::Value jv;
1069 jv["invalid"] = 1;
1070 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1071 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1072 BEAST_EXPECT(resp.body() == "Null method\r\n");
1073 }
1074
1075 {
1076 boost::beast::http::response<boost::beast::http::string_body> resp;
1078 jv.append("invalid");
1079 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1080 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1081 BEAST_EXPECT(resp.body() == "Unable to parse request: \r\n");
1082 }
1083
1084 {
1085 boost::beast::http::response<boost::beast::http::string_body> resp;
1087 json::Value j;
1088 j["invalid"] = 1;
1089 jv.append(j);
1090 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1091 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1092 BEAST_EXPECT(resp.body() == "Unable to parse request: \r\n");
1093 }
1094
1095 {
1096 boost::beast::http::response<boost::beast::http::string_body> resp;
1097 json::Value jv;
1098 jv[jss::method] = "batch";
1099 jv[jss::params] = 2;
1100 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1101 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1102 BEAST_EXPECT(resp.body() == "Malformed batch request\r\n");
1103 }
1104
1105 {
1106 boost::beast::http::response<boost::beast::http::string_body> resp;
1107 json::Value jv;
1108 jv[jss::method] = "batch";
1109 jv[jss::params] = json::ValueType::Object;
1110 jv[jss::params]["invalid"] = 3;
1111 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1112 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1113 BEAST_EXPECT(resp.body() == "Malformed batch request\r\n");
1114 }
1115
1116 json::Value jv;
1117 {
1118 boost::beast::http::response<boost::beast::http::string_body> resp;
1119 jv[jss::method] = json::ValueType::Null;
1120 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1121 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1122 BEAST_EXPECT(resp.body() == "Null method\r\n");
1123 }
1124
1125 {
1126 boost::beast::http::response<boost::beast::http::string_body> resp;
1127 jv[jss::method] = 1;
1128 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1129 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1130 BEAST_EXPECT(resp.body() == "method is not string\r\n");
1131 }
1132
1133 {
1134 boost::beast::http::response<boost::beast::http::string_body> resp;
1135 jv[jss::method] = "";
1136 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1137 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1138 BEAST_EXPECT(resp.body() == "method is empty\r\n");
1139 }
1140
1141 {
1142 boost::beast::http::response<boost::beast::http::string_body> resp;
1143 jv[jss::method] = "some_method";
1144 jv[jss::params] = "params";
1145 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1146 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1147 BEAST_EXPECT(resp.body() == "params unparsable\r\n");
1148 }
1149
1150 {
1151 boost::beast::http::response<boost::beast::http::string_body> resp;
1152 jv[jss::params] = json::ValueType::Array;
1153 jv[jss::params][0u] = "not an object";
1154 doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
1155 BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
1156 BEAST_EXPECT(resp.body() == "params unparsable\r\n");
1157 }
1158 }
1159
1160 void
1161 testStatusNotOkay(boost::asio::yield_context& yield)
1162 {
1163 testcase("Server status not okay");
1164
1165 using namespace test::jtx;
1166 Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
1167 cfg->elbSupport = true;
1168 return cfg;
1169 })};
1170
1171 // raise the fee so that the server is considered overloaded
1172 env.app().getFeeTrack().raiseLocalFee();
1173
1174 boost::beast::http::response<boost::beast::http::string_body> resp;
1175 boost::system::error_code ec;
1176 doHTTPRequest(env, yield, false, resp, ec);
1177 BEAST_EXPECT(resp.result() == boost::beast::http::status::internal_server_error);
1178 std::regex const body{"Server cannot accept clients"};
1179 BEAST_EXPECT(std::regex_search(resp.body(), body));
1180 }
1181
1182public:
1183 void
1184 run() override
1185 {
1186 for (auto it : {"http", "ws", "ws2"})
1187 {
1188 testAdminRequest(it, true, true);
1189 testAdminRequest(it, true, false);
1190 testAdminRequest(it, false, false);
1191 }
1192
1193 yieldTo([&](boost::asio::yield_context& yield) {
1195 testStatusRequest(yield);
1197
1198 // these are secure/insecure protocol pairs, i.e. for
1199 // each item, the second value is the secure or insecure equivalent
1200 testCantConnect("ws", "wss", yield);
1201 testCantConnect("ws2", "wss2", yield);
1202 testCantConnect("http", "https", yield);
1203 testCantConnect("wss", "ws", yield);
1204 testCantConnect("wss2", "ws2", yield);
1205 testCantConnect("https", "http", yield);
1206
1207 testAmendmentWarning(yield);
1208 testAmendmentBlock(yield);
1209 testAuth(false, yield);
1210 testAuth(true, yield);
1211 testLimit(yield, 5);
1212 testLimit(yield, 0);
1213 testWSHandoff(yield);
1214 testNoRPC(yield);
1215 testWSRequests(yield);
1216 testRPCRequests(yield);
1217 testStatusNotOkay(yield);
1218 });
1219 }
1220};
1221
1222BEAST_DEFINE_TESTSUITE(ServerStatus, server, xrpl);
1223
1224} // namespace xrpl::test
T back(T... args)
Mix-in to support tests using asio coroutines.
Definition yield_to.h:30
boost::asio::io_context & getIoContext()
Return the io_context associated with the object.
Definition yield_to.h:67
void yieldTo(F0 &&f0, FN &&... fn)
Run one or more functions, each in a coroutine.
Definition yield_to.h:107
A testsuite class.
Definition suite.h:52
void pass()
Record a successful test condition.
Definition suite.h:532
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Unserialize a JSON document into a Value.
Definition json_reader.h:20
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Represents a JSON value.
Definition json_value.h:121
bool isNull() const
isNull() tests to see if this field is null.
Value & append(Value const &value)
Append value to array at the end.
virtual Config & config()=0
Section & section(std::string const &name)
Returns the section with the given name.
void tryAdvance()
Signals that the ledger stream may be able to make progress.
virtual void setAmendmentBlocked()=0
virtual json::Value getConsensusInfo()=0
virtual bool beginConsensus(UInt256 const &netLCL, std::unique_ptr< std::stringstream > const &clog)=0
virtual void setAmendmentWarned()=0
std::optional< T > get(std::string const &name) const
virtual NetworkOPs & getOPs()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual LedgerMaster & getLedgerMaster()=0
void testWSClientToHttpServer(boost::asio::yield_context &yield)
void doWSRequest(test::jtx::Env &env, boost::asio::yield_context &yield, bool secure, boost::beast::http::response< boost::beast::http::string_body > &resp, boost::system::error_code &ec)
void doHTTPRequest(test::jtx::Env &env, boost::asio::yield_context &yield, bool secure, boost::beast::http::response< boost::beast::http::string_body > &resp, boost::system::error_code &ec, std::string const &body="", MyFields const &fields={})
void testAmendmentBlock(boost::asio::yield_context &yield)
static auto makeWSUpgrade(std::string const &host, uint16_t port)
void testNoRPC(boost::asio::yield_context &yield)
void testWSHandoff(boost::asio::yield_context &yield)
void testTruncatedWSUpgrade(boost::asio::yield_context &yield)
void testAdminRequest(std::string const &proto, bool admin, bool credentials)
void testRPCRequests(boost::asio::yield_context &yield)
void testStatusNotOkay(boost::asio::yield_context &yield)
static auto makeAdminRequest(jtx::Env &env, std::string const &proto, std::string const &user, std::string const &password, bool subobject=false)
void run() override
Runs the suite.
void testCantConnect(std::string const &clientProtocol, std::string const &serverProtocol, boost::asio::yield_context &yield)
void testAmendmentWarning(boost::asio::yield_context &yield)
void doRequest(boost::asio::yield_context &yield, boost::beast::http::request< boost::beast::http::string_body > const &req, std::string const &host, uint16_t port, bool secure, boost::beast::http::response< boost::beast::http::string_body > &resp, boost::system::error_code &ec)
void testAuth(bool secure, boost::asio::yield_context &yield)
void testLimit(boost::asio::yield_context &yield, int limit)
void testWSRequests(boost::asio::yield_context &yield)
static auto makeHTTPRequest(std::string const &host, uint16_t port, std::string const &body, MyFields const &fields)
static auto makeConfig(std::string const &proto, bool admin=true, bool credentials=false)
void testStatusRequest(boost::asio::yield_context &yield)
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:127
bool disconnectClient(std::chrono::steady_clock::duration timeout=std::chrono::seconds{1})
Disconnect the Env's built-in client and wait for the server to register the dropped connection.
Definition Env.h:514
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1058
T data(T... args)
T emplace_back(T... args)
T empty(T... args)
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
@ Null
'null' value
Definition json_value.h:26
std::unique_ptr< Config > singleThreadIo(std::unique_ptr< Config >)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
std::unique_ptr< AbstractClient > makeJSONRPCClient(Config const &cfg, unsigned rpcVersion)
Returns a client using JSON-RPC over HTTP/S.
char const * getEnvLocalhostAddr()
Definition envconfig.h:16
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpcVersion, std::unordered_map< std::string, std::string > const &headers)
Returns a client operating through WebSockets/S.
Definition WSClient.cpp:373
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ WarnRpcAmendmentBlocked
Definition ErrorCodes.h:159
@ WarnRpcUnsupportedMajority
Definition ErrorCodes.h:158
@ RpcForbidden
Definition ErrorCodes.h:31
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
std::string base64Encode(std::uint8_t const *data, std::size_t len)
T regex_search(T... args)
T size(T... args)
T starts_with(T... args)
static constexpr auto kProtocol
Definition Constants.h:151
static constexpr auto kLimit
Definition Constants.h:121
static constexpr auto kAdminPassword
Definition Constants.h:87
static constexpr auto kUser
Definition Constants.h:181
static constexpr auto kAdmin
Definition Constants.h:86
static constexpr auto kPort
Definition Constants.h:149
static constexpr auto kIp
Definition Constants.h:117
static constexpr auto kAdminUser
Definition Constants.h:88
static constexpr auto kPassword
Definition Constants.h:146
static constexpr auto kPortWs
Definition Constants.h:48
static constexpr auto kServer
Definition Constants.h:56
static constexpr auto kPortRpc
Definition Constants.h:47
T to_string(T... args)