From 04b0a6eabe37e7f62273274d8f984f157d949212 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Thu, 9 Jul 2020 22:44:08 +0200 Subject: [PATCH] fix authentication with vlc --- auth.go | 14 ++++---------- auth_test.go | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/auth.go b/auth.go index 3c14daef..d808ee6b 100644 --- a/auth.go +++ b/auth.go @@ -144,22 +144,16 @@ func (as *AuthServer) ValidateHeader(header []string, method Method, ur *url.URL uri := ur.String() if inUri != uri { - // VLC strips any subpath + // VLC strips the subpath newUrl := *ur newUrl.Path = func() string { ret := newUrl.Path - // remove leading slash - if len(ret) > 1 { - ret = ret[1:] + if n := strings.Index(ret[1:], "/"); n >= 0 { + ret = ret[:n+2] } - // strip any subpath - if n := strings.Index(ret, "/"); n >= 0 { - ret = ret[:n] - } - - return "/" + ret + return ret }() uri = newUrl.String() diff --git a/auth_test.go b/auth_test.go index 2718c8b4..6c243e84 100644 --- a/auth_test.go +++ b/auth_test.go @@ -25,7 +25,7 @@ var casesAuth = []struct { }, } -func TestAuth(t *testing.T) { +func TestAuthMethods(t *testing.T) { for _, c := range casesAuth { t.Run(c.name, func(t *testing.T) { 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) +}