Add fuzz testing to 'serv' for the GQL hash parser
This commit is contained in:
21
serv/corpus/001.gql
Normal file
21
serv/corpus/001.gql
Normal file
@ -0,0 +1,21 @@
|
||||
query {
|
||||
products(
|
||||
# returns only 30 items
|
||||
limit: 30,
|
||||
|
||||
# starts from item 10, commented out for now
|
||||
# offset: 10,
|
||||
|
||||
# orders the response items by highest price
|
||||
order_by: { price: desc },
|
||||
|
||||
# no duplicate prices returned
|
||||
distinct: [ price ]
|
||||
|
||||
# only items with an id >= 30 and < 30 are returned
|
||||
where: { id: { and: { greater_or_equals: 20, lt: 28 } } }) {
|
||||
id
|
||||
name
|
||||
price
|
||||
}
|
||||
}
|
9
serv/fuzz.go
Normal file
9
serv/fuzz.go
Normal file
@ -0,0 +1,9 @@
|
||||
package serv
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
gql := string(data)
|
||||
isMutation(gql)
|
||||
gqlHash(gql, nil, "")
|
||||
|
||||
return 1
|
||||
}
|
16
serv/fuzz_test.go
Normal file
16
serv/fuzz_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package serv
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFuzzCrashers(t *testing.T) {
|
||||
var crashers = []string{
|
||||
"query",
|
||||
"q",
|
||||
"que",
|
||||
}
|
||||
|
||||
for _, f := range crashers {
|
||||
isMutation(f)
|
||||
gqlHash(f, nil, "")
|
||||
}
|
||||
}
|
@ -32,6 +32,10 @@ func gqlHash(b string, vars []byte, role string) string {
|
||||
|
||||
var b0, b1 byte
|
||||
|
||||
if len(b) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
for {
|
||||
if starting && b[e] == 'q' {
|
||||
n := 0
|
||||
@ -44,6 +48,9 @@ func gqlHash(b string, vars []byte, role string) string {
|
||||
io.WriteString(h, strings.ToLower(b[se:e]))
|
||||
}
|
||||
}
|
||||
if e >= len(b) {
|
||||
break
|
||||
}
|
||||
if ws(b[e]) {
|
||||
for e < len(b) && ws(b[e]) {
|
||||
e++
|
||||
|
Reference in New Issue
Block a user