-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add source and sourcefromlast fuzzers
Signed-off-by: Sepehrdad Sh <[email protected]>
- Loading branch information
1 parent
d40d6fa
commit 10723c2
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |