1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

shadowsocks test

This commit is contained in:
Darien Raymond 2016-11-05 01:00:54 +01:00
parent 0727aa0da9
commit 13ab2622c5
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 92 additions and 57 deletions

View File

@ -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"
}
]
}
}
}

View File

@ -1,11 +1,24 @@
{ {
"port": 50051, "log": {
"loglevel": "debug"
},
"inbound": { "inbound": {
"port": 50051,
"listen": "127.0.0.1", "listen": "127.0.0.1",
"protocol": "shadowsocks", "protocol": "shadowsocks",
"settings": { "settings": {
"method": "aes-256-cfb", "method": "aes-256-cfb",
"password": "v2ray-password" "password": "v2ray-password"
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"request": {},
"response": {}
}
}
} }
}, },
"inboundDetour": [ "inboundDetour": [
@ -17,6 +30,16 @@
"method": "aes-128-cfb", "method": "aes-128-cfb",
"password": "v2ray-another", "password": "v2ray-another",
"udp": true "udp": true
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"request": {},
"response": {}
}
}
} }
}, },
{ {

View File

@ -4,11 +4,10 @@ import (
"net" "net"
"testing" "testing"
"v2ray.com/core/common/alloc"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
"v2ray.com/core/testing/servers/tcp" "v2ray.com/core/testing/servers/tcp"
ssclient "github.com/shadowsocks/shadowsocks-go/shadowsocks"
) )
func TestShadowsocksTCP(t *testing.T) { func TestShadowsocksTCP(t *testing.T) {
@ -27,65 +26,39 @@ func TestShadowsocksTCP(t *testing.T) {
assert.Error(err).IsNil() assert.Error(err).IsNil()
defer tcpServer.Close() defer tcpServer.Close()
assert.Error(InitializeServerServer("test_6")).IsNil() assert.Error(InitializeServerSetOnce("test_6")).IsNil()
cipher, err := ssclient.NewCipher("aes-256-cfb", "v2ray-password") for i := 0; i < 1; i++ {
assert.Error(err).IsNil() 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 payload := "dokodemo request."
conn, err := ssclient.DialWithRawAddr(rawAddr, "127.0.0.1:50051", cipher) nBytes, err := conn.Write([]byte(payload))
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload))
payload := "shadowsocks request." conn.CloseWrite()
nBytes, err := conn.Write([]byte(payload))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload))
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) conn.Close()
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()
CloseAllServers() CloseAllServers()
} }