mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 04:52:36 +02:00
Merge compat_jsonrpc_weirdversions
This commit is contained in:
commit
d50d30bf83
@ -218,18 +218,8 @@ void JSONRPCRequest::parse(const UniValue& valRequest)
|
|||||||
m_json_version = JSONRPCVersion::V1_LEGACY;
|
m_json_version = JSONRPCVersion::V1_LEGACY;
|
||||||
const UniValue& jsonrpc_version = request.find_value("jsonrpc");
|
const UniValue& jsonrpc_version = request.find_value("jsonrpc");
|
||||||
if (!jsonrpc_version.isNull()) {
|
if (!jsonrpc_version.isNull()) {
|
||||||
if (!jsonrpc_version.isStr()) {
|
if (jsonrpc_version.isStr() && jsonrpc_version.get_str() == "2.0") {
|
||||||
throw JSONRPCError(RPC_INVALID_REQUEST, "jsonrpc field must be a string");
|
|
||||||
}
|
|
||||||
// The "jsonrpc" key was added in the 2.0 spec, but some older documentation
|
|
||||||
// incorrectly included {"jsonrpc":"1.0"} in a request object, so we
|
|
||||||
// maintain that for backwards compatibility.
|
|
||||||
if (jsonrpc_version.get_str() == "1.0") {
|
|
||||||
m_json_version = JSONRPCVersion::V1_LEGACY;
|
|
||||||
} else if (jsonrpc_version.get_str() == "2.0") {
|
|
||||||
m_json_version = JSONRPCVersion::V2;
|
m_json_version = JSONRPCVersion::V2;
|
||||||
} else {
|
|
||||||
throw JSONRPCError(RPC_INVALID_REQUEST, "JSON-RPC version not supported");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,10 +172,13 @@ class RPCInterfaceTest(BitcoinTestFramework):
|
|||||||
self.log.info("Testing nonstandard jsonrpc 1.0 version number is accepted...")
|
self.log.info("Testing nonstandard jsonrpc 1.0 version number is accepted...")
|
||||||
self.test_batch_request(lambda idx: BatchOptions(request_fields={"jsonrpc": "1.0"}))
|
self.test_batch_request(lambda idx: BatchOptions(request_fields={"jsonrpc": "1.0"}))
|
||||||
|
|
||||||
self.log.info("Testing unrecognized jsonrpc version number is rejected...")
|
self.log.info("Testing nonstandard jsonrpc 1.0 version number is accepted as a Number...")
|
||||||
|
self.test_batch_request(lambda idx: BatchOptions(request_fields={"jsonrpc": 1.0}))
|
||||||
|
|
||||||
|
self.log.info("Testing unrecognized jsonrpc version number is accepted as if 1.0...")
|
||||||
self.test_batch_request(lambda idx: BatchOptions(
|
self.test_batch_request(lambda idx: BatchOptions(
|
||||||
request_fields={"jsonrpc": "2.1"},
|
request_fields={"jsonrpc": "2.1"},
|
||||||
response_fields={"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}}))
|
))
|
||||||
|
|
||||||
def test_http_status_codes(self):
|
def test_http_status_codes(self):
|
||||||
self.log.info("Testing HTTP status codes for JSON-RPC 1.1 requests...")
|
self.log.info("Testing HTTP status codes for JSON-RPC 1.1 requests...")
|
||||||
@ -201,11 +204,11 @@ class RPCInterfaceTest(BitcoinTestFramework):
|
|||||||
expect_http_rpc_status(200, RPC_INVALID_PARAMETER, self.nodes[0], "getblockhash", [42], 2, False)
|
expect_http_rpc_status(200, RPC_INVALID_PARAMETER, self.nodes[0], "getblockhash", [42], 2, False)
|
||||||
# force-send invalidly formatted requests
|
# force-send invalidly formatted requests
|
||||||
response, status = send_json_rpc(self.nodes[0], {"jsonrpc": 2, "method": "getblockcount"})
|
response, status = send_json_rpc(self.nodes[0], {"jsonrpc": 2, "method": "getblockcount"})
|
||||||
assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "jsonrpc field must be a string"}})
|
assert_equal(response, {"result": 0, "error": None})
|
||||||
assert_equal(status, 400)
|
assert_equal(status, 200)
|
||||||
response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "3.0", "method": "getblockcount"})
|
response, status = send_json_rpc(self.nodes[0], {"jsonrpc": "3.0", "method": "getblockcount"})
|
||||||
assert_equal(response, {"result": None, "error": {"code": RPC_INVALID_REQUEST, "message": "JSON-RPC version not supported"}})
|
assert_equal(response, {"result": 0, "error": None})
|
||||||
assert_equal(status, 400)
|
assert_equal(status, 200)
|
||||||
|
|
||||||
self.log.info("Testing HTTP status codes for JSON-RPC 2.0 notifications...")
|
self.log.info("Testing HTTP status codes for JSON-RPC 2.0 notifications...")
|
||||||
# Not notification: id exists
|
# Not notification: id exists
|
||||||
|
@ -192,7 +192,7 @@ class AuthServiceProxy():
|
|||||||
response = json.loads(responsedata, parse_float=decimal.Decimal)
|
response = json.loads(responsedata, parse_float=decimal.Decimal)
|
||||||
elapsed = time.time() - req_start_time
|
elapsed = time.time() - req_start_time
|
||||||
if "error" in response and response["error"] is None:
|
if "error" in response and response["error"] is None:
|
||||||
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
|
log.debug("<-%s- [%.6f] %s" % (response.get("id"), elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
|
||||||
else:
|
else:
|
||||||
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
|
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
|
||||||
return response, http_response.status
|
return response, http_response.status
|
||||||
|
Loading…
Reference in New Issue
Block a user