report not support (#682)

Fixes #678 #679
This commit is contained in:
cyan317
2023-06-09 16:14:19 +01:00
committed by GitHub
parent b873af2d43
commit 9d28e64383
2 changed files with 17 additions and 2 deletions

View File

@@ -202,16 +202,21 @@ CustomValidator IssuerValidator =
CustomValidator SubscribeStreamValidator =
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
static std::unordered_set<std::string> const validStreams = {
"ledger", "transactions", "transactions_proposed", "book_changes", "manifests", "validations"};
if (!value.is_array())
return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + "NotArray"}};
static std::unordered_set<std::string> const validStreams = {
"ledger", "transactions", "transactions_proposed", "book_changes", "manifests", "validations"};
static std::unordered_set<std::string> const reportingNotSupportStreams = {"peer_status", "consensus"};
for (auto const& v : value.as_array())
{
if (!v.is_string())
return Error{Status{RippledError::rpcINVALID_PARAMS, "streamNotString"}};
if (reportingNotSupportStreams.contains(v.as_string().c_str()))
return Error{Status{RippledError::rpcREPORTING_UNSUPPORTED}};
if (not validStreams.contains(v.as_string().c_str()))
return Error{Status{RippledError::rpcSTREAM_MALFORMED}};
}

View File

@@ -126,6 +126,16 @@ generateTestValuesForParametersTest()
SubscribeParamTestCaseBundle{"StreamsNotArray", R"({"streams": 1})", "invalidParams", "streamsNotArray"},
SubscribeParamTestCaseBundle{"StreamNotString", R"({"streams": [1]})", "invalidParams", "streamNotString"},
SubscribeParamTestCaseBundle{"StreamNotValid", R"({"streams": ["1"]})", "malformedStream", "Stream malformed."},
SubscribeParamTestCaseBundle{
"StreamPeerStatusNotSupport",
R"({"streams": ["peer_status"]})",
"reportingUnsupported",
"Requested operation not supported by reporting mode server"},
SubscribeParamTestCaseBundle{
"StreamConsensusNotSupport",
R"({"streams": ["consensus"]})",
"reportingUnsupported",
"Requested operation not supported by reporting mode server"},
SubscribeParamTestCaseBundle{"BooksNotArray", R"({"books": "1"})", "invalidParams", "booksNotArray"},
SubscribeParamTestCaseBundle{
"BooksItemNotObject", R"({"books": ["1"]})", "invalidParams", "booksItemNotObject"},