mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-03 06:37:14 +00:00
test/fuzz: fix rpc, secret_connection and pex tests (#6190)
* test/fuzz: fix rpc, secret_connection and pex tests - ignore empty data in rpc - provide correct IP in pex - spawn a goroutine for Write and do multiple Read(s) * test/fuzz: fix init in pex test * test/fuzz: assign NewServeMux to global var * test/fuzz: only try to Unmarshal if blob is not empty * run fuzz tests for PRs which modify fuzz tests themselves * test/fuzz: move MakeSwitch into init
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
rs "github.com/tendermint/tendermint/rpc/jsonrpc/server"
|
||||
@@ -18,13 +19,16 @@ var rpcFuncMap = map[string]*rs.RPCFunc{
|
||||
var mux *http.ServeMux
|
||||
|
||||
func init() {
|
||||
mux := http.NewServeMux()
|
||||
buf := new(bytes.Buffer)
|
||||
lgr := log.NewTMLogger(buf)
|
||||
mux = http.NewServeMux()
|
||||
lgr := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||
rs.RegisterRPCFuncs(mux, rpcFuncMap, lgr)
|
||||
}
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
if len(data) == 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("POST", "http://localhost/", bytes.NewReader(data))
|
||||
rec := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rec, req)
|
||||
@@ -36,9 +40,11 @@ func Fuzz(data []byte) int {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
recv := new(types.RPCResponse)
|
||||
if err := json.Unmarshal(blob, recv); err != nil {
|
||||
panic(err)
|
||||
if len(blob) > 0 {
|
||||
recv := new(types.RPCResponse)
|
||||
if err := json.Unmarshal(blob, recv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user