mirror of
https://github.com/aler9/gortsplib
synced 2025-10-08 08:30:06 +08:00
fix authentication with vlc
This commit is contained in:
14
auth.go
14
auth.go
@@ -144,22 +144,16 @@ func (as *AuthServer) ValidateHeader(header []string, method Method, ur *url.URL
|
|||||||
uri := ur.String()
|
uri := ur.String()
|
||||||
|
|
||||||
if inUri != uri {
|
if inUri != uri {
|
||||||
// VLC strips any subpath
|
// VLC strips the subpath
|
||||||
newUrl := *ur
|
newUrl := *ur
|
||||||
newUrl.Path = func() string {
|
newUrl.Path = func() string {
|
||||||
ret := newUrl.Path
|
ret := newUrl.Path
|
||||||
|
|
||||||
// remove leading slash
|
if n := strings.Index(ret[1:], "/"); n >= 0 {
|
||||||
if len(ret) > 1 {
|
ret = ret[:n+2]
|
||||||
ret = ret[1:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// strip any subpath
|
return ret
|
||||||
if n := strings.Index(ret, "/"); n >= 0 {
|
|
||||||
ret = ret[:n]
|
|
||||||
}
|
|
||||||
|
|
||||||
return "/" + ret
|
|
||||||
}()
|
}()
|
||||||
uri = newUrl.String()
|
uri = newUrl.String()
|
||||||
|
|
||||||
|
16
auth_test.go
16
auth_test.go
@@ -25,7 +25,7 @@ var casesAuth = []struct {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuth(t *testing.T) {
|
func TestAuthMethods(t *testing.T) {
|
||||||
for _, c := range casesAuth {
|
for _, c := range casesAuth {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
authServer := NewAuthServer("testuser", "testpass", c.methods)
|
authServer := NewAuthServer("testuser", "testpass", c.methods)
|
||||||
@@ -42,3 +42,17 @@ func TestAuth(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAuthBasePath(t *testing.T) {
|
||||||
|
authServer := NewAuthServer("testuser", "testpass", []AuthMethod{Basic, Digest})
|
||||||
|
wwwAuthenticate := authServer.GenerateHeader()
|
||||||
|
|
||||||
|
ac, err := NewAuthClient(wwwAuthenticate, "testuser", "testpass")
|
||||||
|
require.NoError(t, err)
|
||||||
|
authorization := ac.GenerateHeader(ANNOUNCE,
|
||||||
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/"})
|
||||||
|
|
||||||
|
err = authServer.ValidateHeader(authorization, ANNOUNCE,
|
||||||
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/trackId=0"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user