mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
chore: move cookie fuzz test to go 1.18 fuzzing (#1686)
This commit is contained in:
@@ -6,3 +6,4 @@ tags
|
||||
.vscode
|
||||
.DS_Store
|
||||
vendor/
|
||||
testdata/fuzz
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -15,6 +16,27 @@ func TestCookiePanic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzCookieParse(f *testing.F) {
|
||||
inputs := []string{
|
||||
`xxx=yyy`,
|
||||
`xxx=yyy; expires=Tue, 10 Nov 2009 23:00:00 GMT; domain=foobar.com; path=/a/b`,
|
||||
" \n\t\"",
|
||||
}
|
||||
for _, input := range inputs {
|
||||
f.Add([]byte(input))
|
||||
}
|
||||
c := AcquireCookie()
|
||||
defer ReleaseCookie(c)
|
||||
f.Fuzz(func(t *testing.T, cookie []byte) {
|
||||
_ = c.ParseBytes(cookie)
|
||||
|
||||
w := bytes.Buffer{}
|
||||
if _, err := c.WriteTo(&w); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCookieValueWithEqualAndSpaceChars(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
//go:build gofuzz
|
||||
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
c := fasthttp.AcquireCookie()
|
||||
defer fasthttp.ReleaseCookie(c)
|
||||
|
||||
if err := c.ParseBytes(data); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
w := bytes.Buffer{}
|
||||
if _, err := c.WriteTo(&w); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user