feat: Add initial OSS-Fuzz testing integration

pull/18780/head
pierwill 2020-06-29 10:29:35 -07:00
parent 2825427cf5
commit 770f46b0a2
2 changed files with 49 additions and 0 deletions

25
FUZZ.md Normal file
View File

@ -0,0 +1,25 @@
# Fuzzing InfluxDB
## Continuous fuzzing
The InfluxDB repository contains testing targets for InfluxDB's integration with
[OSS-Fuzz](https://google.github.io/oss-fuzz/).
The build scripts for this integration are contained [in the OSS-Fuzz repo](https://github.com/google/oss-fuzz/tree/master/projects/influxdb).
## Local fuzzing
For local fuzzing, install [go-fuzz](https://github.com/dvyukov/go-fuzz):
```
$ go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
```
Below is an example of building and running a fuzz test.
In this case, the test is located at `./jsonweb/fuzz.go`.
```
$ cd go/src/github.com/influxdata/influxdb/jsonweb
$ go-fuzz-build github.com/influxdata/influxdb/v2/jsonweb
$ go-fuzz -bin jsonweb-fuzz.zip
```

24
jsonweb/fuzz.go Normal file
View File

@ -0,0 +1,24 @@
// +build gofuzz
package jsonweb
// FuzzJsonWeb is the entry point for fuzzing when built with go-fuzz-build.
func FuzzJsonWeb(data []byte) int {
var keyStore = KeyStoreFunc(func(kid string) ([]byte, error) {
if kid != "some-key" {
return nil, ErrKeyNotFound
}
return []byte("correct-key"), nil
})
parser := NewTokenParser(keyStore)
if _, err := parser.Parse(string(data)); err != nil {
// An error here means this input is not interesting
// to the fuzzer.
return 0
}
// The input valid, and the fuzzer should increase priority
// along these lines.
return 1
}