From e2c29a670956d9893582b3b380eb3a9a09ef8581 Mon Sep 17 00:00:00 2001 From: nickajacks1 <128185314+nickajacks1@users.noreply.github.com> Date: Thu, 4 Jan 2024 06:04:50 -0800 Subject: [PATCH] chore: move cookie fuzz test to go 1.18 fuzzing (#1686) --- cookie_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cookie_test.go b/cookie_test.go index b4b81ac9ab..df9568c4d5 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()