style: Mark JSON literal strings with R"JSON (#2169)

This commit is contained in:
Ayaz Salikhov
2025-05-30 15:50:39 +01:00
committed by GitHub
parent 7588e9d5bf
commit ecdea015b9
76 changed files with 2811 additions and 2748 deletions

View File

@@ -169,27 +169,27 @@ INSTANTIATE_TEST_SUITE_P(
},
MakeAdminVerificationStrategyFromConfigTestParams{
.testName = "OnlyPassword",
.config = R"({"server": {"admin_password": "password"}})",
.config = R"JSON({"server": {"admin_password": "password"}})JSON",
.expectedError = false
},
MakeAdminVerificationStrategyFromConfigTestParams{
.testName = "OnlyLocalAdmin",
.config = R"({"server": {"local_admin": true}})",
.config = R"JSON({"server": {"local_admin": true}})JSON",
.expectedError = false
},
MakeAdminVerificationStrategyFromConfigTestParams{
.testName = "OnlyLocalAdminDisabled",
.config = R"({"server": {"local_admin": false}})",
.config = R"JSON({"server": {"local_admin": false}})JSON",
.expectedError = true
},
MakeAdminVerificationStrategyFromConfigTestParams{
.testName = "LocalAdminAndPassword",
.config = R"({"server": {"local_admin": true, "admin_password": "password"}})",
.config = R"JSON({"server": {"local_admin": true, "admin_password": "password"}})JSON",
.expectedError = true
},
MakeAdminVerificationStrategyFromConfigTestParams{
.testName = "LocalAdminDisabledAndPassword",
.config = R"({"server": {"local_admin": false, "admin_password": "password"}})",
.config = R"JSON({"server": {"local_admin": false, "admin_password": "password"}})JSON",
.expectedError = false
}
),

View File

@@ -112,15 +112,15 @@ struct WebRPCServerHandlerTest : util::prometheus::WithPrometheus, MockBackendTe
TEST_F(WebRPCServerHandlerTest, HTTPDefaultPath)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESULT = "{}";
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result": {
"status": "success"
},
@@ -130,7 +130,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPDefaultPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -148,10 +148,10 @@ TEST_F(WebRPCServerHandlerTest, HTTPDefaultPath)
TEST_F(WebRPCServerHandlerTest, HTTPRejectedByDosguard)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(false));
@@ -161,10 +161,10 @@ TEST_F(WebRPCServerHandlerTest, HTTPRejectedByDosguard)
TEST_F(WebRPCServerHandlerTest, HTTPRejectedByDosguardAfterParsing)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, testing::_)).WillOnce(testing::Return(false));
@@ -176,16 +176,16 @@ TEST_F(WebRPCServerHandlerTest, HTTPRejectedByDosguardAfterParsing)
TEST_F(WebRPCServerHandlerTest, WsNormalPath)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99,
"api_version": 2
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESULT = "{}";
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result":{},
"id": 99,
"status": "success",
@@ -197,7 +197,7 @@ TEST_F(WebRPCServerHandlerTest, WsNormalPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
.WillOnce(testing::Return(true));
@@ -215,11 +215,11 @@ TEST_F(WebRPCServerHandlerTest, WsNormalPath)
TEST_F(WebRPCServerHandlerTest, WsRejectedByDosguard)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99,
"api_version": 2
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(false));
@@ -230,11 +230,11 @@ TEST_F(WebRPCServerHandlerTest, WsRejectedByDosguard)
TEST_F(WebRPCServerHandlerTest, WsRejectedByDosguardAfterParsing)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99,
"api_version": 2
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -246,21 +246,21 @@ TEST_F(WebRPCServerHandlerTest, WsRejectedByDosguardAfterParsing)
TEST_F(WebRPCServerHandlerTest, HTTPForwardedPath)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
// Note: forwarding always goes thru WS API
static constexpr auto kRESULT = R"({
static constexpr auto kRESULT = R"JSON({
"result": {
"index": 1
},
"forwarded": true
})";
static constexpr auto kRESPONSE = R"({
})JSON";
static constexpr auto kRESPONSE = R"JSON({
"result":{
"index": 1,
"status": "success"
@@ -272,7 +272,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPForwardedPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -290,23 +290,23 @@ TEST_F(WebRPCServerHandlerTest, HTTPForwardedPath)
TEST_F(WebRPCServerHandlerTest, HTTPForwardedErrorPath)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
// Note: forwarding always goes thru WS API
static constexpr auto kRESULT = R"({
static constexpr auto kRESULT = R"JSON({
"error": "error",
"error_code": 123,
"error_message": "error message",
"status": "error",
"type": "response",
"forwarded": true
})";
static constexpr auto kRESPONSE = R"({
})JSON";
static constexpr auto kRESPONSE = R"JSON({
"result":{
"error": "error",
"error_code": 123,
@@ -321,7 +321,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPForwardedErrorPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -340,21 +340,21 @@ TEST_F(WebRPCServerHandlerTest, HTTPForwardedErrorPath)
TEST_F(WebRPCServerHandlerTest, WsForwardedPath)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
// Note: forwarding always goes thru WS API
static constexpr auto kRESULT = R"({
static constexpr auto kRESULT = R"JSON({
"result": {
"index": 1
},
"forwarded": true
})";
static constexpr auto kRESPONSE = R"({
})JSON";
static constexpr auto kRESPONSE = R"JSON({
"result":{
"index": 1
},
@@ -368,7 +368,7 @@ TEST_F(WebRPCServerHandlerTest, WsForwardedPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -387,24 +387,24 @@ TEST_F(WebRPCServerHandlerTest, WsForwardedPath)
TEST_F(WebRPCServerHandlerTest, WsForwardedErrorPath)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
// Note: forwarding always goes thru WS API
static constexpr auto kRESULT = R"({
static constexpr auto kRESULT = R"JSON({
"error": "error",
"error_code": 123,
"error_message": "error message",
"status": "error",
"type": "response",
"forwarded": true
})";
})JSON";
// WS error responses, unlike their successful counterpart, contain everything on top level without "result"
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"error": "error",
"error_code": 123,
"error_message": "error message",
@@ -418,7 +418,7 @@ TEST_F(WebRPCServerHandlerTest, WsForwardedErrorPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -437,7 +437,7 @@ TEST_F(WebRPCServerHandlerTest, WsForwardedErrorPath)
TEST_F(WebRPCServerHandlerTest, HTTPErrorPath)
{
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result": {
"error": "invalidParams",
"error_code": 31,
@@ -459,18 +459,18 @@ TEST_F(WebRPCServerHandlerTest, HTTPErrorPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kREQUEST_JSON = R"({
static constexpr auto kREQUEST_JSON = R"JSON({
"method": "ledger",
"params": [
{
"ledger_index": "xx"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST_JSON).as_object()))
@@ -489,7 +489,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPErrorPath)
TEST_F(WebRPCServerHandlerTest, WsErrorPath)
{
session->upgraded = true;
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"id": "123",
"error": "invalidParams",
"error_code": 31,
@@ -509,16 +509,16 @@ TEST_F(WebRPCServerHandlerTest, WsErrorPath)
"message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
}
]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kREQUEST_JSON = R"({
static constexpr auto kREQUEST_JSON = R"JSON({
"command": "ledger",
"ledger_index": "xx",
"id": "123",
"api_version": 2
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST_JSON).as_object()))
@@ -536,12 +536,12 @@ TEST_F(WebRPCServerHandlerTest, WsErrorPath)
TEST_F(WebRPCServerHandlerTest, HTTPNotReady)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result": {
"error": "notReady",
"error_code": 13,
@@ -553,7 +553,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPNotReady)
"params": [{}]
}
}
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -569,12 +569,12 @@ TEST_F(WebRPCServerHandlerTest, WsNotReady)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99
})";
})JSON";
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"error": "notReady",
"error_code": 13,
"error_message": "Not ready to handle this request.",
@@ -585,7 +585,7 @@ TEST_F(WebRPCServerHandlerTest, WsNotReady)
"command": "server_info",
"id": 99
}
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -599,11 +599,11 @@ TEST_F(WebRPCServerHandlerTest, WsNotReady)
TEST_F(WebRPCServerHandlerTest, HTTPBadSyntaxWhenRequestSubscribe)
{
static constexpr auto kREQUEST = R"({"method": "subscribe"})";
static constexpr auto kREQUEST = R"JSON({"method": "subscribe"})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result": {
"error": "badSyntax",
"error_code": 1,
@@ -615,7 +615,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPBadSyntaxWhenRequestSubscribe)
"params": [{}]
}
}
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, testing::_)).WillOnce(testing::Return(true));
@@ -628,7 +628,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPBadSyntaxWhenRequestSubscribe)
TEST_F(WebRPCServerHandlerTest, HTTPMissingCommand)
{
static constexpr auto kREQUEST = R"({"method2": "server_info"})";
static constexpr auto kREQUEST = R"JSON({"method2": "server_info"})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
@@ -646,7 +646,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPMissingCommand)
TEST_F(WebRPCServerHandlerTest, HTTPCommandNotString)
{
static constexpr auto kREQUEST = R"({"method": 1})";
static constexpr auto kREQUEST = R"JSON({"method": 1})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
@@ -664,7 +664,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPCommandNotString)
TEST_F(WebRPCServerHandlerTest, HTTPCommandIsEmpty)
{
static constexpr auto kREQUEST = R"({"method": ""})";
static constexpr auto kREQUEST = R"JSON({"method": ""})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
@@ -683,14 +683,14 @@ TEST_F(WebRPCServerHandlerTest, HTTPCommandIsEmpty)
TEST_F(WebRPCServerHandlerTest, WsMissingCommand)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command2": "server_info",
"id": 99
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"error": "missingCommand",
"error_code": 6001,
"error_message": "Method/Command is not specified or is not a string.",
@@ -701,7 +701,7 @@ TEST_F(WebRPCServerHandlerTest, WsMissingCommand)
"command2": "server_info",
"id": 99
}
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -719,10 +719,10 @@ TEST_F(WebRPCServerHandlerTest, HTTPParamsUnparsableNotArray)
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kREQUEST_JSON = R"({
static constexpr auto kREQUEST_JSON = R"JSON({
"method": "ledger",
"params": "wrong"
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, testing::_)).WillOnce(testing::Return(true));
@@ -740,10 +740,10 @@ TEST_F(WebRPCServerHandlerTest, HTTPParamsUnparsableArrayWithDigit)
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kREQUEST_JSON = R"({
static constexpr auto kREQUEST_JSON = R"JSON({
"method": "ledger",
"params": [1]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, testing::_)).WillOnce(testing::Return(true));
@@ -757,7 +757,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPParamsUnparsableArrayWithDigit)
TEST_F(WebRPCServerHandlerTest, HTTPInternalError)
{
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result": {
"error": "internal",
"error_code": 73,
@@ -769,14 +769,14 @@ TEST_F(WebRPCServerHandlerTest, HTTPInternalError)
"params": [{}]
}
}
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kREQUEST_JSON = R"({
static constexpr auto kREQUEST_JSON = R"JSON({
"method": "ledger",
"params": [{}]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST_JSON).as_object()))
@@ -793,7 +793,7 @@ TEST_F(WebRPCServerHandlerTest, WsInternalError)
{
session->upgraded = true;
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"error": "internal",
"error_code": 73,
"error_message": "Internal error.",
@@ -804,14 +804,14 @@ TEST_F(WebRPCServerHandlerTest, WsInternalError)
"command": "ledger",
"id": "123"
}
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kREQUEST_JSON = R"({
static constexpr auto kREQUEST_JSON = R"JSON({
"command": "ledger",
"id": "123"
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST_JSON).as_object()))
@@ -826,15 +826,15 @@ TEST_F(WebRPCServerHandlerTest, WsInternalError)
TEST_F(WebRPCServerHandlerTest, HTTPOutDated)
{
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESULT = "{}";
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result": {
"status": "success"
},
@@ -848,7 +848,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPOutDated)
"message": "This server may be out of date"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -868,15 +868,15 @@ TEST_F(WebRPCServerHandlerTest, WsOutdated)
{
session->upgraded = true;
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESULT = "{}";
static constexpr auto kRESPONSE = R"({
static constexpr auto kRESPONSE = R"JSON({
"result":{},
"id": 99,
"status": "success",
@@ -891,7 +891,7 @@ TEST_F(WebRPCServerHandlerTest, WsOutdated)
"message": "This server may be out of date"
}
]
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -913,21 +913,21 @@ TEST_F(WebRPCServerHandlerTest, WsTooBusy)
auto localRpcEngine = std::make_shared<MockRPCEngine>();
auto localHandler = std::make_shared<RPCServerHandler<MockRPCEngine>>(cfg, backend_, localRpcEngine, etl, dosguard);
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"command": "server_info",
"id": 99
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESPONSE =
R"({
R"JSON({
"error": "tooBusy",
"error_code": 9,
"error_message": "The server is too busy to help you now.",
"status": "error",
"type": "response"
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -944,21 +944,21 @@ TEST_F(WebRPCServerHandlerTest, HTTPTooBusy)
{
auto localRpcEngine = std::make_shared<MockRPCEngine>();
auto localHandler = std::make_shared<RPCServerHandler<MockRPCEngine>>(cfg, backend_, localRpcEngine, etl, dosguard);
static constexpr auto kREQUEST = R"({
static constexpr auto kREQUEST = R"JSON({
"method": "server_info",
"params": [{}]
})";
})JSON";
backend_->setRange(kMIN_SEQ, kMAX_SEQ);
static constexpr auto kRESPONSE =
R"({
R"JSON({
"error": "tooBusy",
"error_code": 9,
"error_message": "The server is too busy to help you now.",
"status": "error",
"type": "response"
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
EXPECT_CALL(dosguard, request(session->clientIp, boost::json::parse(kREQUEST).as_object()))
@@ -990,13 +990,13 @@ TEST_F(WebRPCServerHandlerTest, WsRequestNotJson)
session->upgraded = true;
static constexpr auto kREQUEST = "not json";
static constexpr auto kRESPONSE =
R"({
R"JSON({
"error": "badSyntax",
"error_code": 1,
"error_message": "Syntax error.",
"status": "error",
"type": "response"
})";
})JSON";
EXPECT_CALL(dosguard, isOk(session->clientIp)).WillOnce(testing::Return(true));
@@ -1045,12 +1045,12 @@ INSTANTIATE_TEST_CASE_P(
TEST_P(WebRPCServerHandlerInvalidAPIVersionParamTest, HTTPInvalidAPIVersion)
{
auto request = fmt::format(
R"({{
R"JSON({{
"method": "server_info",
"params": [{{
"api_version": {}
}}]
}})",
}})JSON",
GetParam().version
);
@@ -1071,10 +1071,10 @@ TEST_P(WebRPCServerHandlerInvalidAPIVersionParamTest, WSInvalidAPIVersion)
{
session->upgraded = true;
auto request = fmt::format(
R"({{
R"JSON({{
"method": "server_info",
"api_version": {}
}})",
}})JSON",
GetParam().version
);

View File

@@ -246,8 +246,8 @@ TEST_F(WebServerTest, Http)
{
auto const e = std::make_shared<EchoExecutor>();
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
auto const [status, res] = HttpSyncClient::post("localhost", port, R"({"Hello":1})");
EXPECT_EQ(res, R"({"Hello":1})");
auto const [status, res] = HttpSyncClient::post("localhost", port, R"JSON({"Hello":1})JSON");
EXPECT_EQ(res, R"JSON({"Hello":1})JSON");
EXPECT_EQ(status, boost::beast::http::status::ok);
}
@@ -257,8 +257,8 @@ TEST_F(WebServerTest, Ws)
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
WebSocketSyncClient wsClient;
wsClient.connect("localhost", port);
auto const res = wsClient.syncPost(R"({"Hello":1})");
EXPECT_EQ(res, R"({"Hello":1})");
auto const res = wsClient.syncPost(R"JSON({"Hello":1})JSON");
EXPECT_EQ(res, R"JSON({"Hello":1})JSON");
wsClient.disconnect();
}
@@ -266,10 +266,10 @@ TEST_F(WebServerTest, HttpInternalError)
{
auto const e = std::make_shared<ExceptionExecutor>();
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
auto const [status, res] = HttpSyncClient::post("localhost", port, R"({})");
auto const [status, res] = HttpSyncClient::post("localhost", port, R"JSON({})JSON");
EXPECT_EQ(
res,
R"({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"})"
R"JSON({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"})JSON"
);
EXPECT_EQ(status, boost::beast::http::status::internal_server_error);
}
@@ -280,11 +280,11 @@ TEST_F(WebServerTest, WsInternalError)
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
WebSocketSyncClient wsClient;
wsClient.connect("localhost", port);
auto const res = wsClient.syncPost(R"({"id":"id1"})");
auto const res = wsClient.syncPost(R"JSON({"id":"id1"})JSON");
wsClient.disconnect();
EXPECT_EQ(
res,
R"({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","id":"id1","request":{"id":"id1"}})"
R"JSON({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","id":"id1","request":{"id":"id1"}})JSON"
);
}
@@ -298,7 +298,7 @@ TEST_F(WebServerTest, WsInternalErrorNotJson)
wsClient.disconnect();
EXPECT_EQ(
res,
R"({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","request":"not json"})"
R"JSON({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","request":"not json"})JSON"
);
}
@@ -330,8 +330,8 @@ TEST_F(WebServerTest, Https)
auto const e = std::make_shared<EchoExecutor>();
cfg = getParseServerConfig(addSslConfig(generateJSONWithDynamicPort(port)));
auto const server = makeServerSync(cfg, ctx, dosGuard, e);
auto const res = HttpsSyncClient::syncPost("localhost", port, R"({"Hello":1})");
EXPECT_EQ(res, R"({"Hello":1})");
auto const res = HttpsSyncClient::syncPost("localhost", port, R"JSON({"Hello":1})JSON");
EXPECT_EQ(res, R"JSON({"Hello":1})JSON");
}
TEST_F(WebServerTest, Wss)
@@ -341,8 +341,8 @@ TEST_F(WebServerTest, Wss)
auto server = makeServerSync(cfg, ctx, dosGuard, e);
WebServerSslSyncClient wsClient;
wsClient.connect("localhost", port);
auto const res = wsClient.syncPost(R"({"Hello":1})");
EXPECT_EQ(res, R"({"Hello":1})");
auto const res = wsClient.syncPost(R"JSON({"Hello":1})JSON");
EXPECT_EQ(res, R"JSON({"Hello":1})JSON");
wsClient.disconnect();
}
@@ -351,10 +351,11 @@ TEST_F(WebServerTest, HttpPayloadOverload)
std::string const s100(100, 'a');
auto const e = std::make_shared<EchoExecutor>();
auto server = makeServerSync(cfg, ctx, dosGuardOverload, e);
auto const [status, res] = HttpSyncClient::post("localhost", port, fmt::format(R"({{"payload":"{}"}})", s100));
auto const [status, res] =
HttpSyncClient::post("localhost", port, fmt::format(R"JSON({{"payload":"{}"}})JSON", s100));
EXPECT_EQ(
res,
R"({"payload":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","warning":"load","warnings":[{"id":2003,"message":"You are about to be rate limited"}]})"
R"JSON({"payload":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","warning":"load","warnings":[{"id":2003,"message":"You are about to be rate limited"}]})JSON"
);
EXPECT_EQ(status, boost::beast::http::status::ok);
}
@@ -366,11 +367,11 @@ TEST_F(WebServerTest, WsPayloadOverload)
auto server = makeServerSync(cfg, ctx, dosGuardOverload, e);
WebSocketSyncClient wsClient;
wsClient.connect("localhost", port);
auto const res = wsClient.syncPost(fmt::format(R"({{"payload":"{}"}})", s100));
auto const res = wsClient.syncPost(fmt::format(R"JSON({{"payload":"{}"}})JSON", s100));
wsClient.disconnect();
EXPECT_EQ(
res,
R"({"payload":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","warning":"load","warnings":[{"id":2003,"message":"You are about to be rate limited"}]})"
R"JSON({"payload":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","warning":"load","warnings":[{"id":2003,"message":"You are about to be rate limited"}]})JSON"
);
}

View File

@@ -66,133 +66,133 @@ INSTANTIATE_TEST_SUITE_P(
WeightsTest,
::testing::Values(
TestParams{.testName = "EmptyObject", .requestJson = "{}", .expectedWeight = 10},
TestParams{.testName = "NonStringMethod", .requestJson = R"json({"method": 123})json", .expectedWeight = 10},
TestParams{.testName = "NonStringCommand", .requestJson = R"json({"command": 123})json", .expectedWeight = 10},
TestParams{.testName = "NonStringMethod", .requestJson = R"JSON({"method": 123})JSON", .expectedWeight = 10},
TestParams{.testName = "NonStringCommand", .requestJson = R"JSON({"command": 123})JSON", .expectedWeight = 10},
TestParams{
.testName = "UnknownMethodName",
.requestJson = R"json({"method": "unknown_method"})json",
.requestJson = R"JSON({"method": "unknown_method"})JSON",
.expectedWeight = 10
},
TestParams{
.testName = "UnknownCommandName",
.requestJson = R"json({"command": "unknown_command"})json",
.requestJson = R"JSON({"command": "unknown_command"})JSON",
.expectedWeight = 10
},
TestParams{
.testName = "OnlyWeight_NoLedgerIndex",
.requestJson = R"json({"method": "only_weight"})json",
.requestJson = R"JSON({"method": "only_weight"})JSON",
.expectedWeight = 20
},
TestParams{
.testName = "OnlyWeight_CurrentLedgerIndex",
.requestJson = R"json({"method": "only_weight", "ledger_index": "current"})json",
.requestJson = R"JSON({"method": "only_weight", "ledger_index": "current"})JSON",
.expectedWeight = 20
},
TestParams{
.testName = "OnlyWeight_ValidatedLedgerIndex",
.requestJson = R"json({"method": "only_weight", "ledger_index": "validated"})json",
.requestJson = R"JSON({"method": "only_weight", "ledger_index": "validated"})JSON",
.expectedWeight = 20
},
TestParams{
.testName = "OnlyWeight_ClosedLedgerIndex",
.requestJson = R"json({"method": "only_weight", "ledger_index": "closed"})json",
.requestJson = R"JSON({"method": "only_weight", "ledger_index": "closed"})JSON",
.expectedWeight = 20
},
TestParams{
.testName = "OnlyWeight_NumericLedgerIndex",
.requestJson = R"json({"method": "only_weight", "ledger_index": "123"})json",
.requestJson = R"JSON({"method": "only_weight", "ledger_index": "123"})JSON",
.expectedWeight = 20
},
TestParams{
.testName = "OnlyWeight_OtherStringLedgerIndex",
.requestJson = R"json({"method": "only_weight", "ledger_index": "some_string"})json",
.requestJson = R"JSON({"method": "only_weight", "ledger_index": "some_string"})JSON",
.expectedWeight = 20
},
// With Current Weight
TestParams{
.testName = "WithCurrentWeight_NoLedgerIndex",
.requestJson = R"json({"method": "with_current_weight"})json",
.requestJson = R"JSON({"method": "with_current_weight"})JSON",
.expectedWeight = 30
},
TestParams{
.testName = "WithCurrentWeight_CurrentLedgerIndex",
.requestJson = R"json({"method": "with_current_weight", "ledger_index": "current"})json",
.requestJson = R"JSON({"method": "with_current_weight", "ledger_index": "current"})JSON",
.expectedWeight = 35
},
TestParams{
.testName = "WithCurrentWeight_ValidatedLedgerIndex",
.requestJson = R"json({"method": "with_current_weight", "ledger_index": "validated"})json",
.requestJson = R"JSON({"method": "with_current_weight", "ledger_index": "validated"})JSON",
.expectedWeight = 30
},
// With Validated Weight
TestParams{
.testName = "WithValidatedWeight_NoLedgerIndex",
.requestJson = R"json({"method": "with_validated_weight"})json",
.requestJson = R"JSON({"method": "with_validated_weight"})JSON",
.expectedWeight = 40
},
TestParams{
.testName = "WithValidatedWeight_CurrentLedgerIndex",
.requestJson = R"json({"method": "with_validated_weight", "ledger_index": "current"})json",
.requestJson = R"JSON({"method": "with_validated_weight", "ledger_index": "current"})JSON",
.expectedWeight = 40
},
TestParams{
.testName = "WithValidatedWeight_ValidatedLedgerIndex",
.requestJson = R"json({"method": "with_validated_weight", "ledger_index": "validated"})json",
.requestJson = R"JSON({"method": "with_validated_weight", "ledger_index": "validated"})JSON",
.expectedWeight = 45
},
// With Both Weights
TestParams{
.testName = "WithBothWeights_NoLedgerIndex",
.requestJson = R"json({"method": "with_both_weights"})json",
.requestJson = R"JSON({"method": "with_both_weights"})JSON",
.expectedWeight = 50
},
TestParams{
.testName = "WithBothWeights_CurrentLedgerIndex",
.requestJson = R"json({"method": "with_both_weights", "ledger_index": "current"})json",
.requestJson = R"JSON({"method": "with_both_weights", "ledger_index": "current"})JSON",
.expectedWeight = 55
},
TestParams{
.testName = "WithBothWeights_ValidatedLedgerIndex",
.requestJson = R"json({"method": "with_both_weights", "ledger_index": "validated"})json",
.requestJson = R"JSON({"method": "with_both_weights", "ledger_index": "validated"})JSON",
.expectedWeight = 60
},
// Using Command
TestParams{
.testName = "UsingCommand_NoLedgerIndex",
.requestJson = R"json({"command": "with_both_weights"})json",
.requestJson = R"JSON({"command": "with_both_weights"})JSON",
.expectedWeight = 50
},
TestParams{
.testName = "UsingCommand_CurrentLedgerIndex",
.requestJson = R"json({"command": "with_both_weights", "ledger_index": "current"})json",
.requestJson = R"JSON({"command": "with_both_weights", "ledger_index": "current"})JSON",
.expectedWeight = 55
},
TestParams{
.testName = "UsingCommand_ValidatedLedgerIndex",
.requestJson = R"json({"command": "with_both_weights", "ledger_index": "validated"})json",
.requestJson = R"JSON({"command": "with_both_weights", "ledger_index": "validated"})JSON",
.expectedWeight = 60
},
// With Params Array
TestParams{
.testName = "WithParamsArray_CurrentLedgerIndex",
.requestJson = R"json({"method": "with_both_weights", "params": [{"ledger_index": "current"}]})json",
.requestJson = R"JSON({"method": "with_both_weights", "params": [{"ledger_index": "current"}]})JSON",
.expectedWeight = 55
},
TestParams{
.testName = "WithParamsArray_ValidatedLedgerIndex",
.requestJson = R"json({"method": "with_both_weights", "params": [{"ledger_index": "validated"}]})json",
.requestJson = R"JSON({"method": "with_both_weights", "params": [{"ledger_index": "validated"}]})JSON",
.expectedWeight = 60
},
TestParams{
.testName = "WithParamsArray_WithCommand",
.requestJson = R"json({"command": "with_both_weights", "params": [{"ledger_index": "current"}]})json",
.requestJson = R"JSON({"command": "with_both_weights", "params": [{"ledger_index": "current"}]})JSON",
.expectedWeight = 55
}
),
@@ -213,7 +213,7 @@ TEST(WeightsMakeTest, CreateFromConfig)
{"dos_guard.__ng_weights.[].weight_ledger_validated",
util::config::Array{util::config::ConfigValue{util::config::ConfigType::Integer}.optional()}}
};
std::string const configStr = R"json(
std::string const configStr = R"JSON(
{
"dos_guard": {
"__ng_default_weight": 15,
@@ -237,7 +237,7 @@ TEST(WeightsMakeTest, CreateFromConfig)
]
}
}
)json";
)JSON";
auto const configJson = boost::json::parse(configStr).as_object();
@@ -245,33 +245,33 @@ TEST(WeightsMakeTest, CreateFromConfig)
Weights const weights = Weights::make(mockConfig);
auto request = boost::json::parse(R"json({"method": "unknown_method"})json").as_object();
auto request = boost::json::parse(R"JSON({"method": "unknown_method"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 15);
request = boost::json::parse(R"json({"method": "method1"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method1"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 25);
request = boost::json::parse(R"json({"method": "method1", "ledger_index": "current"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method1", "ledger_index": "current"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 30);
request = boost::json::parse(R"json({"method": "method1", "ledger_index": "validated"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method1", "ledger_index": "validated"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 25);
request = boost::json::parse(R"json({"method": "method2"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method2"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 35);
request = boost::json::parse(R"json({"method": "method2", "ledger_index": "current"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method2", "ledger_index": "current"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 35);
request = boost::json::parse(R"json({"method": "method2", "ledger_index": "validated"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method2", "ledger_index": "validated"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 40);
request = boost::json::parse(R"json({"method": "method3"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method3"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 45);
request = boost::json::parse(R"json({"method": "method3", "ledger_index": "current"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method3", "ledger_index": "current"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 50);
request = boost::json::parse(R"json({"method": "method3", "ledger_index": "validated"})json").as_object();
request = boost::json::parse(R"JSON({"method": "method3", "ledger_index": "validated"})JSON").as_object();
EXPECT_EQ(weights.requestWeight(request), 55);
}

View File

@@ -152,7 +152,7 @@ INSTANTIATE_TEST_CASE_P(
"UpgradedConnection",
true,
rpc::Status{rpc::RippledError::rpcTOO_BUSY},
R"({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})",
R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON",
boost::beast::http::status::ok
},
ErrorHandlingSendErrorTestBundle{
@@ -194,7 +194,7 @@ INSTANTIATE_TEST_CASE_P(
"NotUpgradedConnection_RippledError",
false,
rpc::Status{rpc::RippledError::rpcTOO_BUSY},
R"({"result":{"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"}})",
R"JSON({"result":{"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"}})JSON",
boost::beast::http::status::bad_request
},
}),
@@ -209,7 +209,7 @@ TEST_F(ErrorHandlingTests, sendInternalError)
*connection_,
send(
std::string{
R"({"result":{"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"}})"
R"JSON({"result":{"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"}})JSON"
},
boost::beast::http::status::internal_server_error
)
@@ -224,7 +224,7 @@ TEST_F(ErrorHandlingTests, sendNotReadyError)
*connection_,
send(
std::string{
R"({"result":{"error":"notReady","error_code":13,"error_message":"Not ready to handle this request.","status":"error","type":"response"}})"
R"JSON({"result":{"error":"notReady","error_code":13,"error_message":"Not ready to handle this request.","status":"error","type":"response"}})JSON"
},
boost::beast::http::status::ok
)
@@ -240,7 +240,7 @@ TEST_F(ErrorHandlingTests, sendTooBusyError_UpgradedConnection)
*connection_,
send(
std::string{
R"({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})"
R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON"
},
boost::beast::http::status::ok
)
@@ -256,7 +256,7 @@ TEST_F(ErrorHandlingTests, sendTooBusyError_NotUpgradedConnection)
*connection_,
send(
std::string{
R"({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})"
R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON"
},
boost::beast::http::status::service_unavailable
)
@@ -272,7 +272,7 @@ TEST_F(ErrorHandlingTests, sendJsonParsingError_UpgradedConnection)
*connection_,
send(
std::string{
R"({"error":"badSyntax","error_code":1,"error_message":"Syntax error.","status":"error","type":"response"})"
R"JSON({"error":"badSyntax","error_code":1,"error_message":"Syntax error.","status":"error","type":"response"})JSON"
},
boost::beast::http::status::ok
)

View File

@@ -131,7 +131,7 @@ TEST_F(NgRpcServerHandlerTest, DosguardRejectedWsRequest)
TEST_F(NgRpcServerHandlerTest, DosguardRejectedWsJsonRequest)
{
runSpawn([&](boost::asio::yield_context yield) {
auto const requestStr = R"json({"request": "some message", "id": "some id"})json";
auto const requestStr = R"JSON({"request": "some message", "id": "some id"})JSON";
auto const request = makeWsRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(false));
@@ -326,7 +326,7 @@ TEST_F(NgRpcServerHandlerTest, HandleRequest_BuildResponseFailed)
{
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
std::string const requestStr = R"json({"method":"some_method"})json";
std::string const requestStr = R"JSON({"method":"some_method"})JSON";
auto const request = makeHttpRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -357,7 +357,7 @@ TEST_F(NgRpcServerHandlerTest, HandleRequest_BuildResponseThrewAnException)
{
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
std::string const requestStr = R"json({"method":"some_method"})json";
std::string const requestStr = R"JSON({"method":"some_method"})JSON";
auto const request = makeHttpRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -383,7 +383,7 @@ TEST_F(NgRpcServerHandlerTest, HandleRequest_Successful_HttpRequest)
{
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
std::string const requestStr = R"json({"method":"some_method"})json";
std::string const requestStr = R"JSON({"method":"some_method"})JSON";
auto const request = makeHttpRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -416,7 +416,7 @@ TEST_F(NgRpcServerHandlerTest, HandleRequest_OutdatedWarning)
{
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
std::string const requestStr = R"json({"method":"some_method"})json";
std::string const requestStr = R"JSON({"method":"some_method"})JSON";
auto const request = makeHttpRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -455,7 +455,7 @@ TEST_F(NgRpcServerHandlerTest, HandleRequest_Successful_HttpRequest_Forwarded)
{
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
std::string const requestStr = R"json({"method":"some_method"})json";
std::string const requestStr = R"JSON({"method":"some_method"})JSON";
auto const request = makeHttpRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -491,7 +491,7 @@ TEST_F(NgRpcServerHandlerTest, HandleRequest_Successful_HttpRequest_HasError)
{
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
std::string const requestStr = R"json({"method":"some_method"})json";
std::string const requestStr = R"JSON({"method":"some_method"})JSON";
auto const request = makeHttpRequest(requestStr);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -543,7 +543,7 @@ TEST_F(NgRpcServerHandlerWsTest, HandleRequest_Successful_WsRequest)
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
Request::HttpHeaders const headers;
std::string const requestStr = R"json({"method":"some_method", "id": 1234, "api_version": 1})json";
std::string const requestStr = R"JSON({"method":"some_method", "id": 1234, "api_version": 1})JSON";
auto const request = Request(requestStr, headers);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));
@@ -578,7 +578,7 @@ TEST_F(NgRpcServerHandlerWsTest, HandleRequest_Successful_WsRequest_HasError)
backend_->setRange(0, 1);
runSpawn([&](boost::asio::yield_context yield) {
Request::HttpHeaders const headers;
std::string const requestStr = R"json({"method":"some_method", "id": 1234, "api_version": 1})json";
std::string const requestStr = R"JSON({"method":"some_method", "id": 1234, "api_version": 1})JSON";
auto const request = Request(requestStr, headers);
EXPECT_CALL(dosguard_, isOk(ip_)).WillOnce(Return(true));

View File

@@ -103,48 +103,48 @@ INSTANTIATE_TEST_CASE_P(
testing::Values(
MakeServerTestBundle{
"BadEndpoint",
R"json(
R"JSON(
{
"server": {"ip": "wrong", "port": 12345}
}
)json",
)JSON",
false
},
MakeServerTestBundle{
"BadSslConfig",
R"json(
R"JSON(
{
"server": {"ip": "127.0.0.1", "port": 12345},
"ssl_cert_file": "some_file"
}
)json",
)JSON",
false
},
MakeServerTestBundle{
"BadProcessingPolicy",
R"json(
R"JSON(
{
"server": {"ip": "127.0.0.1", "port": 12345, "processing_policy": "wrong"}
}
)json",
)JSON",
false
},
MakeServerTestBundle{
"CorrectConfig_ParallelPolicy",
R"json(
R"JSON(
{
"server": {"ip": "127.0.0.1", "port": 12345, "processing_policy": "parallel"}
}
)json",
)JSON",
true
},
MakeServerTestBundle{
"CorrectConfig_SequentPolicy",
R"json(
R"JSON(
{
"server": {"ip": "127.0.0.1", "port": 12345, "processing_policy": "sequent"}
}
)json",
)JSON",
true
}
),
@@ -358,7 +358,7 @@ TEST_F(ServerHttpTest, OnConnectCheckFailed)
auto const response = client.receive(yield, std::chrono::milliseconds{100});
[&]() { ASSERT_TRUE(response.has_value()) << response.error().message(); }();
EXPECT_EQ(response->result(), http::status::too_many_requests);
EXPECT_EQ(response->body(), R"json({"error":"some error"})json");
EXPECT_EQ(response->body(), R"JSON({"error":"some error"})JSON");
EXPECT_EQ(response->version(), 11);
client.gracefulShutdown();

View File

@@ -92,7 +92,7 @@ INSTANTIATE_TEST_CASE_P(
"WsRequest",
false,
rpc::Status{rpc::RippledError::rpcTOO_BUSY},
R"({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})",
R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON",
boost::beast::http::status::ok
},
NgErrorHandlingMakeErrorTestBundle{
@@ -134,7 +134,7 @@ INSTANTIATE_TEST_CASE_P(
"HttpRequest_RippledError",
true,
rpc::Status{rpc::RippledError::rpcTOO_BUSY},
R"({"result":{"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"}})",
R"JSON({"result":{"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"}})JSON",
boost::beast::http::status::bad_request
},
}),
@@ -198,7 +198,7 @@ INSTANTIATE_TEST_CASE_P(
NgErrorHandlingMakeInternalErrorTestBundle{
"Request_WebsocketConnection",
false,
std::string{R"({"id": 1, "api_version": 2})"},
std::string{R"JSON({"id": 1, "api_version": 2})JSON"},
{{"error", "internal"},
{"error_code", 73},
{"error_message", "Internal error."},
@@ -211,7 +211,7 @@ INSTANTIATE_TEST_CASE_P(
NgErrorHandlingMakeInternalErrorTestBundle{
"Request_WebsocketConnection_NoId",
false,
std::string{R"({"api_version": 2})"},
std::string{R"JSON({"api_version": 2})JSON"},
{{"error", "internal"},
{"error_code", 73},
{"error_message", "Internal error."},
@@ -223,7 +223,7 @@ INSTANTIATE_TEST_CASE_P(
NgErrorHandlingMakeInternalErrorTestBundle{
"Request_HttpConnection",
true,
std::string{R"({"id": 1, "api_version": 2})"},
std::string{R"JSON({"id": 1, "api_version": 2})JSON"},
{{"result",
{{"error", "internal"},
{"error_code", 73},
@@ -244,7 +244,7 @@ TEST_F(NgErrorHandlingTests, MakeNotReadyError)
EXPECT_EQ(
response.message(),
std::string{
R"({"result":{"error":"notReady","error_code":13,"error_message":"Not ready to handle this request.","status":"error","type":"response"}})"
R"JSON({"result":{"error":"notReady","error_code":13,"error_message":"Not ready to handle this request.","status":"error","type":"response"}})JSON"
}
);
auto const httpResponse = std::move(response).intoHttpResponse();
@@ -259,7 +259,7 @@ TEST_F(NgErrorHandlingTests, MakeTooBusyError_WebsocketRequest)
EXPECT_EQ(
response.message(),
std::string{
R"({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})"
R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON"
}
);
}
@@ -271,7 +271,7 @@ TEST_F(NgErrorHandlingTests, sendTooBusyError_HttpConnection)
EXPECT_EQ(
response.message(),
std::string{
R"({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})"
R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON"
}
);
auto const httpResponse = std::move(response).intoHttpResponse();
@@ -286,7 +286,7 @@ TEST_F(NgErrorHandlingTests, makeJsonParsingError_WebsocketConnection)
EXPECT_EQ(
response.message(),
std::string{
R"({"error":"badSyntax","error_code":1,"error_message":"Syntax error.","status":"error","type":"response"})"
R"JSON({"error":"badSyntax","error_code":1,"error_message":"Syntax error.","status":"error","type":"response"})JSON"
}
);
}
@@ -327,31 +327,31 @@ INSTANTIATE_TEST_CASE_P(
"NoRequest_WebsocketConnection",
false,
std::nullopt,
R"({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"})"
R"JSON({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"})JSON"
},
NgErrorHandlingComposeErrorTestBundle{
"NoRequest_HttpConnection",
true,
std::nullopt,
R"({"result":{"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"}})"
R"JSON({"result":{"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response"}})JSON"
},
NgErrorHandlingComposeErrorTestBundle{
"Request_WebsocketConnection",
false,
boost::json::object{{"id", 1}, {"api_version", 2}},
R"({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","id":1,"api_version":2,"request":{"id":1,"api_version":2}})",
R"JSON({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","id":1,"api_version":2,"request":{"id":1,"api_version":2}})JSON",
},
NgErrorHandlingComposeErrorTestBundle{
"Request_WebsocketConnection_NoId",
false,
boost::json::object{{"api_version", 2}},
R"({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","api_version":2,"request":{"api_version":2}})",
R"JSON({"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","api_version":2,"request":{"api_version":2}})JSON",
},
NgErrorHandlingComposeErrorTestBundle{
"Request_HttpConnection",
true,
boost::json::object{{"id", 1}, {"api_version", 2}},
R"({"result":{"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","id":1,"request":{"id":1,"api_version":2}}})"
R"JSON({"result":{"error":"internal","error_code":73,"error_message":"Internal error.","status":"error","type":"response","id":1,"request":{"id":1,"api_version":2}}})JSON"
}}
),
tests::util::kNAME_GENERATOR