support basic authentication

This commit is contained in:
aler9
2020-06-14 18:34:36 +02:00
parent c06d302979
commit 2eddb95cab
7 changed files with 346 additions and 198 deletions

44
auth_test.go Normal file
View File

@@ -0,0 +1,44 @@
package gortsplib
import (
"net/url"
"testing"
"github.com/stretchr/testify/require"
)
var casesAuth = []struct {
name string
methods []AuthMethod
}{
{
"basic",
[]AuthMethod{Basic},
},
{
"digest",
[]AuthMethod{Digest},
},
{
"both",
[]AuthMethod{Basic, Digest},
},
}
func TestAuth(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(ANNOUNCE,
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath"})
err = authServer.ValidateHeader(authorization, ANNOUNCE,
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath"})
require.NoError(t, err)
})
}
}