diff --git a/go.mod b/go.mod index 2c814b0be..ddc7dd87e 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,8 @@ module github.com/graph-gophers/graphql-go -require github.com/opentracing/opentracing-go v1.1.0 +require ( + github.com/opentracing/opentracing-go v1.1.0 + github.com/stretchr/testify v1.3.0 // indirect +) go 1.13 diff --git a/go.sum b/go.sum index 71fd021b0..d82fcd03a 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,9 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/graphql_test.go b/graphql_test.go index b2074275c..cb326644c 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "sync" "testing" "time" @@ -4297,3 +4298,28 @@ func TestInterfaceImplementingInterface(t *testing.T) { `, }}) } + +type query struct{} + +func (_ *query) Hello() string { return "Hello, world!" } +func (_ *query) Hi(string, string) string { return "Hello, world!" } +func (_ *query) LaunchMissil(string, string) string { return "Hello, world!" } + +func FuzzSchemaExec(f *testing.F) { + f.Fuzz(func(t *testing.T, s string, queryString , operationName string) { + defer func(){ + if err := recover(); err != nil{ + if !strings.Contains(err.(error).Error(), "invalid syntax"){ + panic(err) + } + } + }() + ctx := context.Background() + variables := map[string]interface{}{} + schema,err := graphql.ParseSchema(s, &query{}) + if err != nil { + t.Skip() + } + schema.Exec(ctx, queryString, operationName, variables) + }) +} diff --git a/internal/query/query_test.go b/internal/query/query_test.go new file mode 100644 index 000000000..62e3537df --- /dev/null +++ b/internal/query/query_test.go @@ -0,0 +1,12 @@ +package query + +import ( + "testing" +) + +func FuzzParseQuery(f *testing.F) { + f.Fuzz(func(t *testing.T, queryStr string) { + Parse(queryStr) + }) +} + diff --git a/internal/schema/schema_test.go b/internal/schema/schema_test.go index 065e9917a..e66798f38 100644 --- a/internal/schema/schema_test.go +++ b/internal/schema/schema_test.go @@ -1007,3 +1007,10 @@ func TestInterfaceImplementsInterface(t *testing.T) { }) } } + +func FuzzParse(f *testing.F){ + f.Fuzz(func(t *testing.T, schemaString string, useStringDescriptions bool){ + s := schema.New() + schema.Parse(s, schemaString, useStringDescriptions) + }) +}