rpc/lib/server: add handlers tests

Follow up of PR https://github.com/tendermint/tendermint/pull/724
For https://github.com/tendermint/tendermint/issues/708

Reported initially in #708, this bug was reconfirmed
by the fuzzer.

This fix ensures that:
* if the user doesn't pass in `"id"` that we send them back
a message in an error telling them to send `"id"`. Previously
we let the handler return a 200 with nothing.
* passing in nil `params` doesn't crash
* not passing in `params` doesn't crash
* passing in non-JSON parseable data to `params` doesn't crash
This commit is contained in:
Emmanuel Odeke
2017-10-14 19:58:47 -06:00
parent 128e2a1d9e
commit 59556ab030
2 changed files with 83 additions and 0 deletions

View File

@ -118,6 +118,8 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
// The Server MUST NOT reply to a Notification, including those that are within a batch request.
if request.ID == "" {
logger.Debug("HTTPJSONRPC received a notification, skipping... (please send a non-empty ID if you want to call a method)")
// Not sending back a response here because according the JSONRPC
// specification Section 4.1, we SHOULD NOT one back when "id" == "".
return
}
if len(r.URL.Path) > 1 {