add fuzz tests to all headers (#522)

This commit is contained in:
Alessandro Ros
2024-02-22 12:08:42 +01:00
committed by GitHub
parent 55fa72f0c2
commit c93d5c54d9
32 changed files with 177 additions and 326 deletions

View File

@@ -53,41 +53,6 @@ func TestSessionUnmarshal(t *testing.T) {
}
}
func TestSessionUnmarshalErrors(t *testing.T) {
for _, ca := range []struct {
name string
hv base.HeaderValue
err string
}{
{
"empty",
base.HeaderValue{},
"value not provided",
},
{
"2 values",
base.HeaderValue{"a", "b"},
"value provided multiple times ([a b])",
},
{
"invalid key-value",
base.HeaderValue{"A3eqwsafq3rFASqew;test=\"a"},
"apexes not closed (test=\"a)",
},
{
"invalid timeout",
base.HeaderValue{`A3eqwsafq3rFASqew;timeout=aaa`},
"strconv.ParseUint: parsing \"aaa\": invalid syntax",
},
} {
t.Run(ca.name, func(t *testing.T) {
var h Session
err := h.Unmarshal(ca.hv)
require.EqualError(t, err, ca.err)
})
}
}
func TestSessionMarshal(t *testing.T) {
for _, ca := range casesSession {
t.Run(ca.name, func(t *testing.T) {
@@ -96,3 +61,30 @@ func TestSessionMarshal(t *testing.T) {
})
}
}
func FuzzSessionUnmarshal(f *testing.F) {
for _, ca := range casesSession {
f.Add(ca.vin[0])
}
f.Add("timeout=")
f.Fuzz(func(t *testing.T, b string) {
var h Session
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
})
}
func TestSessionAdditionalErrors(t *testing.T) {
func() {
var h Session
err := h.Unmarshal(base.HeaderValue{})
require.Error(t, err)
}()
func() {
var h Session
err := h.Unmarshal(base.HeaderValue{"a", "b"})
require.Error(t, err)
}()
}