mirror of
https://github.com/aler9/gortsplib
synced 2025-10-26 08:40:35 +08:00
fix error when authenticating with vlc and slashes in paths
This commit is contained in:
@@ -46,7 +46,7 @@ func TestAuthMethods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuthBasePath(t *testing.T) {
|
func TestAuthVLC(t *testing.T) {
|
||||||
authServer := NewServer("testuser", "testpass",
|
authServer := NewServer("testuser", "testpass",
|
||||||
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest})
|
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest})
|
||||||
wwwAuthenticate := authServer.GenerateHeader()
|
wwwAuthenticate := authServer.GenerateHeader()
|
||||||
@@ -54,9 +54,9 @@ func TestAuthBasePath(t *testing.T) {
|
|||||||
ac, err := NewClient(wwwAuthenticate, "testuser", "testpass")
|
ac, err := NewClient(wwwAuthenticate, "testuser", "testpass")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
||||||
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/"})
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "/mypath/"})
|
||||||
|
|
||||||
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
||||||
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/trackId=0"})
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "/mypath/trackId=0"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/aler9/gortsplib/headers"
|
"github.com/aler9/gortsplib/headers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is an object that helps a server to authenticate a client.
|
// Server allows a server to authenticate a client.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
user string
|
user string
|
||||||
pass string
|
pass string
|
||||||
@@ -126,18 +126,12 @@ func (as *Server) ValidateHeader(v base.HeaderValue, method base.Method, ur *url
|
|||||||
uri := ur.String()
|
uri := ur.String()
|
||||||
|
|
||||||
if *auth.URI != uri {
|
if *auth.URI != uri {
|
||||||
// VLC strips the subpath
|
// VLC strips the control path; do another try without the control path
|
||||||
newUrl := *ur
|
base, _, ok := base.URLGetBaseControlPath(ur)
|
||||||
newUrl.Path = func() string {
|
if ok {
|
||||||
ret := newUrl.Path
|
ur.Path = "/" + base + "/"
|
||||||
|
uri = ur.String()
|
||||||
if n := strings.Index(ret[1:], "/"); n >= 0 {
|
}
|
||||||
ret = ret[:n+2]
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}()
|
|
||||||
uri = newUrl.String()
|
|
||||||
|
|
||||||
if *auth.URI != uri {
|
if *auth.URI != uri {
|
||||||
return fmt.Errorf("wrong url")
|
return fmt.Errorf("wrong url")
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stringsReverseIndexByte(s string, c byte) int {
|
func stringsReverseIndexByte(s string, c byte) int {
|
||||||
|
|||||||
190
base/url_test.go
190
base/url_test.go
@@ -1,109 +1,109 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestURLGetBasePath(t *testing.T) {
|
func TestURLGetBasePath(t *testing.T) {
|
||||||
for _, ca := range []struct{
|
for _, ca := range []struct {
|
||||||
u *url.URL
|
u *url.URL
|
||||||
b string
|
b string
|
||||||
} {
|
}{
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://localhost:8554/teststream"),
|
urlMustParse("rtsp://localhost:8554/teststream"),
|
||||||
"teststream",
|
"teststream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://localhost:8554/test/stream"),
|
urlMustParse("rtsp://localhost:8554/test/stream"),
|
||||||
"test/stream",
|
"test/stream",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
|
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
|
||||||
"test",
|
"test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
"te!st",
|
"te!st",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp",
|
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
b := URLGetBasePath(ca.u)
|
b := URLGetBasePath(ca.u)
|
||||||
require.Equal(t, ca.b, b)
|
require.Equal(t, ca.b, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestURLGetBaseControlPath(t *testing.T) {
|
func TestURLGetBaseControlPath(t *testing.T) {
|
||||||
for _, ca := range []struct{
|
for _, ca := range []struct {
|
||||||
u *url.URL
|
u *url.URL
|
||||||
b string
|
b string
|
||||||
c string
|
c string
|
||||||
} {
|
}{
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://localhost:8554/teststream/trackID=1"),
|
urlMustParse("rtsp://localhost:8554/teststream/trackID=1"),
|
||||||
"teststream",
|
"teststream",
|
||||||
"trackID=1",
|
"trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://localhost:8554/test/stream/trackID=1"),
|
urlMustParse("rtsp://localhost:8554/test/stream/trackID=1"),
|
||||||
"test/stream",
|
"test/stream",
|
||||||
"trackID=1",
|
"trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
||||||
"test",
|
"test",
|
||||||
"trackID=1",
|
"trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
"te!st",
|
"te!st",
|
||||||
"trackID=1",
|
"trackID=1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp",
|
"user=tmp&password=BagRep1!&channel=1&stream=0.sdp",
|
||||||
"trackID=1",
|
"trackID=1",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
b, c, ok := URLGetBaseControlPath(ca.u)
|
b, c, ok := URLGetBaseControlPath(ca.u)
|
||||||
require.Equal(t, true, ok)
|
require.Equal(t, true, ok)
|
||||||
require.Equal(t, ca.b, b)
|
require.Equal(t, ca.b, b)
|
||||||
require.Equal(t, ca.c, c)
|
require.Equal(t, ca.c, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestURLAddControlPath(t *testing.T) {
|
func TestURLAddControlPath(t *testing.T) {
|
||||||
for _, ca := range []struct{
|
for _, ca := range []struct {
|
||||||
u *url.URL
|
u *url.URL
|
||||||
ou *url.URL
|
ou *url.URL
|
||||||
} {
|
}{
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://localhost:8554/teststream"),
|
urlMustParse("rtsp://localhost:8554/teststream"),
|
||||||
urlMustParse("rtsp://localhost:8554/teststream/trackID=1"),
|
urlMustParse("rtsp://localhost:8554/teststream/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://localhost:8554/test/stream"),
|
urlMustParse("rtsp://localhost:8554/test/stream"),
|
||||||
urlMustParse("rtsp://localhost:8554/test/stream/trackID=1"),
|
urlMustParse("rtsp://localhost:8554/test/stream/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
|
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
|
||||||
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
urlMustParse("rtsp://192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
urlMustParse("rtsp://192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
|
||||||
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
urlMustParse("rtsp://192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=1"),
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
URLAddControlPath(ca.u, "trackID=1")
|
URLAddControlPath(ca.u, "trackID=1")
|
||||||
require.Equal(t, ca.ou, ca.u)
|
require.Equal(t, ca.ou, ca.u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user