mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Touched up snowflake client tests
There were a few tests that needed refreshing since the introduction of the pion library. Also added a few tests for the ICE server parsing function in the client.
This commit is contained in:
parent
dabdd847ce
commit
0f99c5ab12
3 changed files with 90 additions and 8 deletions
59
client/client_test.go
Normal file
59
client/client_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestICEServerParser(t *testing.T) {
|
||||
Convey("Test parsing of ICE servers", t, func() {
|
||||
for _, test := range []struct {
|
||||
input string
|
||||
urls [][]string
|
||||
length int
|
||||
}{
|
||||
{
|
||||
"",
|
||||
nil,
|
||||
0,
|
||||
},
|
||||
{
|
||||
" ",
|
||||
nil,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"stun:stun.l.google.com:19302",
|
||||
[][]string{[]string{"stun:stun.l.google.com:19302"}},
|
||||
1,
|
||||
},
|
||||
{
|
||||
"stun:stun.l.google.com:19302,stun.ekiga.net",
|
||||
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun.ekiga.net"}},
|
||||
2,
|
||||
},
|
||||
{
|
||||
"stun:stun.l.google.com:19302, stun.ekiga.net",
|
||||
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun.ekiga.net"}},
|
||||
2,
|
||||
},
|
||||
} {
|
||||
servers := parseIceServers(test.input)
|
||||
|
||||
if test.urls == nil {
|
||||
So(servers, ShouldBeNil)
|
||||
} else {
|
||||
So(servers, ShouldNotBeNil)
|
||||
}
|
||||
|
||||
So(len(servers), ShouldEqual, test.length)
|
||||
|
||||
for i, server := range servers {
|
||||
So(server.URLs, ShouldResemble, test.urls[i])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/pion/webrtc"
|
||||
|
@ -72,6 +73,10 @@ func (f FakePeers) Collect() (Snowflake, error) { return &WebRTCPeer{}, nil }
|
|||
func (f FakePeers) Pop() Snowflake { return nil }
|
||||
func (f FakePeers) Melted() <-chan struct{} { return nil }
|
||||
|
||||
const sampleSDP = `"v=0\r\no=- 4358805017720277108 2 IN IP4 8.8.8.8\r\ns=-\r\nt=0 0\r\na=group:BUNDLE data\r\na=msid-semantic: WMS\r\nm=application 56688 DTLS/SCTP 5000\r\nc=IN IP4 8.8.8.8\r\na=candidate:3769337065 1 udp 2122260223 8.8.8.8 56688 typ host generation 0 network-id 1 network-cost 50\r\na=candidate:2921887769 1 tcp 1518280447 8.8.8.8 35441 typ host tcptype passive generation 0 network-id 1 network-cost 50\r\na=ice-ufrag:aMAZ\r\na=ice-pwd:jcHb08Jjgrazp2dzjdrvPPvV\r\na=ice-options:trickle\r\na=fingerprint:sha-256 C8:88:EE:B9:E7:02:2E:21:37:ED:7A:D1:EB:2B:A3:15:A2:3B:5B:1C:3D:D4:D5:1F:06:CF:52:40:03:F8:DD:66\r\na=setup:actpass\r\na=mid:data\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n"`
|
||||
|
||||
const sampleAnswer = `{"type":"answer","sdp":` + sampleSDP + `}`
|
||||
|
||||
func TestSnowflakeClient(t *testing.T) {
|
||||
|
||||
Convey("Peers", t, func() {
|
||||
|
@ -219,23 +224,40 @@ func TestSnowflakeClient(t *testing.T) {
|
|||
c.answerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||
|
||||
c.config = &webrtc.Configuration{}
|
||||
c.preparePeerConnection()
|
||||
c.pc, _ = webrtc.NewPeerConnection(*c.config)
|
||||
offer, _ := c.pc.CreateOffer(nil)
|
||||
err := c.pc.SetLocalDescription(offer)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
c.offerChannel <- nil
|
||||
answer := deserializeSessionDescription(
|
||||
`{"type":"answer","sdp":""}`)
|
||||
answer := deserializeSessionDescription(sampleAnswer)
|
||||
So(answer, ShouldNotBeNil)
|
||||
c.answerChannel <- answer
|
||||
c.exchangeSDP()
|
||||
err = c.exchangeSDP()
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
SkipConvey("Exchange SDP fails on nil answer", func() {
|
||||
c.reset = make(chan struct{})
|
||||
Convey("Exchange SDP keeps trying on nil answer", func(ctx C) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
||||
c.offerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||
c.answerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||
c.config = &webrtc.Configuration{}
|
||||
c.pc, _ = webrtc.NewPeerConnection(*c.config)
|
||||
offer, _ := c.pc.CreateOffer(nil)
|
||||
c.pc.SetLocalDescription(offer)
|
||||
|
||||
c.offerChannel <- nil
|
||||
c.answerChannel <- nil
|
||||
c.exchangeSDP()
|
||||
<-c.reset
|
||||
go func() {
|
||||
err := c.exchangeSDP()
|
||||
ctx.So(err, ShouldBeNil)
|
||||
wg.Done()
|
||||
}()
|
||||
answer := deserializeSessionDescription(sampleAnswer)
|
||||
c.answerChannel <- answer
|
||||
wg.Wait()
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -77,6 +77,7 @@ func parseIceServers(s string) []webrtc.ICEServer {
|
|||
urls := strings.Split(s, ",")
|
||||
log.Printf("Using ICE Servers:")
|
||||
for _, url := range urls {
|
||||
url = strings.TrimSpace(url)
|
||||
log.Printf("url: %s", url)
|
||||
servers = append(servers, webrtc.ICEServer{
|
||||
URLs: []string{url},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue