From 71095762c0a102a560f67370e27455450f8bca1b Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Thu, 11 Jul 2024 10:30:22 -0400 Subject: [PATCH] change error for invalid feature --- src/test/rpc/Feature_test.cpp | 25 ++++++++++++++++++++++--- src/xrpld/rpc/handlers/Feature1.cpp | 9 +++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/test/rpc/Feature_test.cpp b/src/test/rpc/Feature_test.cpp index 488255542f2..12d4b27745c 100644 --- a/src/test/rpc/Feature_test.cpp +++ b/src/test/rpc/Feature_test.cpp @@ -229,9 +229,28 @@ class Feature_test : public beast::unit_test::suite using namespace test::jtx; Env env{*this}; - auto jrr = env.rpc("feature", "AllTheThings")[jss::result]; - BEAST_EXPECT(jrr[jss::error] == "badFeature"); - BEAST_EXPECT(jrr[jss::error_message] == "Feature unknown or invalid."); + auto testInvalidParam = [&](auto const& param) { + Json::Value params; + params[jss::feature] = param; + auto jrr = + env.rpc("json", "feature", to_string(params))[jss::result]; + BEAST_EXPECT(jrr[jss::error] == "invalidParams"); + BEAST_EXPECT(jrr[jss::error_message] == "Invalid parameters."); + }; + + testInvalidParam(1); + testInvalidParam(1.1); + testInvalidParam(true); + testInvalidParam(Json::Value(Json::nullValue)); + testInvalidParam(Json::Value(Json::objectValue)); + testInvalidParam(Json::Value(Json::arrayValue)); + + { + auto jrr = env.rpc("feature", "AllTheThings")[jss::result]; + BEAST_EXPECT(jrr[jss::error] == "badFeature"); + BEAST_EXPECT( + jrr[jss::error_message] == "Feature unknown or invalid."); + } } void diff --git a/src/xrpld/rpc/handlers/Feature1.cpp b/src/xrpld/rpc/handlers/Feature1.cpp index d4499f120ef..c06756ca00a 100644 --- a/src/xrpld/rpc/handlers/Feature1.cpp +++ b/src/xrpld/rpc/handlers/Feature1.cpp @@ -38,6 +38,15 @@ doFeature(RPC::JsonContext& context) if (context.app.config().reporting()) return rpcError(rpcREPORTING_UNSUPPORTED); + if (context.params.isMember(jss::feature)) + { + // ensure that the `feature` param is a string + if (!context.params[jss::feature].isString()) + { + return rpcError(rpcINVALID_PARAMS); + } + } + bool const isAdmin = context.role == Role::ADMIN; // Get majority amendment status majorityAmendments_t majorities;