Merge #8638: rest.cpp: change HTTP_INTERNAL_SERVER_ERROR to HTTP_BAD_REQUEST

f012a85 rest.cpp: change HTTP_INTERNAL_SERVER_ERROR to HTTP_BAD_REQUEST (djpnewton)
This commit is contained in:
Wladimir J. van der Laan 2016-09-01 15:58:31 +02:00 committed by Alexander Block
parent 79d550d563
commit bc91f34da6
2 changed files with 12 additions and 12 deletions

View File

@ -179,14 +179,14 @@ class RESTTest (BitcoinTestFramework):
#do some invalid requests #do some invalid requests
json_request = '{"checkmempool' json_request = '{"checkmempool'
response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'json', json_request, True) response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'json', json_request, True)
assert_equal(response.status, 500) #must be a 500 because we send a invalid json request assert_equal(response.status, 400) #must be a 400 because we send a invalid json request
json_request = '{"checkmempool' json_request = '{"checkmempool'
response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', json_request, True) response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', json_request, True)
assert_equal(response.status, 500) #must be a 500 because we send a invalid bin request assert_equal(response.status, 400) #must be a 400 because we send a invalid bin request
response = http_post_call(url.hostname, url.port, '/rest/getutxos/checkmempool'+self.FORMAT_SEPARATOR+'bin', '', True) response = http_post_call(url.hostname, url.port, '/rest/getutxos/checkmempool'+self.FORMAT_SEPARATOR+'bin', '', True)
assert_equal(response.status, 500) #must be a 500 because we send a invalid bin request assert_equal(response.status, 400) #must be a 400 because we send a invalid bin request
#test limits #test limits
json_request = '/checkmempool/' json_request = '/checkmempool/'
@ -194,14 +194,14 @@ class RESTTest (BitcoinTestFramework):
json_request += txid+'-'+str(n)+'/' json_request += txid+'-'+str(n)+'/'
json_request = json_request.rstrip("/") json_request = json_request.rstrip("/")
response = http_post_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True) response = http_post_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True)
assert_equal(response.status, 500) #must be a 500 because we exceeding the limits assert_equal(response.status, 400) #must be a 400 because we exceeding the limits
json_request = '/checkmempool/' json_request = '/checkmempool/'
for x in range(0, 15): for x in range(0, 15):
json_request += txid+'-'+str(n)+'/' json_request += txid+'-'+str(n)+'/'
json_request = json_request.rstrip("/") json_request = json_request.rstrip("/")
response = http_post_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True) response = http_post_call(url.hostname, url.port, '/rest/getutxos'+json_request+self.FORMAT_SEPARATOR+'json', '', True)
assert_equal(response.status, 200) #must be a 500 because we exceeding the limits assert_equal(response.status, 200) #must be a 200 because we are within the limits
self.nodes[0].generate(1) #generate block to not affect upcoming tests self.nodes[0].generate(1) #generate block to not affect upcoming tests
self.sync_all() self.sync_all()

View File

@ -423,7 +423,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
// throw exception in case of a empty request // throw exception in case of a empty request
std::string strRequestMutable = req->ReadBody(); std::string strRequestMutable = req->ReadBody();
if (strRequestMutable.length() == 0 && uriParts.size() == 0) if (strRequestMutable.length() == 0 && uriParts.size() == 0)
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Error: empty request"); return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
bool fInputParsed = false; bool fInputParsed = false;
bool fCheckMemPool = false; bool fCheckMemPool = false;
@ -447,7 +447,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
std::string strOutput = uriParts[i].substr(uriParts[i].find("-")+1); std::string strOutput = uriParts[i].substr(uriParts[i].find("-")+1);
if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid)) if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Parse error"); return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
txid.SetHex(strTxid); txid.SetHex(strTxid);
vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput)); vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput));
@ -456,7 +456,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
if (vOutPoints.size() > 0) if (vOutPoints.size() > 0)
fInputParsed = true; fInputParsed = true;
else else
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Error: empty request"); return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
} }
switch (rf) { switch (rf) {
@ -472,7 +472,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
if (strRequestMutable.size() > 0) if (strRequestMutable.size() > 0)
{ {
if (fInputParsed) //don't allow sending input over URI and HTTP RAW DATA if (fInputParsed) //don't allow sending input over URI and HTTP RAW DATA
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Combination of URI scheme inputs and raw post data is not allowed"); return RESTERR(req, HTTP_BAD_REQUEST, "Combination of URI scheme inputs and raw post data is not allowed");
CDataStream oss(SER_NETWORK, PROTOCOL_VERSION); CDataStream oss(SER_NETWORK, PROTOCOL_VERSION);
oss << strRequestMutable; oss << strRequestMutable;
@ -481,14 +481,14 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
} }
} catch (const std::ios_base::failure& e) { } catch (const std::ios_base::failure& e) {
// abort in case of unreadable binary data // abort in case of unreadable binary data
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Parse error"); return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
} }
break; break;
} }
case RF_JSON: { case RF_JSON: {
if (!fInputParsed) if (!fInputParsed)
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Error: empty request"); return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
break; break;
} }
default: { default: {
@ -498,7 +498,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
// limit max outpoints // limit max outpoints
if (vOutPoints.size() > MAX_GETUTXOS_OUTPOINTS) if (vOutPoints.size() > MAX_GETUTXOS_OUTPOINTS)
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, strprintf("Error: max outpoints exceeded (max: %d, tried: %d)", MAX_GETUTXOS_OUTPOINTS, vOutPoints.size())); return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Error: max outpoints exceeded (max: %d, tried: %d)", MAX_GETUTXOS_OUTPOINTS, vOutPoints.size()));
// check spentness and form a bitmap (as well as a JSON capable human-readable string representation) // check spentness and form a bitmap (as well as a JSON capable human-readable string representation)
vector<unsigned char> bitmap; vector<unsigned char> bitmap;