[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Touched up snowflake client tests



commit 0f99c5ab12edfaac2e95d5d403297cd26d6229bc
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Tue Nov 26 15:04:48 2019 -0500

    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.
---
 client/client_test.go  | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 client/lib/lib_test.go | 38 +++++++++++++++++++++++++-------
 client/snowflake.go    |  1 +
 3 files changed, 90 insertions(+), 8 deletions(-)

diff --git a/client/client_test.go b/client/client_test.go
new file mode 100644
index 0000000..aeaf979
--- /dev/null
+++ b/client/client_test.go
@@ -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])
+			}
+
+		}
+
+	})
+}
diff --git a/client/lib/lib_test.go b/client/lib/lib_test.go
index 4e9e2c7..12368f3 100644
--- a/client/lib/lib_test.go
+++ b/client/lib/lib_test.go
@@ -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()
 			})
 
 		})
diff --git a/client/snowflake.go b/client/snowflake.go
index 959f83c..bb7de46 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -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},



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits