mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-04 17:27:00 +00:00
chore: Set ColumnLimit to 120 in clang-format (#6288)
This change updates the ColumnLimit from 80 to 120, and applies clang-format to reformat the code.
This commit is contained in:
@@ -27,21 +27,16 @@
|
||||
namespace xrpl {
|
||||
namespace test {
|
||||
|
||||
class ServerStatus_test : public beast::unit_test::suite,
|
||||
public beast::test::enable_yield_to
|
||||
class ServerStatus_test : public beast::unit_test::suite, public beast::test::enable_yield_to
|
||||
{
|
||||
class myFields : public boost::beast::http::fields
|
||||
{
|
||||
};
|
||||
|
||||
auto
|
||||
makeConfig(
|
||||
std::string const& proto,
|
||||
bool admin = true,
|
||||
bool credentials = false)
|
||||
makeConfig(std::string const& proto, bool admin = true, bool credentials = false)
|
||||
{
|
||||
auto const section_name =
|
||||
boost::starts_with(proto, "h") ? "port_rpc" : "port_ws";
|
||||
auto const section_name = boost::starts_with(proto, "h") ? "port_rpc" : "port_ws";
|
||||
auto p = jtx::envconfig();
|
||||
|
||||
p->overwrite(section_name, "protocol", proto);
|
||||
@@ -95,8 +90,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
std::array<std::uint8_t, 16> key;
|
||||
for (auto& v : key)
|
||||
v = d(e);
|
||||
req.insert(
|
||||
"Sec-WebSocket-Key", base64_encode(key.data(), key.size()));
|
||||
req.insert("Sec-WebSocket-Key", base64_encode(key.data(), key.size()));
|
||||
};
|
||||
req.insert("Sec-WebSocket-Version", "13");
|
||||
req.insert(boost::beast::http::field::connection, "upgrade");
|
||||
@@ -104,11 +98,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
}
|
||||
|
||||
auto
|
||||
makeHTTPRequest(
|
||||
std::string const& host,
|
||||
uint16_t port,
|
||||
std::string const& body,
|
||||
myFields const& fields)
|
||||
makeHTTPRequest(std::string const& host, uint16_t port, std::string const& body, myFields const& fields)
|
||||
{
|
||||
using namespace boost::asio;
|
||||
using namespace boost::beast::http;
|
||||
@@ -199,11 +189,9 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
boost::beast::http::response<boost::beast::http::string_body>& resp,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
auto const port =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const port = env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto ip = env.app().config()["port_ws"].get<std::string>("ip");
|
||||
doRequest(
|
||||
yield, makeWSUpgrade(*ip, *port), *ip, *port, secure, resp, ec);
|
||||
doRequest(yield, makeWSUpgrade(*ip, *port), *ip, *port, secure, resp, ec);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -217,17 +205,9 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
std::string const& body = "",
|
||||
myFields const& fields = {})
|
||||
{
|
||||
auto const port =
|
||||
env.app().config()["port_rpc"].get<std::uint16_t>("port");
|
||||
auto const port = env.app().config()["port_rpc"].get<std::uint16_t>("port");
|
||||
auto const ip = env.app().config()["port_rpc"].get<std::string>("ip");
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip, *port, body, fields),
|
||||
*ip,
|
||||
*port,
|
||||
secure,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip, *port, body, fields), *ip, *port, secure, resp, ec);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -279,9 +259,8 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
void
|
||||
testAdminRequest(std::string const& proto, bool admin, bool credentials)
|
||||
{
|
||||
testcase << "Admin request over " << proto << ", config "
|
||||
<< (admin ? "enabled" : "disabled") << ", credentials "
|
||||
<< (credentials ? "" : "not ") << "set";
|
||||
testcase << "Admin request over " << proto << ", config " << (admin ? "enabled" : "disabled")
|
||||
<< ", credentials " << (credentials ? "" : "not ") << "set";
|
||||
using namespace jtx;
|
||||
Env env{*this, makeConfig(proto, admin, credentials)};
|
||||
|
||||
@@ -293,53 +272,34 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
|
||||
if (admin && credentials)
|
||||
{
|
||||
auto const user = env.app()
|
||||
.config()[proto_ws ? "port_ws" : "port_rpc"]
|
||||
.get<std::string>("admin_user");
|
||||
auto const user = env.app().config()[proto_ws ? "port_ws" : "port_rpc"].get<std::string>("admin_user");
|
||||
|
||||
auto const password =
|
||||
env.app()
|
||||
.config()[proto_ws ? "port_ws" : "port_rpc"]
|
||||
.get<std::string>("admin_password");
|
||||
env.app().config()[proto_ws ? "port_ws" : "port_rpc"].get<std::string>("admin_password");
|
||||
|
||||
// 1 - FAILS with wrong pass
|
||||
jrr = makeAdminRequest(
|
||||
env, proto, *user, *password + "_")[jss::result];
|
||||
jrr = makeAdminRequest(env, proto, *user, *password + "_")[jss::result];
|
||||
BEAST_EXPECT(jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error_message"] == proto_ws
|
||||
? "Bad credentials."
|
||||
: "You don't have permission for this command.");
|
||||
jrr["error_message"] == proto_ws ? "Bad credentials." : "You don't have permission for this command.");
|
||||
|
||||
// 2 - FAILS with password in an object
|
||||
jrr = makeAdminRequest(
|
||||
env, proto, *user, *password, true)[jss::result];
|
||||
jrr = makeAdminRequest(env, proto, *user, *password, true)[jss::result];
|
||||
BEAST_EXPECT(jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error_message"] == proto_ws
|
||||
? "Bad credentials."
|
||||
: "You don't have permission for this command.");
|
||||
jrr["error_message"] == proto_ws ? "Bad credentials." : "You don't have permission for this command.");
|
||||
|
||||
// 3 - FAILS with wrong user
|
||||
jrr = makeAdminRequest(
|
||||
env, proto, *user + "_", *password)[jss::result];
|
||||
jrr = makeAdminRequest(env, proto, *user + "_", *password)[jss::result];
|
||||
BEAST_EXPECT(jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error_message"] == proto_ws
|
||||
? "Bad credentials."
|
||||
: "You don't have permission for this command.");
|
||||
jrr["error_message"] == proto_ws ? "Bad credentials." : "You don't have permission for this command.");
|
||||
|
||||
// 4 - FAILS no credentials
|
||||
jrr = makeAdminRequest(env, proto, "", "")[jss::result];
|
||||
BEAST_EXPECT(jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error_message"] == proto_ws
|
||||
? "Bad credentials."
|
||||
: "You don't have permission for this command.");
|
||||
jrr["error_message"] == proto_ws ? "Bad credentials." : "You don't have permission for this command.");
|
||||
|
||||
// 5 - SUCCEEDS with proper credentials
|
||||
jrr = makeAdminRequest(env, proto, *user, *password)[jss::result];
|
||||
@@ -359,12 +319,9 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
{
|
||||
// 1 - FAILS - admin disabled
|
||||
jrr = makeAdminRequest(env, proto, "", "")[jss::result];
|
||||
BEAST_EXPECT(jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error"] == proto_ws ? "forbidden" : "noPermission");
|
||||
BEAST_EXPECT(
|
||||
jrr["error_message"] == proto_ws
|
||||
? "Bad credentials."
|
||||
: "You don't have permission for this command.");
|
||||
jrr["error_message"] == proto_ws ? "Bad credentials." : "You don't have permission for this command.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,8 +342,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
doWSRequest(env, yield, false, resp, ec);
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::unauthorized);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::unauthorized);
|
||||
}
|
||||
|
||||
// secure request
|
||||
@@ -396,8 +352,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
doWSRequest(env, yield, true, resp, ec);
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::unauthorized);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::unauthorized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,8 +400,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
return cfg;
|
||||
})};
|
||||
|
||||
auto const port =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const port = env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const ip = env.app().config()["port_ws"].get<std::string>("ip");
|
||||
|
||||
boost::system::error_code ec;
|
||||
@@ -487,8 +441,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
// The essence of this test is to have a client and server configured
|
||||
// out-of-phase with respect to ssl (secure client and insecure server
|
||||
// or vice-versa)
|
||||
testcase << "Connect fails: " << client_protocol << " client to "
|
||||
<< server_protocol << " server";
|
||||
testcase << "Connect fails: " << client_protocol << " client to " << server_protocol << " server";
|
||||
using namespace jtx;
|
||||
Env env{*this, makeConfig(server_protocol)};
|
||||
|
||||
@@ -501,12 +454,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
}
|
||||
else
|
||||
{
|
||||
doWSRequest(
|
||||
env,
|
||||
yield,
|
||||
client_protocol == "wss" || client_protocol == "wss2",
|
||||
resp,
|
||||
ec);
|
||||
doWSRequest(env, yield, client_protocol == "wss" || client_protocol == "wss2", resp, ec);
|
||||
BEAST_EXPECT(ec);
|
||||
}
|
||||
}
|
||||
@@ -514,15 +462,13 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
void
|
||||
testAuth(bool secure, boost::asio::yield_context& yield)
|
||||
{
|
||||
testcase << "Server with authorization, "
|
||||
<< (secure ? "secure" : "non-secure");
|
||||
testcase << "Server with authorization, " << (secure ? "secure" : "non-secure");
|
||||
|
||||
using namespace test::jtx;
|
||||
Env env{*this, envconfig([secure](std::unique_ptr<Config> cfg) {
|
||||
(*cfg)["port_rpc"].set("user", "me");
|
||||
(*cfg)["port_rpc"].set("password", "secret");
|
||||
(*cfg)["port_rpc"].set(
|
||||
"protocol", secure ? "https" : "http");
|
||||
(*cfg)["port_rpc"].set("protocol", secure ? "https" : "http");
|
||||
if (secure)
|
||||
(*cfg)["port_ws"].set("protocol", "http,ws");
|
||||
return cfg;
|
||||
@@ -548,16 +494,8 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
|
||||
|
||||
auto const user = env.app()
|
||||
.config()
|
||||
.section("port_rpc")
|
||||
.get<std::string>("user")
|
||||
.value();
|
||||
auto const pass = env.app()
|
||||
.config()
|
||||
.section("port_rpc")
|
||||
.get<std::string>("password")
|
||||
.value();
|
||||
auto const user = env.app().config().section("port_rpc").get<std::string>("user").value();
|
||||
auto const pass = env.app().config().section("port_rpc").get<std::string>("password").value();
|
||||
|
||||
// try with the correct user/pass, but not encoded
|
||||
auth.set("Authorization", "Basic " + user + ":" + pass);
|
||||
@@ -584,10 +522,8 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
return cfg;
|
||||
})};
|
||||
|
||||
auto const port =
|
||||
env.app().config()["port_rpc"].get<std::uint16_t>("port").value();
|
||||
auto const ip =
|
||||
env.app().config()["port_rpc"].get<std::string>("ip").value();
|
||||
auto const port = env.app().config()["port_rpc"].get<std::uint16_t>("port").value();
|
||||
auto const ip = env.app().config()["port_rpc"].get<std::string>("ip").value();
|
||||
|
||||
boost::system::error_code ec;
|
||||
io_context& ios = get_io_context();
|
||||
@@ -599,8 +535,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
auto it = r.async_resolve(ip, std::to_string(port), yield[ec]);
|
||||
BEAST_EXPECT(!ec);
|
||||
|
||||
std::vector<std::pair<ip::tcp::socket, boost::beast::multi_buffer>>
|
||||
clients;
|
||||
std::vector<std::pair<ip::tcp::socket, boost::beast::multi_buffer>> clients;
|
||||
int connectionCount{1}; // starts at 1 because the Env already has one
|
||||
// for JSONRPCCLient
|
||||
|
||||
@@ -612,8 +547,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
int testTo = (limit == 0) ? 50 : limit + 1;
|
||||
while (connectionCount < testTo)
|
||||
{
|
||||
clients.emplace_back(std::make_pair(
|
||||
ip::tcp::socket{ios}, boost::beast::multi_buffer{}));
|
||||
clients.emplace_back(std::make_pair(ip::tcp::socket{ios}, boost::beast::multi_buffer{}));
|
||||
async_connect(clients.back().first, it, yield[ec]);
|
||||
BEAST_EXPECT(!ec);
|
||||
auto req = makeHTTPRequest(ip, port, to_string(jr), {});
|
||||
@@ -630,8 +564,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
++readCount;
|
||||
// expect the reads to fail for the clients that connected at or
|
||||
// above the limit. If limit is 0, all reads should succeed
|
||||
BEAST_EXPECT(
|
||||
(limit == 0 || readCount < limit - 1) ? (!ec) : bool(ec));
|
||||
BEAST_EXPECT((limit == 0 || readCount < limit - 1) ? (!ec) : bool(ec));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,21 +579,14 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
return cfg;
|
||||
})};
|
||||
|
||||
auto const port =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port").value();
|
||||
auto const ip =
|
||||
env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
auto const port = env.app().config()["port_ws"].get<std::uint16_t>("port").value();
|
||||
auto const ip = env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
boost::system::error_code ec;
|
||||
doRequest(yield, makeWSUpgrade(ip, port), ip, port, true, resp, ec);
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::switching_protocols);
|
||||
BEAST_EXPECT(
|
||||
resp.find("Upgrade") != resp.end() &&
|
||||
resp["Upgrade"] == "websocket");
|
||||
BEAST_EXPECT(
|
||||
resp.find("Connection") != resp.end() &&
|
||||
boost::iequals(resp["Connection"], "upgrade"));
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::switching_protocols);
|
||||
BEAST_EXPECT(resp.find("Upgrade") != resp.end() && resp["Upgrade"] == "websocket");
|
||||
BEAST_EXPECT(resp.find("Connection") != resp.end() && boost::iequals(resp["Connection"], "upgrade"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -671,22 +597,13 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
using namespace test::jtx;
|
||||
Env env{*this};
|
||||
|
||||
auto const port =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port").value();
|
||||
auto const ip =
|
||||
env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
auto const port = env.app().config()["port_ws"].get<std::uint16_t>("port").value();
|
||||
auto const ip = env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
boost::system::error_code ec;
|
||||
// body content is required here to avoid being
|
||||
// detected as a status request
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(ip, port, "foo", {}),
|
||||
ip,
|
||||
port,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(ip, port, "foo", {}), ip, port, false, resp, ec);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden);
|
||||
BEAST_EXPECT(resp.body() == "Forbidden\r\n");
|
||||
}
|
||||
@@ -701,10 +618,8 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
using namespace boost::beast::http;
|
||||
Env env{*this};
|
||||
|
||||
auto const port =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port").value();
|
||||
auto const ip =
|
||||
env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
auto const port = env.app().config()["port_ws"].get<std::uint16_t>("port").value();
|
||||
auto const ip = env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
boost::system::error_code ec;
|
||||
|
||||
io_context& ios = get_io_context();
|
||||
@@ -735,10 +650,8 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
|
||||
Json::Value resp;
|
||||
Json::Reader jr;
|
||||
if (!BEAST_EXPECT(jr.parse(
|
||||
boost::lexical_cast<std::string>(
|
||||
boost::beast::make_printable(sb.data())),
|
||||
resp)))
|
||||
if (!BEAST_EXPECT(
|
||||
jr.parse(boost::lexical_cast<std::string>(boost::beast::make_printable(sb.data())), resp)))
|
||||
return Json::objectValue;
|
||||
sb.consume(sb.size());
|
||||
return resp;
|
||||
@@ -746,8 +659,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
|
||||
{ // send invalid json
|
||||
auto resp = sendAndParse("NOT JSON");
|
||||
BEAST_EXPECT(
|
||||
resp.isMember(jss::error) && resp[jss::error] == "jsonInvalid");
|
||||
BEAST_EXPECT(resp.isMember(jss::error) && resp[jss::error] == "jsonInvalid");
|
||||
BEAST_EXPECT(!resp.isMember(jss::status));
|
||||
}
|
||||
|
||||
@@ -756,22 +668,17 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
jv[jss::command] = "foo";
|
||||
jv[jss::method] = "bar";
|
||||
auto resp = sendAndParse(to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.isMember(jss::error) &&
|
||||
resp[jss::error] == "missingCommand");
|
||||
BEAST_EXPECT(
|
||||
resp.isMember(jss::status) && resp[jss::status] == "error");
|
||||
BEAST_EXPECT(resp.isMember(jss::error) && resp[jss::error] == "missingCommand");
|
||||
BEAST_EXPECT(resp.isMember(jss::status) && resp[jss::status] == "error");
|
||||
}
|
||||
|
||||
{ // send a ping (not an error)
|
||||
Json::Value jv;
|
||||
jv[jss::command] = "ping";
|
||||
auto resp = sendAndParse(to_string(jv));
|
||||
BEAST_EXPECT(resp.isMember(jss::status) && resp[jss::status] == "success");
|
||||
BEAST_EXPECT(
|
||||
resp.isMember(jss::status) && resp[jss::status] == "success");
|
||||
BEAST_EXPECT(
|
||||
resp.isMember(jss::result) &&
|
||||
resp[jss::result].isMember(jss::role) &&
|
||||
resp.isMember(jss::result) && resp[jss::result].isMember(jss::role) &&
|
||||
resp[jss::result][jss::role] == "admin");
|
||||
}
|
||||
}
|
||||
@@ -779,8 +686,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
void
|
||||
testAmendmentWarning(boost::asio::yield_context& yield)
|
||||
{
|
||||
testcase(
|
||||
"Status request over WS and RPC with/without Amendment Warning");
|
||||
testcase("Status request over WS and RPC with/without Amendment Warning");
|
||||
using namespace jtx;
|
||||
using namespace boost::asio;
|
||||
using namespace boost::beast::http;
|
||||
@@ -805,8 +711,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
auto si = env.rpc("server_info")[jss::result];
|
||||
BEAST_EXPECT(si.isMember(jss::info));
|
||||
BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
|
||||
BEAST_EXPECT(
|
||||
env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(!si.isMember(jss::warnings));
|
||||
|
||||
// make an RPC server state request and look for
|
||||
@@ -814,39 +719,28 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
si = env.rpc("server_state")[jss::result];
|
||||
BEAST_EXPECT(si.isMember(jss::state));
|
||||
BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
|
||||
BEAST_EXPECT(
|
||||
env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(!si[jss::state].isMember(jss::warnings));
|
||||
|
||||
auto const port_ws =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const port_ws = env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const ip_ws = env.app().config()["port_ws"].get<std::string>("ip");
|
||||
|
||||
boost::system::error_code ec;
|
||||
response<string_body> resp;
|
||||
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip_ws, *port_ws, "", {}),
|
||||
*ip_ws,
|
||||
*port_ws,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip_ws, *port_ws, "", {}), *ip_ws, *port_ws, false, resp, ec);
|
||||
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("connectivity is working.") != std::string::npos);
|
||||
BEAST_EXPECT(resp.body().find("connectivity is working.") != std::string::npos);
|
||||
|
||||
// mark the Network as having an Amendment Warning, but won't fail
|
||||
env.app().getOPs().setAmendmentWarned();
|
||||
env.app().getOPs().beginConsensus(env.closed()->header().hash, {});
|
||||
|
||||
// consensus doesn't change
|
||||
BEAST_EXPECT(
|
||||
env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
|
||||
// RPC request server_info again, now unsupported majority should be
|
||||
// returned
|
||||
@@ -854,11 +748,9 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
BEAST_EXPECT(si.isMember(jss::info));
|
||||
BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
|
||||
BEAST_EXPECT(
|
||||
si[jss::info].isMember(jss::warnings) &&
|
||||
si[jss::info][jss::warnings].isArray() &&
|
||||
si[jss::info].isMember(jss::warnings) && si[jss::info][jss::warnings].isArray() &&
|
||||
si[jss::info][jss::warnings].size() == 1 &&
|
||||
si[jss::info][jss::warnings][0u][jss::id].asInt() ==
|
||||
warnRPC_UNSUPPORTED_MAJORITY);
|
||||
si[jss::info][jss::warnings][0u][jss::id].asInt() == warnRPC_UNSUPPORTED_MAJORITY);
|
||||
|
||||
// RPC request server_state again, now unsupported majority should be
|
||||
// returned
|
||||
@@ -866,45 +758,27 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
BEAST_EXPECT(si.isMember(jss::state));
|
||||
BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
|
||||
BEAST_EXPECT(
|
||||
si[jss::state].isMember(jss::warnings) &&
|
||||
si[jss::state][jss::warnings].isArray() &&
|
||||
si[jss::state].isMember(jss::warnings) && si[jss::state][jss::warnings].isArray() &&
|
||||
si[jss::state][jss::warnings].size() == 1 &&
|
||||
si[jss::state][jss::warnings][0u][jss::id].asInt() ==
|
||||
warnRPC_UNSUPPORTED_MAJORITY);
|
||||
si[jss::state][jss::warnings][0u][jss::id].asInt() == warnRPC_UNSUPPORTED_MAJORITY);
|
||||
|
||||
// but status does not indicate a problem
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip_ws, *port_ws, "", {}),
|
||||
*ip_ws,
|
||||
*port_ws,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip_ws, *port_ws, "", {}), *ip_ws, *port_ws, false, resp, ec);
|
||||
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("connectivity is working.") != std::string::npos);
|
||||
BEAST_EXPECT(resp.body().find("connectivity is working.") != std::string::npos);
|
||||
|
||||
// with ELB_SUPPORT, status still does not indicate a problem
|
||||
env.app().config().ELB_SUPPORT = true;
|
||||
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip_ws, *port_ws, "", {}),
|
||||
*ip_ws,
|
||||
*port_ws,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip_ws, *port_ws, "", {}), *ip_ws, *port_ws, false, resp, ec);
|
||||
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("connectivity is working.") != std::string::npos);
|
||||
BEAST_EXPECT(resp.body().find("connectivity is working.") != std::string::npos);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -935,8 +809,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
auto si = env.rpc("server_info")[jss::result];
|
||||
BEAST_EXPECT(si.isMember(jss::info));
|
||||
BEAST_EXPECT(!si[jss::info].isMember(jss::amendment_blocked));
|
||||
BEAST_EXPECT(
|
||||
env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(!si.isMember(jss::warnings));
|
||||
|
||||
// make an RPC server state request and look for
|
||||
@@ -944,31 +817,21 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
si = env.rpc("server_state")[jss::result];
|
||||
BEAST_EXPECT(si.isMember(jss::state));
|
||||
BEAST_EXPECT(!si[jss::state].isMember(jss::amendment_blocked));
|
||||
BEAST_EXPECT(
|
||||
env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||
BEAST_EXPECT(!si[jss::state].isMember(jss::warnings));
|
||||
|
||||
auto const port_ws =
|
||||
env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const port_ws = env.app().config()["port_ws"].get<std::uint16_t>("port");
|
||||
auto const ip_ws = env.app().config()["port_ws"].get<std::string>("ip");
|
||||
|
||||
boost::system::error_code ec;
|
||||
response<string_body> resp;
|
||||
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip_ws, *port_ws, "", {}),
|
||||
*ip_ws,
|
||||
*port_ws,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip_ws, *port_ws, "", {}), *ip_ws, *port_ws, false, resp, ec);
|
||||
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("connectivity is working.") != std::string::npos);
|
||||
BEAST_EXPECT(resp.body().find("connectivity is working.") != std::string::npos);
|
||||
|
||||
// mark the Network as Amendment Blocked, but still won't fail until
|
||||
// ELB is enabled (next step)
|
||||
@@ -976,70 +839,43 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
env.app().getOPs().beginConsensus(env.closed()->header().hash, {});
|
||||
|
||||
// consensus now sees validation disabled
|
||||
BEAST_EXPECT(
|
||||
env.app().getOPs().getConsensusInfo()["validating"] == false);
|
||||
BEAST_EXPECT(env.app().getOPs().getConsensusInfo()["validating"] == false);
|
||||
|
||||
// RPC request server_info again, now AB should be returned
|
||||
si = env.rpc("server_info")[jss::result];
|
||||
BEAST_EXPECT(si.isMember(jss::info));
|
||||
BEAST_EXPECT(si[jss::info].isMember(jss::amendment_blocked) && si[jss::info][jss::amendment_blocked] == true);
|
||||
BEAST_EXPECT(
|
||||
si[jss::info].isMember(jss::amendment_blocked) &&
|
||||
si[jss::info][jss::amendment_blocked] == true);
|
||||
BEAST_EXPECT(
|
||||
si[jss::info].isMember(jss::warnings) &&
|
||||
si[jss::info][jss::warnings].isArray() &&
|
||||
si[jss::info].isMember(jss::warnings) && si[jss::info][jss::warnings].isArray() &&
|
||||
si[jss::info][jss::warnings].size() == 1 &&
|
||||
si[jss::info][jss::warnings][0u][jss::id].asInt() ==
|
||||
warnRPC_AMENDMENT_BLOCKED);
|
||||
si[jss::info][jss::warnings][0u][jss::id].asInt() == warnRPC_AMENDMENT_BLOCKED);
|
||||
|
||||
// RPC request server_state again, now AB should be returned
|
||||
si = env.rpc("server_state")[jss::result];
|
||||
BEAST_EXPECT(si[jss::state].isMember(jss::amendment_blocked) && si[jss::state][jss::amendment_blocked] == true);
|
||||
BEAST_EXPECT(
|
||||
si[jss::state].isMember(jss::amendment_blocked) &&
|
||||
si[jss::state][jss::amendment_blocked] == true);
|
||||
BEAST_EXPECT(
|
||||
si[jss::state].isMember(jss::warnings) &&
|
||||
si[jss::state][jss::warnings].isArray() &&
|
||||
si[jss::state].isMember(jss::warnings) && si[jss::state][jss::warnings].isArray() &&
|
||||
si[jss::state][jss::warnings].size() == 1 &&
|
||||
si[jss::state][jss::warnings][0u][jss::id].asInt() ==
|
||||
warnRPC_AMENDMENT_BLOCKED);
|
||||
si[jss::state][jss::warnings][0u][jss::id].asInt() == warnRPC_AMENDMENT_BLOCKED);
|
||||
|
||||
// but status does not indicate because it still relies on ELB
|
||||
// being enabled
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip_ws, *port_ws, "", {}),
|
||||
*ip_ws,
|
||||
*port_ws,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip_ws, *port_ws, "", {}), *ip_ws, *port_ws, false, resp, ec);
|
||||
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::ok);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("connectivity is working.") != std::string::npos);
|
||||
BEAST_EXPECT(resp.body().find("connectivity is working.") != std::string::npos);
|
||||
|
||||
env.app().config().ELB_SUPPORT = true;
|
||||
|
||||
doRequest(
|
||||
yield,
|
||||
makeHTTPRequest(*ip_ws, *port_ws, "", {}),
|
||||
*ip_ws,
|
||||
*port_ws,
|
||||
false,
|
||||
resp,
|
||||
ec);
|
||||
doRequest(yield, makeHTTPRequest(*ip_ws, *port_ws, "", {}), *ip_ws, *port_ws, false, resp, ec);
|
||||
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::internal_server_error);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("cannot accept clients:") != std::string::npos);
|
||||
BEAST_EXPECT(
|
||||
resp.body().find("Server version too old") != std::string::npos);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::internal_server_error);
|
||||
BEAST_EXPECT(resp.body().find("cannot accept clients:") != std::string::npos);
|
||||
BEAST_EXPECT(resp.body().find("Server version too old") != std::string::npos);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1054,8 +890,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
{
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
doHTTPRequest(env, yield, false, resp, ec, "{}");
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Unable to parse request: \r\n");
|
||||
}
|
||||
|
||||
@@ -1064,8 +899,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
Json::Value jv;
|
||||
jv["invalid"] = 1;
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Null method\r\n");
|
||||
}
|
||||
|
||||
@@ -1074,8 +908,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
Json::Value jv(Json::arrayValue);
|
||||
jv.append("invalid");
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Unable to parse request: \r\n");
|
||||
}
|
||||
|
||||
@@ -1086,8 +919,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
j["invalid"] = 1;
|
||||
jv.append(j);
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Unable to parse request: \r\n");
|
||||
}
|
||||
|
||||
@@ -1097,8 +929,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
jv[jss::method] = "batch";
|
||||
jv[jss::params] = 2;
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Malformed batch request\r\n");
|
||||
}
|
||||
|
||||
@@ -1109,8 +940,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
jv[jss::params] = Json::objectValue;
|
||||
jv[jss::params]["invalid"] = 3;
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Malformed batch request\r\n");
|
||||
}
|
||||
|
||||
@@ -1119,8 +949,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
jv[jss::method] = Json::nullValue;
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "Null method\r\n");
|
||||
}
|
||||
|
||||
@@ -1128,8 +957,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
jv[jss::method] = 1;
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "method is not string\r\n");
|
||||
}
|
||||
|
||||
@@ -1137,8 +965,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
jv[jss::method] = "";
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "method is empty\r\n");
|
||||
}
|
||||
|
||||
@@ -1147,8 +974,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
jv[jss::method] = "some_method";
|
||||
jv[jss::params] = "params";
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "params unparsable\r\n");
|
||||
}
|
||||
|
||||
@@ -1157,8 +983,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
jv[jss::params] = Json::arrayValue;
|
||||
jv[jss::params][0u] = "not an object";
|
||||
doHTTPRequest(env, yield, false, resp, ec, to_string(jv));
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request);
|
||||
BEAST_EXPECT(resp.body() == "params unparsable\r\n");
|
||||
}
|
||||
}
|
||||
@@ -1180,8 +1005,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
boost::beast::http::response<boost::beast::http::string_body> resp;
|
||||
boost::system::error_code ec;
|
||||
doHTTPRequest(env, yield, false, resp, ec);
|
||||
BEAST_EXPECT(
|
||||
resp.result() == boost::beast::http::status::internal_server_error);
|
||||
BEAST_EXPECT(resp.result() == boost::beast::http::status::internal_server_error);
|
||||
std::regex body{"Server cannot accept clients"};
|
||||
BEAST_EXPECT(std::regex_search(resp.body(), body));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user