mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 23:52:46 +08:00
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package gortsplib
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/aler9/gortsplib/base"
|
|
"github.com/aler9/gortsplib/headers"
|
|
)
|
|
|
|
var casesAuth = []struct {
|
|
name string
|
|
methods []headers.AuthMethod
|
|
}{
|
|
{
|
|
"basic",
|
|
[]headers.AuthMethod{headers.AuthBasic},
|
|
},
|
|
{
|
|
"digest",
|
|
[]headers.AuthMethod{headers.AuthDigest},
|
|
},
|
|
{
|
|
"both",
|
|
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest},
|
|
},
|
|
}
|
|
|
|
func TestAuthMethods(t *testing.T) {
|
|
for _, c := range casesAuth {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
authServer := NewAuthServer("testuser", "testpass", c.methods)
|
|
wwwAuthenticate := authServer.GenerateHeader()
|
|
|
|
ac, err := newAuthClient(wwwAuthenticate, "testuser", "testpass")
|
|
require.NoError(t, err)
|
|
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath"})
|
|
|
|
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath"})
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAuthBasePath(t *testing.T) {
|
|
authServer := NewAuthServer("testuser", "testpass",
|
|
[]headers.AuthMethod{headers.AuthBasic, headers.AuthDigest})
|
|
wwwAuthenticate := authServer.GenerateHeader()
|
|
|
|
ac, err := newAuthClient(wwwAuthenticate, "testuser", "testpass")
|
|
require.NoError(t, err)
|
|
authorization := ac.GenerateHeader(base.ANNOUNCE,
|
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/"})
|
|
|
|
err = authServer.ValidateHeader(authorization, base.ANNOUNCE,
|
|
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/trackId=0"})
|
|
require.NoError(t, err)
|
|
}
|