mirror of
https://github.com/aler9/gortsplib
synced 2025-10-07 08:01:14 +08:00
add fuzz tests (#234)
This commit is contained in:
@@ -105,76 +105,6 @@ func TestResponseUnmarshal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseUnmarshalErrors(t *testing.T) {
|
||||
for _, ca := range []struct {
|
||||
name string
|
||||
byts []byte
|
||||
err string
|
||||
}{
|
||||
{
|
||||
"empty",
|
||||
[]byte{},
|
||||
"EOF",
|
||||
},
|
||||
{
|
||||
"missing code, message, eol",
|
||||
[]byte("RTSP/1.0"),
|
||||
"EOF",
|
||||
},
|
||||
{
|
||||
"missing message, eol",
|
||||
[]byte("RTSP/1.0 200"),
|
||||
"EOF",
|
||||
},
|
||||
{
|
||||
"missing eol",
|
||||
[]byte("RTSP/1.0 200 OK"),
|
||||
"EOF",
|
||||
},
|
||||
{
|
||||
"missing eol 2",
|
||||
[]byte("RTSP/1.0 200 OK\r"),
|
||||
"EOF",
|
||||
},
|
||||
{
|
||||
"invalid protocol",
|
||||
[]byte("RTSP/2.0 200 OK\r\n"),
|
||||
"expected 'RTSP/1.0', got [82 84 83 80 47 50 46 48]",
|
||||
},
|
||||
{
|
||||
"code too long",
|
||||
[]byte("RTSP/1.0 1234 OK\r\n"),
|
||||
"buffer length exceeds 4",
|
||||
},
|
||||
{
|
||||
"invalid code",
|
||||
[]byte("RTSP/1.0 str OK\r\n"),
|
||||
"unable to parse status code",
|
||||
},
|
||||
{
|
||||
"empty message",
|
||||
[]byte("RTSP/1.0 200 \r\n"),
|
||||
"empty status message",
|
||||
},
|
||||
{
|
||||
"invalid header",
|
||||
[]byte("RTSP/1.0 200 OK\r\nTesting: val\r"),
|
||||
"EOF",
|
||||
},
|
||||
{
|
||||
"invalid body",
|
||||
[]byte("RTSP/1.0 200 OK\r\nContent-Length: 17\r\n\r\n123"),
|
||||
"unexpected EOF",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var res Response
|
||||
err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(ca.byts)))
|
||||
require.EqualError(t, err, ca.err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseMarshal(t *testing.T) {
|
||||
for _, c := range casesResponse {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
@@ -224,3 +154,17 @@ func TestResponseString(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(byts), res.String())
|
||||
}
|
||||
|
||||
func FuzzResponseUnmarshal(f *testing.F) {
|
||||
f.Add([]byte("RTSP/1.0 "))
|
||||
|
||||
f.Add([]byte("RTSP/1.0 200 OK\r\n" +
|
||||
"Content-Length: 100\r\n" +
|
||||
"\r\n" +
|
||||
"testing"))
|
||||
|
||||
f.Fuzz(func(t *testing.T, b []byte) {
|
||||
var res Response
|
||||
res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user