From 9d28e643833eb3422a28394dc51b6896fae63d73 Mon Sep 17 00:00:00 2001 From: cyan317 <120398799+cindyyan317@users.noreply.github.com> Date: Fri, 9 Jun 2023 16:14:19 +0100 Subject: [PATCH] report not support (#682) Fixes #678 #679 --- src/rpc/common/Validators.cpp | 9 +++++++-- unittests/rpc/handlers/SubscribeTest.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rpc/common/Validators.cpp b/src/rpc/common/Validators.cpp index 52c43ce2..4d5c51bc 100644 --- a/src/rpc/common/Validators.cpp +++ b/src/rpc/common/Validators.cpp @@ -202,16 +202,21 @@ CustomValidator IssuerValidator = CustomValidator SubscribeStreamValidator = CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError { - static std::unordered_set 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 const validStreams = { + "ledger", "transactions", "transactions_proposed", "book_changes", "manifests", "validations"}; + + static std::unordered_set 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}}; } diff --git a/unittests/rpc/handlers/SubscribeTest.cpp b/unittests/rpc/handlers/SubscribeTest.cpp index a37ce63c..b8a91f31 100644 --- a/unittests/rpc/handlers/SubscribeTest.cpp +++ b/unittests/rpc/handlers/SubscribeTest.cpp @@ -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"},