mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
headers: add negative unit tests
This commit is contained in:
@@ -63,7 +63,7 @@ func (h *Auth) Read(v base.HeaderValue) error {
|
||||
|
||||
i := strings.IndexByte(v0, ' ')
|
||||
if i < 0 {
|
||||
return fmt.Errorf("unable to split between method and keys (%v)", v)
|
||||
return fmt.Errorf("unable to split between method and keys (%v)", v0)
|
||||
}
|
||||
method, v0 := v0[:i], v0[i+1:]
|
||||
|
||||
|
@@ -196,28 +196,33 @@ func TestAuthReadError(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])",
|
||||
},
|
||||
{
|
||||
"no keys",
|
||||
base.HeaderValue{"Basic"},
|
||||
"unable to split between method and keys (Basic)",
|
||||
},
|
||||
{
|
||||
"invalid method",
|
||||
base.HeaderValue{"Testing key1=val1"},
|
||||
"invalid method (Testing)",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var h Auth
|
||||
err := h.Read(ca.hv)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ca.err, err.Error())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -191,20 +191,23 @@ func TestRTPInfoReadError(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])",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var h RTPInfo
|
||||
err := h.Read(ca.hv)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ca.err, err.Error())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -72,20 +72,23 @@ func TestSessionReadError(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])",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var h Session
|
||||
err := h.Read(ca.hv)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ca.err, err.Error())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ func (h *Transport) Read(v base.HeaderValue) error {
|
||||
h.Protocol = base.StreamProtocolTCP
|
||||
|
||||
default:
|
||||
return fmt.Errorf("invalid protocol (%v)", v)
|
||||
return fmt.Errorf("invalid protocol (%v)", v0)
|
||||
}
|
||||
|
||||
i = strings.IndexByte(v0, ';')
|
||||
@@ -137,7 +137,7 @@ func (h *Transport) Read(v base.HeaderValue) error {
|
||||
h.Delivery = &v
|
||||
|
||||
default:
|
||||
// cast is optional, go back
|
||||
// delivery is optional, go back
|
||||
v0 = part + ";" + v0
|
||||
}
|
||||
|
||||
|
@@ -137,20 +137,73 @@ func TestTransportReadError(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])",
|
||||
},
|
||||
{
|
||||
"missing delivery",
|
||||
base.HeaderValue{`RTP/AVP`},
|
||||
"unable to find key (;)",
|
||||
},
|
||||
{
|
||||
"invalid protocol",
|
||||
base.HeaderValue{`invalid;unicast;client_port=14186-14187`},
|
||||
"invalid protocol (unicast;client_port=14186-14187)",
|
||||
},
|
||||
{
|
||||
"invalid client port 1",
|
||||
base.HeaderValue{`RTP/AVP;unicast;client_port=aa-14187`},
|
||||
"invalid ports (aa-14187)",
|
||||
},
|
||||
{
|
||||
"invalid client port 2",
|
||||
base.HeaderValue{`RTP/AVP;unicast;client_port=14186-aa`},
|
||||
"invalid ports (14186-aa)",
|
||||
},
|
||||
{
|
||||
"invalid server port 1",
|
||||
base.HeaderValue{`RTP/AVP;unicast;server_port=aa-14187`},
|
||||
"invalid ports (aa-14187)",
|
||||
},
|
||||
{
|
||||
"invalid server port 2",
|
||||
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`},
|
||||
"invalid ports (aa-14187)",
|
||||
},
|
||||
{
|
||||
"invalid interleaved port 2",
|
||||
base.HeaderValue{`RTP/AVP;unicast;interleaved=14186-aa`},
|
||||
"invalid ports (14186-aa)",
|
||||
},
|
||||
{
|
||||
"invalid ttl",
|
||||
base.HeaderValue{`RTP/AVP;unicast;ttl=aa`},
|
||||
"strconv.ParseUint: parsing \"aa\": invalid syntax",
|
||||
},
|
||||
{
|
||||
"invalid mode",
|
||||
base.HeaderValue{`RTP/AVP;unicast;mode=aa`},
|
||||
"invalid transport mode: 'aa'",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
var h Transport
|
||||
err := h.Read(ca.hv)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ca.err, err.Error())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user