Skip to content

Commit

Permalink
test: migrate remaining fuzzit tests to go 1.18 fuzzing (valyala#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickajacks1 authored and Max-Cheng committed Feb 12, 2024
1 parent c7f3f2b commit 5305047
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 75 deletions.
26 changes: 0 additions & 26 deletions fuzzit/request/request_fuzz.go

This file was deleted.

26 changes: 0 additions & 26 deletions fuzzit/response/response_fuzz.go

This file was deleted.

23 changes: 0 additions & 23 deletions fuzzit/url/url_fuzz.go

This file was deleted.

26 changes: 26 additions & 0 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
19 changes: 19 additions & 0 deletions uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 5305047

Please sign in to comment.