aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar nickajacks1 <128185314+nickajacks1@users.noreply.github.com> 2024-01-04 06:04:50 -0800
committerGravatar GitHub <noreply@github.com> 2024-01-04 15:04:50 +0100
commitfec7681cdb74b0e825861d6449e60eba18aca01f (patch)
tree8f47b3caaddfdeda08c0e013f8ee2d467fcb7bb6
parentfeat: add function to parse HTTP header parameters (#1685) (diff)
downloadfasthttp-fec7681cdb74b0e825861d6449e60eba18aca01f.tar.gz
fasthttp-fec7681cdb74b0e825861d6449e60eba18aca01f.tar.bz2
fasthttp-fec7681cdb74b0e825861d6449e60eba18aca01f.zip
chore: move cookie fuzz test to go 1.18 fuzzing (#1686)
-rw-r--r--.gitignore1
-rw-r--r--cookie_test.go22
-rw-r--r--fuzzit/cookie/cookie_fuzz.go25
3 files changed, 23 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
index 035e302..7673684 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ tags
.vscode
.DS_Store
vendor/
+testdata/fuzz
diff --git a/cookie_test.go b/cookie_test.go
index b4b81ac..df9568c 100644
--- a/cookie_test.go
+++ b/cookie_test.go
@@ -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()
diff --git a/fuzzit/cookie/cookie_fuzz.go b/fuzzit/cookie/cookie_fuzz.go
deleted file mode 100644
index 929513f..0000000
--- a/fuzzit/cookie/cookie_fuzz.go
+++ /dev/null
@@ -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
-}