-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth_digest_test.go
47 lines (38 loc) · 1023 Bytes
/
auth_digest_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
package rtsp
import (
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAuthDigest_Header(t *testing.T) {
assert := assert.New(t)
u, err := url.Parse("rtsp://test:[email protected]:34001/digest/")
if !assert.NoError(err) {
return
}
// uri is the request URL without credentials
// in real code will be droppend on SendRequest()
uri := "rtsp://127.0.0.1:34001/digest/"
authItems := []string{
`realm="test"`,
`domain="digest"`,
`nonce="9a52e5d50ca0f63e5b0b9188b1e32a15"`,
}
authHeader := strings.Join(authItems, ", ")
login := u.User.Username()
password, _ := u.User.Password()
auth := NewAuthDigest(login, password, authHeader)
expectedItems := []string{
`Digest username="test"`,
`uri="rtsp://127.0.0.1:34001/digest/"`,
`realm="test"`,
`nonce="9a52e5d50ca0f63e5b0b9188b1e32a15"`,
`response="7e50c7dadf6909bc91e389b258788707"`,
}
expectedHeader := strings.Join(expectedItems, ", ")
assert.Equal(
expectedHeader,
auth.Header("DESCRIBE", uri),
)
}