forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtlsrole_test.go
82 lines (73 loc) · 1.91 KB
/
dtlsrole_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package webrtc
import (
"fmt"
"testing"
"github.com/pion/sdp/v3"
"github.com/stretchr/testify/assert"
)
func TestDTLSRole_String(t *testing.T) {
testCases := []struct {
role DTLSRole
expectedString string
}{
{DTLSRole(Unknown), unknownStr},
{DTLSRoleAuto, "auto"},
{DTLSRoleClient, "client"},
{DTLSRoleServer, "server"},
}
for i, testCase := range testCases {
assert.Equal(t,
testCase.expectedString,
testCase.role.String(),
"testCase: %d %v", i, testCase,
)
}
}
func TestDTLSRoleFromRemoteSDP(t *testing.T) {
parseSDP := func(raw string) *sdp.SessionDescription {
parsed := &sdp.SessionDescription{}
if err := parsed.Unmarshal([]byte(raw)); err != nil {
panic(err)
}
return parsed
}
const noMedia = `v=0
o=- 4596489990601351948 2 IN IP4 127.0.0.1
s=-
t=0 0
`
const mediaNoSetup = `v=0
o=- 4596489990601351948 2 IN IP4 127.0.0.1
s=-
t=0 0
m=application 47299 DTLS/SCTP 5000
c=IN IP4 192.168.20.129
`
const mediaSetupDeclared = `v=0
o=- 4596489990601351948 2 IN IP4 127.0.0.1
s=-
t=0 0
m=application 47299 DTLS/SCTP 5000
c=IN IP4 192.168.20.129
a=setup:%s
`
testCases := []struct {
test string
sessionDescription *sdp.SessionDescription
expectedRole DTLSRole
}{
{"nil SessionDescription", nil, DTLSRoleAuto},
{"No MediaDescriptions", parseSDP(noMedia), DTLSRoleAuto},
{"MediaDescription, no setup", parseSDP(mediaNoSetup), DTLSRoleAuto},
{"MediaDescription, setup:actpass", parseSDP(fmt.Sprintf(mediaSetupDeclared, "actpass")), DTLSRoleAuto},
{"MediaDescription, setup:passive", parseSDP(fmt.Sprintf(mediaSetupDeclared, "passive")), DTLSRoleServer},
{"MediaDescription, setup:active", parseSDP(fmt.Sprintf(mediaSetupDeclared, "active")), DTLSRoleClient},
}
for _, testCase := range testCases {
assert.Equal(t,
testCase.expectedRole,
dtlsRoleFromRemoteSDP(testCase.sessionDescription),
"TestDTLSRoleFromSDP (%s)", testCase.test,
)
}
}