Skip to content

Commit

Permalink
improve error handling in account_info
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jul 12, 2024
1 parent f3bcc65 commit 1739568
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/test/rpc/AccountInfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,44 @@ class AccountInfo_test : public beast::unit_test::suite
BEAST_EXPECT(
info[jss::result][jss::error_message] == "Account malformed.");
}
{
// Cannot pass a non-string into the `account` param

auto testInvalidAccountParam = [&](auto const& param) {
Json::Value params;
params[jss::account] = param;
auto jrr = env.rpc(
"json", "account_info", to_string(params))[jss::result];
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
BEAST_EXPECT(jrr[jss::error_message] == "Invalid parameters.");
};

testInvalidAccountParam(1);
testInvalidAccountParam(1.1);
testInvalidAccountParam(true);
testInvalidAccountParam(Json::Value(Json::nullValue));
testInvalidAccountParam(Json::Value(Json::objectValue));
testInvalidAccountParam(Json::Value(Json::arrayValue));
}
{
// Cannot pass a non-string into the `account` param

auto testInvalidIdentParam = [&](auto const& param) {
Json::Value params;
params[jss::ident] = param;
auto jrr = env.rpc(
"json", "account_info", to_string(params))[jss::result];
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
BEAST_EXPECT(jrr[jss::error_message] == "Invalid parameters.");
};

testInvalidIdentParam(1);
testInvalidIdentParam(1.1);
testInvalidIdentParam(true);
testInvalidIdentParam(Json::Value(Json::nullValue));
testInvalidIdentParam(Json::Value(Json::objectValue));
testInvalidIdentParam(Json::Value(Json::arrayValue));
}
}

// Test the "signer_lists" argument in account_info.
Expand Down Expand Up @@ -652,7 +690,7 @@ class AccountInfo_test : public beast::unit_test::suite
}
};

BEAST_DEFINE_TESTSUITE(AccountInfo, app, ripple);
BEAST_DEFINE_TESTSUITE(AccountInfo, rpc, ripple);

} // namespace test
} // namespace ripple
9 changes: 9 additions & 0 deletions src/xrpld/rpc/handlers/AccountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <xrpl/json/json_value.h>
#include <xrpl/protocol/ErrorCodes.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/RPCErr.h>
#include <xrpl/protocol/UintTypes.h>
#include <xrpl/protocol/jss.h>
#include <grpc/status.h>
Expand Down Expand Up @@ -53,9 +54,17 @@ doAccountInfo(RPC::JsonContext& context)

std::string strIdent;
if (params.isMember(jss::account))
{
if (!params[jss::account].isString())
return rpcError(rpcINVALID_PARAMS);
strIdent = params[jss::account].asString();
}
else if (params.isMember(jss::ident))
{
if (!params[jss::ident].isString())
return rpcError(rpcINVALID_PARAMS);
strIdent = params[jss::ident].asString();
}
else
return RPC::missing_field_error(jss::account);

Expand Down

0 comments on commit 1739568

Please sign in to comment.