diff --git a/fuzz/fuzz_targets/FuzzSource.go b/fuzz/fuzz_targets/FuzzSource.go new file mode 100644 index 0000000000..0e52a8e7e9 --- /dev/null +++ b/fuzz/fuzz_targets/FuzzSource.go @@ -0,0 +1,29 @@ +//go:build gofuzz +// +build gofuzz + +package fuzz + +import ( + "fmt" + "net/http" + + "github.com/zalando/skipper/predicates/source" +) + +func FuzzSource(data []byte) int { + p, err := source.New().Create([]interface{}{string(data)}) + + if err != nil { + return 0 + } + + if !p.Match(&http.Request{RemoteAddr: string(data)}) { + panic(fmt.Sprintf("Source predicate match failed: %x\n", data)) + } + + if !p.Match(&http.Request{RemoteAddr: string(data), Header: http.Header{"X-Forwarded-For": []string{string(data)}}}) { + panic(fmt.Sprintf("Source predicate with xff match failed: %x\n", data)) + } + + return 1 +} diff --git a/fuzz/fuzz_targets/FuzzSourceFromLast.go b/fuzz/fuzz_targets/FuzzSourceFromLast.go new file mode 100644 index 0000000000..cc57dae04b --- /dev/null +++ b/fuzz/fuzz_targets/FuzzSourceFromLast.go @@ -0,0 +1,29 @@ +//go:build gofuzz +// +build gofuzz + +package fuzz + +import ( + "fmt" + "net/http" + + "github.com/zalando/skipper/predicates/source" +) + +func FuzzSourceFromLast(data []byte) int { + p, err := source.NewFromLast().Create([]interface{}{string(data)}) + + if err != nil { + return 0 + } + + if !p.Match(&http.Request{RemoteAddr: string(data)}) { + panic(fmt.Sprintf("SourceFromLast predicate match failed: %x\n", data)) + } + + if !p.Match(&http.Request{RemoteAddr: string(data), Header: http.Header{"X-Forwarded-For": []string{string(data)}}}) { + panic(fmt.Sprintf("SourceFromLast predicate with xff match failed: %x\n", data)) + } + + return 1 +}