forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_test.go
58 lines (49 loc) · 1.38 KB
/
auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 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(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)
})
}
}
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)
}