-
Notifications
You must be signed in to change notification settings - Fork 134
/
ice_test.go
96 lines (78 loc) · 1.86 KB
/
ice_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package ice
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"os"
"reflect"
"strings"
"testing"
"time"
"github.com/pion/webrtc/v3"
"github.com/jech/galene/turnserver"
)
func TestPassword(t *testing.T) {
s := Server{
URLs: []string{"turn:turn.example.org"},
Username: "jch",
Credential: "secret",
}
ss := webrtc.ICEServer{
URLs: []string{"turn:turn.example.org"},
Username: "jch",
Credential: "secret",
}
sss, err := getServer(s)
if err != nil || !reflect.DeepEqual(sss, ss) {
t.Errorf("Got %v, expected %v", sss, ss)
}
}
func TestHMAC(t *testing.T) {
s := Server{
URLs: []string{"turn:turn.example.org"},
Username: "jch",
Credential: "secret",
CredentialType: "hmac-sha1",
}
ss := webrtc.ICEServer{
URLs: []string{"turn:turn.example.org"},
}
sss, err := getServer(s)
if !strings.HasSuffix(sss.Username, ":"+s.Username) {
t.Errorf("username is %v", ss.Username)
}
ss.Username = sss.Username
mac := hmac.New(sha1.New, []byte(s.Credential.(string)))
mac.Write([]byte(sss.Username))
buf := strings.Builder{}
e := base64.NewEncoder(base64.StdEncoding, &buf)
e.Write(mac.Sum(nil))
e.Close()
ss.Credential = buf.String()
if err != nil || !reflect.DeepEqual(sss, ss) {
t.Errorf("Got %v, expected %v", sss, ss)
}
}
func TestICEConfiguration(t *testing.T) {
ICEFilename = "/tmp/no/such/file"
turnserver.Address = ""
conf := ICEConfiguration()
if conf == nil {
t.Errorf("conf is nil")
}
conf2 := ICEConfiguration()
if conf2 != conf {
t.Errorf("conf2 != conf")
}
if len(conf.ICEServers) != 0 {
t.Errorf("len(ICEServers) = %v", len(conf.ICEServers))
}
}
func TestRelayTest(t *testing.T) {
ICEFilename = "/tmp/no/such/file"
turnserver.Address = ""
_, err := RelayTest(200 * time.Millisecond)
if err == nil || !os.IsTimeout(err) {
t.Errorf("Relay test returned %v", err)
}
}