Skip to content

Commit f5cd8ab

Browse files
author
João Veiga
committed
add fuzzing for schema.Exec, schema and query parsing
1 parent 21d1871 commit f5cd8ab

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module github.com/graph-gophers/graphql-go
22

3-
require github.com/opentracing/opentracing-go v1.1.0
3+
require (
4+
github.com/opentracing/opentracing-go v1.1.0
5+
github.com/stretchr/testify v1.3.0 // indirect
6+
)
47

58
go 1.13

go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
24
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
9+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

graphql_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78
"sync"
89
"testing"
910
"time"
@@ -4297,3 +4298,28 @@ func TestInterfaceImplementingInterface(t *testing.T) {
42974298
`,
42984299
}})
42994300
}
4301+
4302+
type query struct{}
4303+
4304+
func (_ *query) Hello() string { return "Hello, world!" }
4305+
func (_ *query) Hi(string, string) string { return "Hello, world!" }
4306+
func (_ *query) LaunchMissil(string, string) string { return "Hello, world!" }
4307+
4308+
func FuzzSchemaExec(f *testing.F) {
4309+
f.Fuzz(func(t *testing.T, s string, queryString , operationName string) {
4310+
defer func(){
4311+
if err := recover(); err != nil{
4312+
if !strings.Contains(err.(error).Error(), "invalid syntax"){
4313+
panic(err)
4314+
}
4315+
}
4316+
}()
4317+
ctx := context.Background()
4318+
variables := map[string]interface{}{}
4319+
schema,err := graphql.ParseSchema(s, &query{})
4320+
if err != nil {
4321+
t.Skip()
4322+
}
4323+
schema.Exec(ctx, queryString, operationName, variables)
4324+
})
4325+
}

internal/query/query_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package query
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func FuzzParseQuery(f *testing.F) {
8+
f.Fuzz(func(t *testing.T, queryStr string) {
9+
Parse(queryStr)
10+
})
11+
}
12+

internal/schema/schema_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,10 @@ func TestInterfaceImplementsInterface(t *testing.T) {
10071007
})
10081008
}
10091009
}
1010+
1011+
func FuzzParse(f *testing.F){
1012+
f.Fuzz(func(t *testing.T, schemaString string, useStringDescriptions bool){
1013+
s := schema.New()
1014+
schema.Parse(s, schemaString, useStringDescriptions)
1015+
})
1016+
}

0 commit comments

Comments
 (0)