Skip to content

Commit

Permalink
add source and sourcefromlast fuzzers
Browse files Browse the repository at this point in the history
Signed-off-by: Sepehrdad Sh <[email protected]>
  • Loading branch information
sepehrdaddev committed Jan 12, 2024
1 parent d40d6fa commit 10723c2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions fuzz/fuzz_targets/FuzzSource.go
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions fuzz/fuzz_targets/FuzzSourceFromLast.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 10723c2

Please sign in to comment.