[tor-commits] [goptlib/master] Rearrange SocksRequest.

dcf at torproject.org dcf at torproject.org
Mon Dec 9 02:49:51 UTC 2013


commit 23e5be1a203cc4d04dcf7f35c6104884ffe3184b
Author: David Fifield <david at bamsoftware.com>
Date:   Sat Dec 7 22:34:59 2013 -0800

    Rearrange SocksRequest.
---
 socks.go      |    4 ++--
 socks_test.go |   38 ++++++++++++++++++++++----------------
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/socks.go b/socks.go
index a3c5ede..583b999 100644
--- a/socks.go
+++ b/socks.go
@@ -18,10 +18,10 @@ const (
 
 // SocksRequest describes a SOCKS request.
 type SocksRequest struct {
-	// The userid string sent by the client.
-	Username string
 	// The endpoint requested by the client as a "host:port" string.
 	Target string
+	// The userid string sent by the client.
+	Username string
 	// The parsed contents of Username as a key–value mapping.
 	Args Args
 }
diff --git a/socks_test.go b/socks_test.go
index bcd4433..6cfa967 100644
--- a/socks_test.go
+++ b/socks_test.go
@@ -26,38 +26,44 @@ func TestReadSocks4aConnect(t *testing.T) {
 	}
 	ipTests := [...]struct {
 		input  []byte
-		userid string
 		addr   net.TCPAddr
+		userid string
 	}{
 		{
 			[]byte("\x04\x01\x12\x34\x01\x02\x03\x04key=value\x00"),
-			"key=value", net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 0x1234},
+			net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 0x1234},
+			"key=value",
 		},
 		{
 			[]byte("\x04\x01\x12\x34\x01\x02\x03\x04\x00"),
-			"", net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 0x1234},
+			net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 0x1234},
+			"",
 		},
 	}
 	hostnameTests := [...]struct {
 		input  []byte
-		userid string
 		target string
+		userid string
 	}{
 		{
 			[]byte("\x04\x01\x12\x34\x00\x00\x00\x01key=value\x00hostname\x00"),
-			"key=value", "hostname:4660",
+			"hostname:4660",
+			"key=value",
 		},
 		{
 			[]byte("\x04\x01\x12\x34\x00\x00\x00\x01\x00hostname\x00"),
-			"", "hostname:4660",
+			"hostname:4660",
+			"",
 		},
 		{
 			[]byte("\x04\x01\x12\x34\x00\x00\x00\x01key=value\x00\x00"),
-			"key=value", ":4660",
+			":4660",
+			"key=value",
 		},
 		{
 			[]byte("\x04\x01\x12\x34\x00\x00\x00\x01\x00\x00"),
-			"", ":4660",
+			":4660",
+			"",
 		},
 	}
 
@@ -77,10 +83,6 @@ func TestReadSocks4aConnect(t *testing.T) {
 		if err != nil {
 			t.Errorf("%q unexpectedly returned an error: %s", test.input, err)
 		}
-		if req.Username != test.userid {
-			t.Errorf("%q → username %q (expected %q)", test.input,
-				req.Username, test.userid)
-		}
 		addr, err := net.ResolveTCPAddr("tcp", req.Target)
 		if err != nil {
 			t.Error("%q → target %q: cannot resolve: %s", test.input,
@@ -90,6 +92,10 @@ func TestReadSocks4aConnect(t *testing.T) {
 			t.Errorf("%q → address %s (expected %s)", test.input,
 				req.Target, test.addr.String())
 		}
+		if req.Username != test.userid {
+			t.Errorf("%q → username %q (expected %q)", test.input,
+				req.Username, test.userid)
+		}
 		if req.Args == nil {
 			t.Errorf("%q → unexpected nil Args from username %q", test.input, req.Username)
 		}
@@ -102,14 +108,14 @@ func TestReadSocks4aConnect(t *testing.T) {
 		if err != nil {
 			t.Errorf("%q unexpectedly returned an error: %s", test.input, err)
 		}
-		if req.Username != test.userid {
-			t.Errorf("%q → username %q (expected %q)", test.input,
-				req.Username, test.userid)
-		}
 		if req.Target != test.target {
 			t.Errorf("%q → target %q (expected %q)", test.input,
 				req.Target, test.target)
 		}
+		if req.Username != test.userid {
+			t.Errorf("%q → username %q (expected %q)", test.input,
+				req.Username, test.userid)
+		}
 		if req.Args == nil {
 			t.Errorf("%q → unexpected nil Args from username %q", test.input, req.Username)
 		}





More information about the tor-commits mailing list