Skip to content

Commit

Permalink
add fuzzing for schema.Exec, schema and query parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
João Veiga committed Dec 13, 2021
1 parent 21d1871 commit f5cd8ab
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
26 changes: 26 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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)
})
}
12 changes: 12 additions & 0 deletions internal/query/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package query

import (
"testing"
)

func FuzzParseQuery(f *testing.F) {
f.Fuzz(func(t *testing.T, queryStr string) {
Parse(queryStr)
})
}

7 changes: 7 additions & 0 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit f5cd8ab

Please sign in to comment.