aboutsummaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-04-07 15:21:01 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-04-07 15:40:17 +0200
commit5078ca45438e8f8d8e7cd937659887fb8ec70038 (patch)
tree44f199b8d7c74f8d5097a80e7de09aff8ad2b719 /qa
parent5851915a006ace71493f54665322e41001fb3ac3 (diff)
downloadbitcoin-5078ca45438e8f8d8e7cd937659887fb8ec70038.tar.xz
tests: Check Content-Type header returned from RPC server
Check the Content-Type header that is returned from the RPC server. Only if it is `application/json` the data is supposed to be parsed as JSON. This gives better reporting if the HTTP server happens to return an error that is not JSON-formatted, which is the case if it happens at a lower level before JSON-RPC kicks in. Before: `Unexpected exception caught during testing: No JSON object could be decoded` After: `JSONRPC error: non-JSON HTTP response with '403 Forbidden' from server`
Diffstat (limited to 'qa')
-rw-r--r--qa/rpc-tests/test_framework/authproxy.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/qa/rpc-tests/test_framework/authproxy.py b/qa/rpc-tests/test_framework/authproxy.py
index 1eb2772592..e5f7ab3656 100644
--- a/qa/rpc-tests/test_framework/authproxy.py
+++ b/qa/rpc-tests/test_framework/authproxy.py
@@ -154,6 +154,11 @@ class AuthServiceProxy(object):
raise JSONRPCException({
'code': -342, 'message': 'missing HTTP response from server'})
+ content_type = http_response.getheader('Content-Type')
+ if content_type != 'application/json':
+ raise JSONRPCException({
+ 'code': -342, 'message': 'non-JSON HTTP response with \'%i %s\' from server' % (http_response.status, http_response.reason)})
+
responsedata = http_response.read().decode('utf8')
response = json.loads(responsedata, parse_float=decimal.Decimal)
if "error" in response and response["error"] is None: