mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 04:55:52 +00:00
fix: change error for invalid feature param in feature RPC (#5063)
* Returns an "Invalid parameters" error if the `feature` parameter is provided and is not a string.
This commit is contained in:
@@ -229,9 +229,28 @@ class Feature_test : public beast::unit_test::suite
|
|||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
Env env{*this};
|
Env env{*this};
|
||||||
|
|
||||||
|
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];
|
auto jrr = env.rpc("feature", "AllTheThings")[jss::result];
|
||||||
BEAST_EXPECT(jrr[jss::error] == "badFeature");
|
BEAST_EXPECT(jrr[jss::error] == "badFeature");
|
||||||
BEAST_EXPECT(jrr[jss::error_message] == "Feature unknown or invalid.");
|
BEAST_EXPECT(
|
||||||
|
jrr[jss::error_message] == "Feature unknown or invalid.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ doFeature(RPC::JsonContext& context)
|
|||||||
if (context.app.config().reporting())
|
if (context.app.config().reporting())
|
||||||
return rpcError(rpcREPORTING_UNSUPPORTED);
|
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;
|
bool const isAdmin = context.role == Role::ADMIN;
|
||||||
// Get majority amendment status
|
// Get majority amendment status
|
||||||
majorityAmendments_t majorities;
|
majorityAmendments_t majorities;
|
||||||
|
|||||||
Reference in New Issue
Block a user