mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-16 16:17:38 +03:00
test: migrate remaining fuzzit tests to go 1.18 fuzzing (#1687)
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
//go:build gofuzz
|
||||
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
req := fasthttp.AcquireRequest()
|
||||
defer fasthttp.ReleaseRequest(req)
|
||||
|
||||
if err := req.ReadLimitBody(bufio.NewReader(bytes.NewReader(data)), 1024*1024); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
w := bytes.Buffer{}
|
||||
if _, err := req.WriteTo(&w); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
//go:build gofuzz
|
||||
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
res := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseResponse(res)
|
||||
|
||||
if err := res.ReadLimitBody(bufio.NewReader(bytes.NewReader(data)), 1024*1024); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
w := bytes.Buffer{}
|
||||
if _, err := res.WriteTo(&w); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build gofuzz
|
||||
|
||||
package fuzz
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
u := fasthttp.AcquireURI()
|
||||
defer fasthttp.ReleaseURI(u)
|
||||
|
||||
u.UpdateBytes(data)
|
||||
|
||||
w := bytes.Buffer{}
|
||||
if _, err := u.WriteTo(&w); err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -1700,6 +1700,32 @@ func testRequestReadLimitBodySuccess(t *testing.T, s string, maxBodySize int) {
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzResponseReadLimitBody(f *testing.F) {
|
||||
res := AcquireResponse()
|
||||
defer ReleaseResponse(res)
|
||||
|
||||
f.Add([]byte("HTTP/1.1 200 OK\r\nContent-Type: aa\r\nContent-Length: 10\r\n\r\n9876543210"), 1024*1024)
|
||||
|
||||
f.Fuzz(func(t *testing.T, body []byte, max int) {
|
||||
_ = res.ReadLimitBody(bufio.NewReader(bytes.NewReader(body)), max)
|
||||
w := bytes.Buffer{}
|
||||
_, _ = res.WriteTo(&w)
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzRequestReadLimitBody(f *testing.F) {
|
||||
req := AcquireRequest()
|
||||
defer ReleaseRequest(req)
|
||||
|
||||
f.Add([]byte("POST /a HTTP/1.1\r\nHost: a.com\r\nTransfer-Encoding: chunked\r\nContent-Type: aa\r\n\r\n6\r\nfoobar\r\n3\r\nbaz\r\n0\r\nfoobar\r\n\r\n"), 1024*1024)
|
||||
|
||||
f.Fuzz(func(t *testing.T, body []byte, max int) {
|
||||
_ = req.ReadLimitBody(bufio.NewReader(bytes.NewReader(body)), max)
|
||||
w := bytes.Buffer{}
|
||||
_, _ = req.WriteTo(&w)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRequestString(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
+19
@@ -9,6 +9,25 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func FuzzURIUpdateBytes(f *testing.F) {
|
||||
u := AcquireURI()
|
||||
defer ReleaseURI(u)
|
||||
|
||||
f.Add([]byte(`http://foobar.com/aaa/bb?cc`))
|
||||
f.Add([]byte(`//foobar.com/aaa/bb?cc`))
|
||||
f.Add([]byte(`/aaa/bb?cc`))
|
||||
f.Add([]byte(`xx?yy=abc`))
|
||||
|
||||
f.Fuzz(func(t *testing.T, uri []byte) {
|
||||
u.UpdateBytes(uri)
|
||||
|
||||
w := bytes.Buffer{}
|
||||
if _, err := u.WriteTo(&w); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestURICopyToQueryArgs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user