[tor-commits] [pluggable-transports/snowflake] 03/03: Add some test cases for client poll requests

gitolite role git at cupani.torproject.org
Mon Mar 21 19:37:18 UTC 2022


This is an automated email from the git hooks/post-receive script.

arlo pushed a commit to branch main
in repository pluggable-transports/snowflake.

commit fa2f6824d924f3317c82bc740130f354f6a1780c
Author: Arlo Breault <arlolra at gmail.com>
AuthorDate: Thu Mar 17 11:23:49 2022 -0400

    Add some test cases for client poll requests
---
 common/messages/messages_test.go | 45 +++++++++++++++++++++++++++++++++-------
 1 file changed, 37 insertions(+), 8 deletions(-)

diff --git a/common/messages/messages_test.go b/common/messages/messages_test.go
index ae0d4f9..5365aa8 100644
--- a/common/messages/messages_test.go
+++ b/common/messages/messages_test.go
@@ -326,15 +326,44 @@ func TestDecodeClientPollRequest(t *testing.T) {
 
 func TestEncodeClientPollRequests(t *testing.T) {
 	Convey("Context", t, func() {
-		req1 := &ClientPollRequest{
-			NAT:   "unknown",
-			Offer: "fake",
+		for i, test := range []struct {
+			natType     string
+			offer       string
+			fingerprint string
+			err         error
+		}{
+			{
+				"unknown",
+				"fake",
+				"",
+				nil,
+			},
+			{
+				"unknown",
+				"fake",
+				defaultBridgeFingerprint,
+				nil,
+			},
+		} {
+			req1 := &ClientPollRequest{
+				NAT:         test.natType,
+				Offer:       test.offer,
+				Fingerprint: test.fingerprint,
+			}
+			b, err := req1.EncodeClientPollRequest()
+			So(err, ShouldEqual, nil)
+			req2, err := DecodeClientPollRequest(b)
+			So(err, ShouldHaveSameTypeAs, test.err)
+			if test.err == nil {
+				So(req2.Offer, ShouldEqual, req1.Offer)
+				So(req2.NAT, ShouldEqual, req1.NAT)
+				fingerprint := test.fingerprint
+				if i == 0 {
+					fingerprint = defaultBridgeFingerprint
+				}
+				So(req2.Fingerprint, ShouldEqual, fingerprint)
+			}
 		}
-		b, err := req1.EncodeClientPollRequest()
-		So(err, ShouldEqual, nil)
-		req2, err := DecodeClientPollRequest(b)
-		So(err, ShouldEqual, nil)
-		So(req2, ShouldResemble, req1)
 	})
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list