Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change error for invalid feature param in feature RPC #5063

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/test/rpc/Feature_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/xrpld/rpc/handlers/Feature1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading