From 13ab2622c5e569a6ac2adf3e1ca33d127a0c413b Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sat, 5 Nov 2016 01:00:54 +0100 Subject: [PATCH] shadowsocks test --- testing/scenarios/data/test_6_client.json | 39 +++++++++++ testing/scenarios/data/test_6_server.json | 25 ++++++- testing/scenarios/shadowsocks_test.go | 85 ++++++++--------------- 3 files changed, 92 insertions(+), 57 deletions(-) create mode 100644 testing/scenarios/data/test_6_client.json diff --git a/testing/scenarios/data/test_6_client.json b/testing/scenarios/data/test_6_client.json new file mode 100644 index 000000000..cf16d9210 --- /dev/null +++ b/testing/scenarios/data/test_6_client.json @@ -0,0 +1,39 @@ +{ + "log": { + "loglevel": "debug" + }, + "inbound": { + "port": 50050, + "listen": "127.0.0.1", + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1", + "port": 50052, + "network": "tcp,udp", + "timeout": 0 + } + }, + "outbound": { + "protocol": "shadowsocks", + "streamSettings": { + "network": "tcp", + "tcpSettings": { + "header": { + "type": "http", + "request": {}, + "response": {} + } + } + }, + "settings": { + "servers": [ + { + "address": "127.0.0.1", + "port": 50051, + "method": "aes-256-cfb", + "password": "v2ray-password" + } + ] + } + } +} diff --git a/testing/scenarios/data/test_6_server.json b/testing/scenarios/data/test_6_server.json index fff9f381b..90168f5bf 100644 --- a/testing/scenarios/data/test_6_server.json +++ b/testing/scenarios/data/test_6_server.json @@ -1,11 +1,24 @@ { - "port": 50051, + "log": { + "loglevel": "debug" + }, "inbound": { + "port": 50051, "listen": "127.0.0.1", "protocol": "shadowsocks", "settings": { "method": "aes-256-cfb", "password": "v2ray-password" + }, + "streamSettings": { + "network": "tcp", + "tcpSettings": { + "header": { + "type": "http", + "request": {}, + "response": {} + } + } } }, "inboundDetour": [ @@ -17,6 +30,16 @@ "method": "aes-128-cfb", "password": "v2ray-another", "udp": true + }, + "streamSettings": { + "network": "tcp", + "tcpSettings": { + "header": { + "type": "http", + "request": {}, + "response": {} + } + } } }, { diff --git a/testing/scenarios/shadowsocks_test.go b/testing/scenarios/shadowsocks_test.go index d29b5f5aa..69f70dc52 100644 --- a/testing/scenarios/shadowsocks_test.go +++ b/testing/scenarios/shadowsocks_test.go @@ -4,11 +4,10 @@ import ( "net" "testing" + "v2ray.com/core/common/alloc" v2net "v2ray.com/core/common/net" "v2ray.com/core/testing/assert" "v2ray.com/core/testing/servers/tcp" - - ssclient "github.com/shadowsocks/shadowsocks-go/shadowsocks" ) func TestShadowsocksTCP(t *testing.T) { @@ -27,65 +26,39 @@ func TestShadowsocksTCP(t *testing.T) { assert.Error(err).IsNil() defer tcpServer.Close() - assert.Error(InitializeServerServer("test_6")).IsNil() + assert.Error(InitializeServerSetOnce("test_6")).IsNil() - cipher, err := ssclient.NewCipher("aes-256-cfb", "v2ray-password") - assert.Error(err).IsNil() + for i := 0; i < 1; i++ { + conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ + IP: []byte{127, 0, 0, 1}, + Port: 50050, + }) + assert.Error(err).IsNil() - rawAddr := []byte{1, 127, 0, 0, 1, 0xc3, 0x84} // 127.0.0.1:50052 - conn, err := ssclient.DialWithRawAddr(rawAddr, "127.0.0.1:50051", cipher) - assert.Error(err).IsNil() + payload := "dokodemo request." + nBytes, err := conn.Write([]byte(payload)) + assert.Error(err).IsNil() + assert.Int(nBytes).Equals(len(payload)) - payload := "shadowsocks request." - nBytes, err := conn.Write([]byte(payload)) - assert.Error(err).IsNil() - assert.Int(nBytes).Equals(len(payload)) + conn.CloseWrite() - conn.Conn.(*net.TCPConn).CloseWrite() + response := alloc.NewBuffer().Clear() + finished := false + for { + _, err := response.FillFrom(conn) + assert.Error(err).IsNil() + if err != nil { + break + } + if response.String() == "Processed: "+payload { + finished = true + break + } + } + assert.Bool(finished).IsTrue() - response := make([]byte, 1024) - nBytes, err = conn.Read(response) - assert.Error(err).IsNil() - assert.String("Processed: " + payload).Equals(string(response[:nBytes])) - conn.Close() - - cipher, err = ssclient.NewCipher("aes-128-cfb", "v2ray-another") - assert.Error(err).IsNil() - - conn, err = ssclient.DialWithRawAddr(rawAddr, "127.0.0.1:50055", cipher) - assert.Error(err).IsNil() - - payload = "shadowsocks request 2." - nBytes, err = conn.Write([]byte(payload)) - assert.Error(err).IsNil() - assert.Int(nBytes).Equals(len(payload)) - - conn.Conn.(*net.TCPConn).CloseWrite() - - response = make([]byte, 1024) - nBytes, err = conn.Read(response) - assert.Error(err).IsNil() - assert.String("Processed: " + payload).Equals(string(response[:nBytes])) - conn.Close() - - cipher, err = ssclient.NewCipher("chacha20", "new-password") - assert.Error(err).IsNil() - - conn, err = ssclient.DialWithRawAddr(rawAddr, "127.0.0.1:50056", cipher) - assert.Error(err).IsNil() - - payload = "shadowsocks request 3." - nBytes, err = conn.Write([]byte(payload)) - assert.Error(err).IsNil() - assert.Int(nBytes).Equals(len(payload)) - - conn.Conn.(*net.TCPConn).CloseWrite() - - response = make([]byte, 1024) - nBytes, err = conn.Read(response) - assert.Error(err).IsNil() - assert.String("Processed: " + payload).Equals(string(response[:nBytes])) - conn.Close() + conn.Close() + } CloseAllServers() }