mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
improve coverage
This commit is contained in:
@@ -138,6 +138,16 @@ func TestHeaderReadErrors(t *testing.T) {
|
|||||||
[]byte{},
|
[]byte{},
|
||||||
"EOF",
|
"EOF",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"missing value",
|
||||||
|
[]byte("Testing:"),
|
||||||
|
"EOF",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"missing eol",
|
||||||
|
[]byte("Testing: val"),
|
||||||
|
"EOF",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"r without n",
|
"r without n",
|
||||||
[]byte("Testing: val\rTesting: val\r\n"),
|
[]byte("Testing: val\rTesting: val\r\n"),
|
||||||
|
@@ -222,6 +222,16 @@ func TestRequestReadErrors(t *testing.T) {
|
|||||||
[]byte("GET rtsp://testing123 RTSP/1.0\r\nContent-Length: 17\r\n\r\n123"),
|
[]byte("GET rtsp://testing123 RTSP/1.0\r\nContent-Length: 17\r\n\r\n123"),
|
||||||
"unexpected EOF",
|
"unexpected EOF",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid content-length",
|
||||||
|
[]byte("GET rtsp://testing123 RTSP/1.0\r\nContent-Length: aaa\r\n\r\n123"),
|
||||||
|
"invalid Content-Length",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"too big content-length",
|
||||||
|
[]byte("GET rtsp://testing123 RTSP/1.0\r\nContent-Length: 1000000\r\n\r\n123"),
|
||||||
|
"Content-Length exceeds 131072 (it's 1000000)",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
var req Request
|
var req Request
|
||||||
@@ -245,3 +255,13 @@ func TestRequestReadIgnoreFrames(t *testing.T) {
|
|||||||
err := req.ReadIgnoreFrames(rb, buf)
|
err := req.ReadIgnoreFrames(rb, buf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRequestReadIgnoreFramesError(t *testing.T) {
|
||||||
|
byts := []byte{0x25}
|
||||||
|
|
||||||
|
rb := bufio.NewReader(bytes.NewBuffer(byts))
|
||||||
|
buf := make([]byte, 10)
|
||||||
|
var req Request
|
||||||
|
err := req.ReadIgnoreFrames(rb, buf)
|
||||||
|
require.Equal(t, "EOF", err.Error())
|
||||||
|
}
|
||||||
|
@@ -179,6 +179,16 @@ func TestResponseReadErrors(t *testing.T) {
|
|||||||
[]byte("RTSP/1.0 200 OK\r\nContent-Length: 17\r\n\r\n123"),
|
[]byte("RTSP/1.0 200 OK\r\nContent-Length: 17\r\n\r\n123"),
|
||||||
"unexpected EOF",
|
"unexpected EOF",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid content-length",
|
||||||
|
[]byte("RTSP/1.0 200 OK\r\nContent-Length: aaa\r\n\r\n123"),
|
||||||
|
"invalid Content-Length",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"too big content-length",
|
||||||
|
[]byte("RTSP/1.0 200 OK\r\nContent-Length: 1000000\r\n\r\n123"),
|
||||||
|
"Content-Length exceeds 131072 (it's 1000000)",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
var res Response
|
var res Response
|
||||||
@@ -230,3 +240,13 @@ func TestResponseReadIgnoreFrames(t *testing.T) {
|
|||||||
err := res.ReadIgnoreFrames(rb, buf)
|
err := res.ReadIgnoreFrames(rb, buf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResponseReadIgnoreFramesError(t *testing.T) {
|
||||||
|
byts := []byte{0x25}
|
||||||
|
|
||||||
|
rb := bufio.NewReader(bytes.NewBuffer(byts))
|
||||||
|
buf := make([]byte, 10)
|
||||||
|
var res Response
|
||||||
|
err := res.ReadIgnoreFrames(rb, buf)
|
||||||
|
require.Equal(t, "EOF", err.Error())
|
||||||
|
}
|
||||||
|
@@ -85,6 +85,26 @@ func TestAuthorizationReadError(t *testing.T) {
|
|||||||
base.HeaderValue{"a", "b"},
|
base.HeaderValue{"a", "b"},
|
||||||
"value provided multiple times ([a b])",
|
"value provided multiple times ([a b])",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid",
|
||||||
|
base.HeaderValue{`Invalid`},
|
||||||
|
"invalid authorization header",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"basic invalid 1",
|
||||||
|
base.HeaderValue{`Basic aaa`},
|
||||||
|
"invalid value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"basic invalid 2",
|
||||||
|
base.HeaderValue{`Basic aW52YWxpZA==`},
|
||||||
|
"invalid value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"digest invalid",
|
||||||
|
base.HeaderValue{`Basic`},
|
||||||
|
"invalid authorization header",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
var h Authorization
|
var h Authorization
|
||||||
|
@@ -46,17 +46,13 @@ func (h *Session) Read(v base.HeaderValue) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range kvs {
|
for k, v := range kvs {
|
||||||
switch k {
|
if k == "timeout" {
|
||||||
case "timeout":
|
|
||||||
iv, err := strconv.ParseUint(v, 10, 64)
|
iv, err := strconv.ParseUint(v, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
uiv := uint(iv)
|
uiv := uint(iv)
|
||||||
h.Timeout = &uiv
|
h.Timeout = &uiv
|
||||||
|
|
||||||
default:
|
|
||||||
// ignore non-standard keys
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,6 +84,16 @@ func TestSessionReadError(t *testing.T) {
|
|||||||
base.HeaderValue{"a", "b"},
|
base.HeaderValue{"a", "b"},
|
||||||
"value provided multiple times ([a b])",
|
"value provided multiple times ([a b])",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"no keys",
|
||||||
|
base.HeaderValue{`A3eqwsafq3rFASqew;aaaa`},
|
||||||
|
"unable to read key (aaaa)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid timeout",
|
||||||
|
base.HeaderValue{`A3eqwsafq3rFASqew;timeout=aaa`},
|
||||||
|
"strconv.ParseUint: parsing \"aaa\": invalid syntax",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
var h Session
|
var h Session
|
||||||
|
@@ -160,35 +160,40 @@ func TestTransportReadError(t *testing.T) {
|
|||||||
"invalid protocol (unicast;client_port=14186-14187)",
|
"invalid protocol (unicast;client_port=14186-14187)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid client port 1",
|
"invalid ports 1",
|
||||||
|
base.HeaderValue{`RTP/AVP;unicast;client_port=aa`},
|
||||||
|
"invalid ports (aa)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid ports 2",
|
||||||
|
base.HeaderValue{`RTP/AVP;unicast;client_port=aa-bb-cc`},
|
||||||
|
"invalid ports (aa-bb-cc)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid ports 3",
|
||||||
base.HeaderValue{`RTP/AVP;unicast;client_port=aa-14187`},
|
base.HeaderValue{`RTP/AVP;unicast;client_port=aa-14187`},
|
||||||
"invalid ports (aa-14187)",
|
"invalid ports (aa-14187)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid client port 2",
|
"invalid ports 4",
|
||||||
base.HeaderValue{`RTP/AVP;unicast;client_port=14186-aa`},
|
base.HeaderValue{`RTP/AVP;unicast;client_port=14186-aa`},
|
||||||
"invalid ports (14186-aa)",
|
"invalid ports (14186-aa)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid server port 1",
|
"invalid client port",
|
||||||
|
base.HeaderValue{`RTP/AVP;unicast;client_port=aa-14187`},
|
||||||
|
"invalid ports (aa-14187)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid server port",
|
||||||
base.HeaderValue{`RTP/AVP;unicast;server_port=aa-14187`},
|
base.HeaderValue{`RTP/AVP;unicast;server_port=aa-14187`},
|
||||||
"invalid ports (aa-14187)",
|
"invalid ports (aa-14187)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid server port 2",
|
"invalid interleaved port",
|
||||||
base.HeaderValue{`RTP/AVP;unicast;server_port=14186-aa`},
|
|
||||||
"invalid ports (14186-aa)",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"invalid interleaved port 1",
|
|
||||||
base.HeaderValue{`RTP/AVP;unicast;interleaved=aa-14187`},
|
base.HeaderValue{`RTP/AVP;unicast;interleaved=aa-14187`},
|
||||||
"invalid ports (aa-14187)",
|
"invalid ports (aa-14187)",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"invalid interleaved port 2",
|
|
||||||
base.HeaderValue{`RTP/AVP;unicast;interleaved=14186-aa`},
|
|
||||||
"invalid ports (14186-aa)",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"invalid ttl",
|
"invalid ttl",
|
||||||
base.HeaderValue{`RTP/AVP;unicast;ttl=aa`},
|
base.HeaderValue{`RTP/AVP;unicast;ttl=aa`},
|
||||||
|
23
pkg/multibuffer/multibuffer_test.go
Normal file
23
pkg/multibuffer/multibuffer_test.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package multibuffer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test(t *testing.T) {
|
||||||
|
mb := New(2, 4)
|
||||||
|
|
||||||
|
b := mb.Next()
|
||||||
|
copy(b, []byte{0x01, 0x02, 0x03, 0x04})
|
||||||
|
|
||||||
|
b = mb.Next()
|
||||||
|
copy(b, []byte{0x05, 0x06, 0x07, 0x08})
|
||||||
|
|
||||||
|
b = mb.Next()
|
||||||
|
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, b)
|
||||||
|
|
||||||
|
b = mb.Next()
|
||||||
|
require.Equal(t, []byte{0x05, 0x06, 0x07, 0x08}, b)
|
||||||
|
}
|
Reference in New Issue
Block a user