From 3747e45978b0e5e7e6facf3e42398d16022b9fbb Mon Sep 17 00:00:00 2001 From: V2Ray Date: Fri, 25 Sep 2015 20:48:55 +0200 Subject: [PATCH] test cases for socks4 --- proxy/socks/protocol/socks4.go | 3 --- proxy/socks/protocol/socks4_test.go | 37 +++++++++++++++++++++++++++++ proxy/socks/protocol/socks_test.go | 17 ------------- 3 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 proxy/socks/protocol/socks4_test.go diff --git a/proxy/socks/protocol/socks4.go b/proxy/socks/protocol/socks4.go index fa690adcd..4e14b69f3 100644 --- a/proxy/socks/protocol/socks4.go +++ b/proxy/socks/protocol/socks4.go @@ -1,10 +1,7 @@ package protocol import ( - _ "fmt" - "github.com/v2ray/v2ray-core/common/errors" - _ "github.com/v2ray/v2ray-core/common/log" ) type SocksVersion4Error struct { diff --git a/proxy/socks/protocol/socks4_test.go b/proxy/socks/protocol/socks4_test.go new file mode 100644 index 000000000..0b1e16b0c --- /dev/null +++ b/proxy/socks/protocol/socks4_test.go @@ -0,0 +1,37 @@ +package protocol + +import ( + "bytes" + "testing" + + "github.com/v2ray/v2ray-core/testing/unit" +) + +func TestSocks4AuthenticationRequestRead(t *testing.T) { + assert := unit.Assert(t) + + rawRequest := []byte{ + 0x04, // version + 0x01, // command + 0x00, 0x35, + 0x72, 0x72, 0x72, 0x72, + } + _, request4, err := ReadAuthentication(bytes.NewReader(rawRequest)) + assert.Error(err).HasCode(1000) + assert.Byte(request4.Version).Named("Version").Equals(0x04) + assert.Byte(request4.Command).Named("Command").Equals(0x01) + assert.Uint16(request4.Port).Named("Port").Equals(53) + assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72}) +} + +func TestSocks4AuthenticationResponseToBytes(t *testing.T) { + assert := unit.Assert(t) + + response := &Socks4AuthenticationResponse{ + result: byte(0x10), + port: 443, + ip: []byte{1, 2, 3, 4}, + } + responseBytes := response.ToBytes(nil) + assert.Bytes(responseBytes).Equals([]byte{0x00, 0x10, 0x01, 0xBB, 0x01, 0x02, 0x03, 0x04}) +} diff --git a/proxy/socks/protocol/socks_test.go b/proxy/socks/protocol/socks_test.go index be4f2d2a8..7310f362f 100644 --- a/proxy/socks/protocol/socks_test.go +++ b/proxy/socks/protocol/socks_test.go @@ -37,23 +37,6 @@ func TestAuthenticationRequestRead(t *testing.T) { assert.Byte(request.authMethods[0]).Named("Auth Method").Equals(0x02) } -func TestAuthentication4RequestRead(t *testing.T) { - assert := unit.Assert(t) - - rawRequest := []byte{ - 0x04, // version - 0x01, // command - 0x00, 0x35, - 0x72, 0x72, 0x72, 0x72, - } - _, request4, err := ReadAuthentication(bytes.NewReader(rawRequest)) - assert.Error(err).HasCode(1000) - assert.Byte(request4.Version).Named("Version").Equals(0x04) - assert.Byte(request4.Command).Named("Command").Equals(0x01) - assert.Uint16(request4.Port).Named("Port").Equals(53) - assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72}) -} - func TestAuthenticationResponseWrite(t *testing.T) { assert := unit.Assert(t)