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

Return 400 http error for unknown account #912

Merged
merged 4 commits into from
Apr 4, 2023
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
12 changes: 12 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,7 @@ void read_write::send_transaction2(const read_write::send_transaction2_params& p
}

read_only::get_abi_results read_only::get_abi( const get_abi_params& params, const fc::time_point& deadline )const {
try {
get_abi_results result;
result.account_name = params.account_name;
const auto& d = db.db();
Expand All @@ -2305,9 +2306,11 @@ read_only::get_abi_results read_only::get_abi( const get_abi_params& params, con
}

return result;
} EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account abi")
}

read_only::get_code_results read_only::get_code( const get_code_params& params, const fc::time_point& deadline )const {
try {
get_code_results result;
result.account_name = params.account_name;
const auto& d = db.db();
Expand All @@ -2327,9 +2330,11 @@ read_only::get_code_results read_only::get_code( const get_code_params& params,
}

return result;
} EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account code")
}

read_only::get_code_hash_results read_only::get_code_hash( const get_code_hash_params& params, const fc::time_point& deadline )const {
try {
get_code_hash_results result;
result.account_name = params.account_name;
const auto& d = db.db();
Expand All @@ -2339,9 +2344,11 @@ read_only::get_code_hash_results read_only::get_code_hash( const get_code_hash_p
result.code_hash = accnt.code_hash;

return result;
} EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account code hash")
}

read_only::get_raw_code_and_abi_results read_only::get_raw_code_and_abi( const get_raw_code_and_abi_params& params, const fc::time_point& deadline)const {
try {
get_raw_code_and_abi_results result;
result.account_name = params.account_name;

Expand All @@ -2355,9 +2362,11 @@ read_only::get_raw_code_and_abi_results read_only::get_raw_code_and_abi( const g
result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}};

return result;
} EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account code/abi")
}

read_only::get_raw_abi_results read_only::get_raw_abi( const get_raw_abi_params& params, const fc::time_point& deadline )const {
try {
get_raw_abi_results result;
result.account_name = params.account_name;

Expand All @@ -2371,9 +2380,11 @@ read_only::get_raw_abi_results read_only::get_raw_abi( const get_raw_abi_params&
result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}};

return result;
} EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account abi")
}

read_only::get_account_results read_only::get_account( const get_account_params& params, const fc::time_point& deadline )const {
try {
get_account_results result;
result.account_name = params.account_name;

Expand Down Expand Up @@ -2541,6 +2552,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}
return result;
} EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account info")
}

read_only::get_required_keys_result read_only::get_required_keys( const get_required_keys_params& params, const fc::time_point& deadline )const {
Expand Down
3 changes: 3 additions & 0 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ namespace eosio {
} catch (chain::invalid_http_request& e) {
error_results results{400, "Invalid Request", error_results::error_info(e, verbose_http_errors)};
cb( 400, fc::time_point::maximum(), fc::variant( results ));
} catch (chain::account_query_exception& e) {
error_results results{400, "Account lookup", error_results::error_info(e, verbose_http_errors)};
cb( 400, fc::time_point::maximum(), fc::variant( results ));
} catch (chain::unsatisfied_authorization& e) {
error_results results{401, "UnAuthorized", error_results::error_info(e, verbose_http_errors)};
cb( 401, fc::time_point::maximum(), fc::variant( results ));
Expand Down
18 changes: 9 additions & 9 deletions tests/plugin_http_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_ChainApi(self) :
# get_account with valid parameter
payload = {"account_name":"default"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_code with empty parameter
command = "get_code"
Expand All @@ -355,7 +355,7 @@ def test_ChainApi(self) :
# get_code with valid parameter
payload = {"account_name":"default"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_code_hash with empty parameter
command = "get_code_hash"
Expand All @@ -373,7 +373,7 @@ def test_ChainApi(self) :
# get_code_hash with valid parameter
payload = {"account_name":"default"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_abi with empty parameter
command = "get_abi"
Expand All @@ -391,7 +391,7 @@ def test_ChainApi(self) :
# get_abi with valid parameter
payload = {"account_name":"default"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_raw_code_and_abi with empty parameter
command = "get_raw_code_and_abi"
Expand All @@ -409,7 +409,7 @@ def test_ChainApi(self) :
# get_raw_code_and_abi with valid parameter
payload = {"account_name":"default"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_raw_abi with empty parameter
command = "get_raw_abi"
Expand All @@ -427,7 +427,7 @@ def test_ChainApi(self) :
# get_raw_abi with valid parameter
payload = {"account_name":"default"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_table_rows with empty parameter
command = "get_table_rows"
Expand All @@ -452,7 +452,7 @@ def test_ChainApi(self) :
"lower_bound":"0x0000000000000000D0F2A472A8EB6A57",
"upper_bound":"0xFFFFFFFFFFFFFFFFD0F2A472A8EB6A57"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_table_by_scope with empty parameter
command = "get_table_by_scope"
Expand Down Expand Up @@ -492,7 +492,7 @@ def test_ChainApi(self) :
# get_currency_balance with valid parameter
payload = {"code":"eosio.token", "account":"unknown"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_currency_stats with empty parameter
command = "get_currency_stats"
Expand All @@ -510,7 +510,7 @@ def test_ChainApi(self) :
# get_currency_stats with valid parameter
payload = {"code":"eosio.token","symbol":"SYS"}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload)
self.assertEqual(ret_json["code"], 500)
self.assertEqual(ret_json["code"], 400)

# get_producers with empty parameter
command = "get_producers"
Expand Down