From 9ec3b79deadeab74813862520e2cfdf8d67e79f9 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 28 Mar 2023 07:42:45 -0500 Subject: [PATCH 1/3] GH-591 Return 400 http error for unknown account --- plugins/chain_plugin/chain_plugin.cpp | 12 ++++++++++++ plugins/http_plugin/http_plugin.cpp | 3 +++ tests/plugin_http_api_test.py | 18 +++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 86d877b413..14fb3204af 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -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(); @@ -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(); @@ -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(); @@ -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 has") } 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; @@ -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; @@ -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; @@ -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 { diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index 12850020e3..12950454dd 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -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 )); diff --git a/tests/plugin_http_api_test.py b/tests/plugin_http_api_test.py index 973abea228..05ea681d4a 100755 --- a/tests/plugin_http_api_test.py +++ b/tests/plugin_http_api_test.py @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" From ce8c1b70d549e5ab6242a3f7201628af197f01aa Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 28 Mar 2023 10:01:38 -0500 Subject: [PATCH 2/3] GH-591 fix expected http code --- tests/read_only_trx_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/read_only_trx_test.py b/tests/read_only_trx_test.py index 495284c009..6dd75f10fe 100755 --- a/tests/read_only_trx_test.py +++ b/tests/read_only_trx_test.py @@ -259,7 +259,7 @@ def chainApiTests(): runReadOnlyTrxAndRpcInParallel("chain", "get_raw_code_and_abi", "account_name", expectedValue=testAccountName, payload = {"account_name":testAccountName}) runReadOnlyTrxAndRpcInParallel("chain", "get_raw_abi", "account_name", expectedValue=testAccountName, payload = {"account_name":testAccountName}) runReadOnlyTrxAndRpcInParallel("chain", "get_producers", "rows", payload = {"json":"true","lower_bound":""}) - runReadOnlyTrxAndRpcInParallel("chain", "get_table_rows", code=500, payload = {"json":"true","table":"noauth"}) + runReadOnlyTrxAndRpcInParallel("chain", "get_table_rows", code=400, payload = {"json":"true","table":"noauth"}) runReadOnlyTrxAndRpcInParallel("chain", "get_table_by_scope", fieldIn="rows", payload = {"json":"true","table":"noauth"}) runReadOnlyTrxAndRpcInParallel("chain", "get_currency_balance", code=200, payload = {"code":"eosio.token", "account":testAccountName}) runReadOnlyTrxAndRpcInParallel("chain", "get_currency_stats", fieldIn="SYS", payload = {"code":"eosio.token", "symbol":"SYS"}) From 1043b9c054f3262c0ab8bf8411c73e6cd71055ce Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 31 Mar 2023 07:25:34 -0500 Subject: [PATCH 3/3] GH-591 Fix spelling --- plugins/chain_plugin/chain_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 14fb3204af..26716786f2 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2344,7 +2344,7 @@ 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 has") + } 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 {