mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
shadowsocks test
This commit is contained in:
parent
0727aa0da9
commit
13ab2622c5
39
testing/scenarios/data/test_6_client.json
Normal file
39
testing/scenarios/data/test_6_client.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user