diff --git a/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp b/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp index ea17de29795..408432d35d7 100644 --- a/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp +++ b/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp @@ -159,6 +159,55 @@ namespace eosio { error_info error; }; + inline std::string_view make_trimmed_string_view(const std::string& body) { + if (body.empty()) { + return {}; + } + size_t left = 0; + size_t right = body.size() - 1; + + while(left < right) + { + if (body[left] == ' ') { + ++left; + } else { + break; + } + } + while(left < right) + { + if (body[right] == ' ') { + --right; + } else { + break; + } + } + if ((left == right) && (body[left] == ' ')) { + return {}; + } + return {body.substr(left, right-left+1)}; + } + + inline bool is_empty_content(const std::string& body) { + const auto trimmed_body_view = make_trimmed_string_view(body); + if (trimmed_body_view.empty()) { + return true; + } + const size_t body_size = trimmed_body_view.size(); + if ((body_size > 1) && (trimmed_body_view.at(0) == '{') && (trimmed_body_view.at(body_size - 1) == '}')) { + for(size_t idx=1; idx T parse_params(const std::string& body) { if constexpr (params_type == http_params_types::params_required) { - if (body.empty()) { + if (is_empty_content(body)) { EOS_THROW(chain::invalid_http_request, "A Request body is required"); } } @@ -176,7 +225,7 @@ namespace eosio { try { try { if constexpr (params_type == http_params_types::no_params_required || params_type == http_params_types::possible_no_params) { - if (body.empty()) { + if (is_empty_content(body)) { if constexpr (std::is_same_v) { return std::string("{}"); } diff --git a/tests/plugin_http_api_test.py b/tests/plugin_http_api_test.py index 286b96ca38d..1811f251995 100755 --- a/tests/plugin_http_api_test.py +++ b/tests/plugin_http_api_test.py @@ -20,6 +20,7 @@ class PluginHttpTest(unittest.TestCase): data_dir = Utils.getNodeDataDir(node_id) http_post_str = " -X POST -d " http_post_invalid_param = " '{invalid}' " + empty_content_str = " ' { } ' " # make a fresh data dir def createDataDir(self): @@ -66,6 +67,10 @@ def test_ChainApi(self) : default_cmd = cmd_base + "get_info" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertIn("server_version", ret_json) + # get_info with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("server_version", ret_json) # get_info with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -75,6 +80,10 @@ def test_ChainApi(self) : default_cmd = cmd_base + "get_activated_protocol_features" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(type(ret_json["activated_protocol_features"]), list) + # get_activated_protocol_features with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(type(ret_json["activated_protocol_features"]), list) # get_activated_protocol_features with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -114,6 +123,10 @@ def test_ChainApi(self) : default_cmd = cmd_base + "get_block" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) + # get_block with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) # get_block with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -127,6 +140,10 @@ def test_ChainApi(self) : default_cmd = cmd_base + "get_block_info" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) + # get_block_info with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) # get_block_info with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -141,6 +158,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_block_header_state with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_block_header_state with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -157,6 +179,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_account with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_account with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -172,6 +199,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_code with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_code with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -187,6 +219,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_code_hash with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_code_hash with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -202,6 +239,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_abi with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_abi with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -217,6 +259,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_raw_code_and_abi with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_raw_code_and_abi with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -232,6 +279,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_raw_abi with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_raw_abi with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -247,6 +299,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_table_rows with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_table_rows with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -271,6 +328,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_table_by_scope with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_table_by_scope with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -292,6 +354,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_currency_balance with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_currency_balance with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -307,6 +374,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_currency_stats with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_currency_stats with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -322,6 +394,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_producers with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_producers with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -336,6 +413,10 @@ def test_ChainApi(self) : default_cmd = cmd_base + "get_producer_schedule" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(type(ret_json["active"]), dict) + # get_producer_schedule with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(type(ret_json["active"]), dict) # get_producer_schedule with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -347,6 +428,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_scheduled_transactions with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_scheduled_transactions with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -362,6 +448,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # abi_json_to_bin with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # abi_json_to_bin with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -381,6 +472,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # abi_bin_to_json with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # abi_bin_to_json with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -400,6 +496,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_required_keys with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_required_keys with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -422,11 +523,16 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(valid_cmd) self.assertEqual(ret_json["code"], 500) - # get_transaction_id with empty p4arameter + # get_transaction_id with empty parameter default_cmd = cmd_base + "get_transaction_id" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_transaction_id with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_transaction_id with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -455,6 +561,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # push_block with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # push_block with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -470,6 +581,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # push_transaction with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # push_transaction with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -490,6 +606,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # push_transactions with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # push_transactions with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -510,6 +631,11 @@ def test_ChainApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # send_transaction with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # send_transaction with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -534,6 +660,11 @@ def test_HistoryApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_actions with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_actions with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -549,6 +680,11 @@ def test_HistoryApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_transaction with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_transaction with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -566,6 +702,11 @@ def test_HistoryApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_key_accounts with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_key_accounts with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -581,6 +722,11 @@ def test_HistoryApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_controlled_accounts with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_controlled_accounts with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -600,6 +746,11 @@ def test_NetApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # connect with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # connect with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -615,6 +766,11 @@ def test_NetApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # disconnect with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # disconnect with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -630,6 +786,11 @@ def test_NetApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # status with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # status with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -644,6 +805,10 @@ def test_NetApi(self) : default_cmd = cmd_base + "connections" ret_str = Utils.runCmdReturnStr(default_cmd) self.assertEqual(ret_str, "[]") + # connections with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_str = Utils.runCmdReturnStr(default_cmd) + self.assertEqual(ret_str, "[]") # connections with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -658,6 +823,10 @@ def test_ProducerApi(self) : default_cmd = cmd_base + "pause" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["result"], "ok") + # pause with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["result"], "ok") # pause with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -668,6 +837,10 @@ def test_ProducerApi(self) : default_cmd = cmd_base + "resume" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["result"], "ok") + # resume with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["result"], "ok") # resume with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -678,6 +851,10 @@ def test_ProducerApi(self) : default_cmd = cmd_base + "paused" ret_str = Utils.runCmdReturnStr(default_cmd) self.assertEqual(ret_str, "false") + # paused with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_str = Utils.runCmdReturnStr(default_cmd) + self.assertEqual(ret_str, "false") # paused with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -688,6 +865,10 @@ def test_ProducerApi(self) : default_cmd = cmd_base + "get_runtime_options" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertIn("max_transaction_time", ret_json) + # get_runtime_options with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("max_transaction_time", ret_json) # get_runtime_options with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -699,6 +880,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # update_runtime_options with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # update_runtime_options with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -721,6 +907,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # add_greylist_accounts with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # add_greylist_accounts with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -736,6 +927,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # remove_greylist_accounts with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # remove_greylist_accounts with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -750,6 +946,10 @@ def test_ProducerApi(self) : default_cmd = cmd_base + "get_greylist" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertIn("accounts", ret_json) + # get_greylist with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("accounts", ret_json) # get_greylist with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -765,6 +965,15 @@ def test_ProducerApi(self) : self.assertIn("contract_blacklist", ret_json) self.assertIn("action_blacklist", ret_json) self.assertIn("key_blacklist", ret_json) + # get_whitelist_blacklist with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("actor_whitelist", ret_json) + self.assertIn("actor_blacklist", ret_json) + self.assertIn("contract_whitelist", ret_json) + self.assertIn("contract_blacklist", ret_json) + self.assertIn("action_blacklist", ret_json) + self.assertIn("key_blacklist", ret_json) # get_whitelist_blacklist with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -776,6 +985,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # set_whitelist_blacklist with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # set_whitelist_blacklist with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -796,6 +1010,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertIn("head_block_id", ret_json) self.assertIn("integrity_hash", ret_json) + # get_integrity_hash with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("head_block_id", ret_json) + self.assertIn("integrity_hash", ret_json) # get_integrity_hash with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -807,6 +1026,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 500) self.assertEqual(ret_json["error"]["code"], 3170000) + # create_snapshot with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["error"]["code"], 3170000) # create_snapshot with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -822,6 +1046,10 @@ def test_ProducerApi(self) : default_cmd = cmd_base + "get_scheduled_protocol_feature_activations" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertIn("protocol_features_to_activate", ret_json) + # get_scheduled_protocol_feature_activations with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("protocol_features_to_activate", ret_json) # get_scheduled_protocol_feature_activations with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -833,6 +1061,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # schedule_protocol_feature_activations with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # schedule_protocol_feature_activations with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -848,6 +1081,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertIn("feature_digest", ret_json[0]) self.assertIn("subjective_restrictions", ret_json[0]) + # get_supported_protocol_features with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertIn("feature_digest", ret_json[0]) + self.assertIn("subjective_restrictions", ret_json[0]) # get_supported_protocol_features with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -874,6 +1112,11 @@ def test_ProducerApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_account_ram_corrections with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # get_account_ram_corrections with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -893,6 +1136,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # set_timeout with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # set_timeout with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -908,6 +1156,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # sign_transaction with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # sign_transaction with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -937,6 +1190,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # create with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # create with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -952,6 +1210,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # open with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # create with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -966,6 +1229,10 @@ def test_WalletApi(self) : default_cmd = cmd_base + "lock_all" ret_str = Utils.runCmdReturnStr(default_cmd) self.assertEqual("{}", ret_str) + # lock_all with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_str = Utils.runCmdReturnStr(default_cmd) + self.assertEqual("{}", ret_str) # lock_all with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -977,6 +1244,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # lock with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # lock with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -992,6 +1264,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # unlock with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # unlock with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1007,6 +1284,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # import_key with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # import_key with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1022,6 +1304,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # remove_key with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # remove_key with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1037,6 +1324,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # create_key with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # create_key with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1051,6 +1343,10 @@ def test_WalletApi(self) : default_cmd = cmd_base + "list_wallets" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(type(ret_json), list) + # list_wallets with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(type(ret_json), list) # list_wallets with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1062,6 +1358,11 @@ def test_WalletApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # list_keys with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # list_keys with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1076,6 +1377,10 @@ def test_WalletApi(self) : default_cmd = cmd_base + "get_public_keys" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(type(ret_json), dict) + # get_public_keys with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(type(ret_json), dict) # list_wallets with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1091,6 +1396,11 @@ def test_TestControlApi(self) : ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) self.assertEqual(ret_json["error"]["code"], 3200006) + # get_info with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + self.assertEqual(ret_json["error"]["code"], 3200006) # kill_node_on_producer with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) @@ -1109,6 +1419,10 @@ def test_TraceApi(self) : default_cmd = cmd_base + "get_block" ret_json = Utils.runCmdReturnJson(default_cmd) self.assertEqual(ret_json["code"], 400) + # get_info with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) # get_block with invalid parameter invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param ret_json = Utils.runCmdReturnJson(invalid_cmd) diff --git a/unittests/plugin_tests.cpp b/unittests/plugin_tests.cpp index baf16fb631f..0372ea4be04 100644 --- a/unittests/plugin_tests.cpp +++ b/unittests/plugin_tests.cpp @@ -26,6 +26,119 @@ auto call_parse_possible_no_params(const string& body) BOOST_AUTO_TEST_SUITE(plugin_tests) +BOOST_AUTO_TEST_CASE( make_trimmed_string_view ) try { + { // empty string + const std::string empty_str; + BOOST_REQUIRE(empty_str.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(empty_str).empty()); + } + { // all spacee string + for(size_t idx=0; idx<10; ++idx) { + const std::string space_str(idx, ' '); + BOOST_REQUIRE(space_str.size() == idx); + BOOST_REQUIRE(eosio::make_trimmed_string_view(space_str).empty()); + } + } + { // space on the head/tail only + const std::string one_char_no_space = "a"; + BOOST_REQUIRE(!one_char_no_space.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(one_char_no_space) == one_char_no_space); + + const std::string one_char_with_leading_space = " " + one_char_no_space; + BOOST_REQUIRE(!one_char_with_leading_space.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(one_char_with_leading_space) == one_char_no_space); + + const std::string one_char_with_trailing_space = one_char_no_space + " "; + BOOST_REQUIRE(!one_char_with_trailing_space.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(one_char_with_trailing_space) == one_char_no_space); + + const std::string one_char_with_space_both_side = " " + one_char_no_space + " "; + BOOST_REQUIRE(!one_char_with_space_both_side.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(one_char_with_space_both_side) == one_char_no_space); + } + { // space on the head/tail and body only + const std::string str_no_pace_both_side = "a b"; + BOOST_REQUIRE(!str_no_pace_both_side.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(str_no_pace_both_side) == str_no_pace_both_side); + + const std::string str_with_leading_space = " " + str_no_pace_both_side; + BOOST_REQUIRE(!str_with_leading_space.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(str_with_leading_space) == str_no_pace_both_side); + + const std::string str_with_with_trailing_space = str_no_pace_both_side + " "; + BOOST_REQUIRE(!str_with_with_trailing_space.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(str_with_with_trailing_space) == str_no_pace_both_side); + + const std::string str_with_with_space_both_side = " " + str_no_pace_both_side + " "; + BOOST_REQUIRE(!str_with_with_space_both_side.empty()); + BOOST_REQUIRE(eosio::make_trimmed_string_view(str_with_with_space_both_side) == str_no_pace_both_side); + } +} FC_LOG_AND_RETHROW() + +BOOST_AUTO_TEST_CASE( is_empty_content ) try { + { // empty string + const std::string empty_str; + BOOST_REQUIRE(empty_str.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_str) == true); + } + { // empty content string + const std::string empty_content_str_1 = "{}"; + BOOST_REQUIRE(!empty_content_str_1.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_1) == true); + const std::string empty_content_str_2 = "{ }"; + BOOST_REQUIRE(!empty_content_str_2.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_2) == true); + const std::string empty_content_str_3 = "{ \t}"; + BOOST_REQUIRE(!empty_content_str_3.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_3) == true); + const std::string empty_content_str_4 = " { }"; + BOOST_REQUIRE(!empty_content_str_4.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_4) == true); + const std::string empty_content_str_5 = "{ } "; + BOOST_REQUIRE(!empty_content_str_5.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_5) == true); + const std::string empty_content_str_6 = " { } "; + BOOST_REQUIRE(!empty_content_str_6.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_6) == true); + } + { // one char string + const std::string one_char_str_1 = "{"; + BOOST_REQUIRE(!one_char_str_1.empty()); + BOOST_REQUIRE(eosio::is_empty_content(one_char_str_1) == false) ; + const std::string one_char_str_2 = "}"; + BOOST_REQUIRE(!one_char_str_2.empty()); + BOOST_REQUIRE(eosio::is_empty_content(one_char_str_2) == false) ; + const std::string one_char_str_3 = " "; + BOOST_REQUIRE(!one_char_str_3.empty()); + BOOST_REQUIRE(eosio::is_empty_content(one_char_str_3) == true) ; + } + { // some content string + const std::string empty_content_str_1 = "{a}"; + BOOST_REQUIRE(!empty_content_str_1.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_1) == false); + const std::string empty_content_str_2 = "{\'\'}"; + BOOST_REQUIRE(!empty_content_str_2.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_2) == false); + const std::string empty_content_str_3 = "{\" \"}"; + BOOST_REQUIRE(!empty_content_str_3.empty()); + BOOST_REQUIRE(eosio::is_empty_content(empty_content_str_3) == false); + } + { // invalid string + const std::string invalid_str_1 = "{ a"; + BOOST_REQUIRE(!invalid_str_1.empty()); + BOOST_REQUIRE(eosio::is_empty_content(invalid_str_1) == false); + const std::string invalid_str_2 = " a }"; + BOOST_REQUIRE(! invalid_str_2.empty()); + BOOST_REQUIRE(eosio::is_empty_content(invalid_str_2) == false); + const std::string invalid_str_3 = " {a}"; + BOOST_REQUIRE(!invalid_str_3.empty()); + BOOST_REQUIRE(eosio::is_empty_content(invalid_str_3) == false); + const std::string invalid_str_4 = "{a} "; + BOOST_REQUIRE(!invalid_str_4.empty()); + BOOST_REQUIRE(eosio::is_empty_content(invalid_str_4 ) == false); + } +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_CASE( parse_params ) try { { // empty body, no input const std::string empty_str; @@ -77,6 +190,22 @@ BOOST_AUTO_TEST_CASE( parse_params ) try { BOOST_REQUIRE(ret == exp_result); ); } + // empty content + { + const std::string empty_content_str = " { \t } "; + BOOST_REQUIRE(!empty_content_str.empty()); + BOOST_REQUIRE_NO_THROW( + auto test_result = call_parse_possible_no_params(empty_content_str); + BOOST_REQUIRE(test_result == "{}"); + ); + BOOST_REQUIRE_NO_THROW( + auto test_result = call_parse_possible_no_params(empty_content_str); + BOOST_REQUIRE(test_result == "{}"); + ); + BOOST_REQUIRE_THROW( + call_parse_params_required(empty_content_str), chain::invalid_http_request + ); + } } FC_LOG_AND_RETHROW() BOOST_AUTO_TEST_SUITE_END()