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

Force json commands to be objects #2319

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 13 additions & 13 deletions src/ripple/net/impl/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class RPCParser
if (reader.parse (jvParams[2u].asString (), txJSON))
{
// sign_for txJSON.
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::account] = jvParams[0u].asString ();
jvRequest[jss::secret] = jvParams[1u].asString ();
Expand Down Expand Up @@ -802,7 +802,7 @@ class RPCParser
Json::Value parseRipplePathFind (Json::Value const& jvParams)
{
Json::Reader reader;
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};
bool bLedger = 2 == jvParams.size ();

JLOG (j_.trace()) << "RPC json: " << jvParams[0u];
Expand Down Expand Up @@ -835,7 +835,7 @@ class RPCParser
{
// Submitting tx_blob

Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::tx_blob] = jvParams[0u].asString ();

Expand All @@ -845,7 +845,7 @@ class RPCParser
&& reader.parse (jvParams[1u].asString (), txJSON))
{
// Signing or submitting tx_json.
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::secret] = jvParams[0u].asString ();
jvRequest[jss::tx_json] = txJSON;
Expand All @@ -870,7 +870,7 @@ class RPCParser
Json::Reader reader;
if (reader.parse (jvParams[0u].asString (), txJSON))
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};
jvRequest[jss::tx_json] = txJSON;
return jvRequest;
}
Expand All @@ -889,7 +889,7 @@ class RPCParser
if (txHash.length() != 64)
return rpcError (rpcINVALID_PARAMS);

Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};
jvRequest[jss::tx_hash] = txHash;

jvParseLedger (jvRequest, jvParams[1u].asString());
Expand All @@ -907,7 +907,7 @@ class RPCParser
// tx <transaction_id>
Json::Value parseTx (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size () > 1)
{
Expand All @@ -922,7 +922,7 @@ class RPCParser
// tx_history <index>
Json::Value parseTxHistory (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

jvRequest[jss::start] = jvParams[0u].asUInt ();

Expand All @@ -935,7 +935,7 @@ class RPCParser
// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps).
Json::Value parseValidationCreate (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::secret] = jvParams[0u].asString ();
Expand All @@ -949,7 +949,7 @@ class RPCParser
// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps).
Json::Value parseValidationSeed (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::secret] = jvParams[0u].asString ();
Expand All @@ -961,7 +961,7 @@ class RPCParser
// <passphrase> is only for testing. Master seeds should only be generated randomly.
Json::Value parseWalletPropose (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::passphrase] = jvParams[0u].asString ();
Expand All @@ -972,7 +972,7 @@ class RPCParser
// wallet_seed [<seed>|<passphrase>|<passkey>]
Json::Value parseWalletSeed (Json::Value const& jvParams)
{
Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

if (jvParams.size ())
jvRequest[jss::secret] = jvParams[0u].asString ();
Expand All @@ -988,7 +988,7 @@ class RPCParser
unsigned int index = 0;
const unsigned int size = jvParams.size ();

Json::Value jvRequest;
Json::Value jvRequest{Json::objectValue};

std::string param = jvParams[index++].asString ();
if (param.empty ())
Expand Down
15 changes: 15 additions & 0 deletions src/test/rpc/ValidatorRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,27 @@ class ValidatorRPC_test : public beast::unit_test::suite
}
}

void
test_validation_create()
{
using namespace test::jtx;
Env env{*this};
auto result = env.rpc("validation_create");
BEAST_EXPECT(result.isMember(jss::result) &&
result[jss::result][jss::status] == "success");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be in favor of getting more coverage with an additional test with the optional seed parameter (which @ximinez may have originally suggested) even though that case worked before and after this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add that test.

result = env.rpc("validation_create",
"BAWL MAN JADE MOON DOVE GEM SON NOW HAD ADEN GLOW TIRE");
BEAST_EXPECT(result.isMember(jss::result) &&
result[jss::result][jss::status] == "success");
}

void
run()
{
testPrivileges();
testStaticUNL();
testDynamicUNL();
test_validation_create();
}
};

Expand Down