1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 22:36:12 -04:00

more test cases

This commit is contained in:
Darien Raymond 2015-12-04 16:32:42 +00:00
parent 30be218c62
commit 5ec30c3ad0
8 changed files with 264 additions and 28 deletions

View File

@ -21,5 +21,77 @@
}
]
}
}
},
"outboundDetour": [
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "127.0.0.1",
"port": 50005,
"users": [
{"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f"}
]
}
]
}
},
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "127.0.0.1",
"port": 50006,
"users": [
{"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f"}
]
}
]
}
},
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "127.0.0.1",
"port": 50007,
"users": [
{"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f"}
]
}
]
}
},
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "127.0.0.1",
"port": 50008,
"users": [
{"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f"}
]
}
]
}
},
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "127.0.0.1",
"port": 50009,
"users": [
{"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f"}
]
}
]
}
}
]
}

View File

@ -14,5 +14,19 @@
"outbound": {
"protocol": "freedom",
"settings": {}
}
},
"inboundDetour": [
{
"protocol": "vmess",
"port": "50005-50009",
"settings": {
"clients": [
{
"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f",
"level": 1
}
]
}
}
]
}

View File

@ -0,0 +1,57 @@
{
"port": 50020,
"inbound": {
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1",
"port": 50024,
"network": "tcp",
"timeout": 0
}
},
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "127.0.0.1",
"port": 50021,
"users": [
{"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f"}
]
}
]
}
},
"inboundDetour": [
{
"protocol": "dokodemo-door",
"port": 50022,
"settings": {
"address": "127.0.0.1",
"port": 50025,
"network": "tcp",
"timeout": 0
}
}
],
"outboundDetour": [
{
"protocol": "blackhole",
"tag": "blocked",
"settings": {}
}
],
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"type": "field",
"port": "50025-50029",
"outboundTag": "blocked"
}
]
}
}
}

View File

@ -0,0 +1,18 @@
{
"port": 50021,
"inbound": {
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "d17a1af7-efa5-42ca-b7e9-6a35282d737f",
"level": 1
}
]
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
}
}

View File

@ -25,11 +25,7 @@ func TestDokodemoTCP(t *testing.T) {
_, err := tcpServer.Start()
assert.Error(err).IsNil()
err = InitializeServer(TestFile("test_2_client.json"))
assert.Error(err).IsNil()
err = InitializeServer(TestFile("test_2_server.json"))
assert.Error(err).IsNil()
assert.Error(InitializeServerSetOnce("test_2")).IsNil()
dokodemoPortStart := v2net.Port(50011)
dokodemoPortEnd := v2net.Port(50015)

View File

@ -0,0 +1,77 @@
package scenarios
import (
"net"
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp"
)
func TestRouter(t *testing.T) {
v2testing.Current(t)
tcpServer := &tcp.Server{
Port: v2net.Port(50024),
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
buffer = append(buffer, data...)
return buffer
},
}
_, err := tcpServer.Start()
assert.Error(err).IsNil()
tcpServer2Accessed := false
tcpServer2 := &tcp.Server{
Port: v2net.Port(50025),
MsgProcessor: func(data []byte) []byte {
tcpServer2Accessed = true
return data
},
}
_, err = tcpServer2.Start()
assert.Error(err).IsNil()
assert.Error(InitializeServerSetOnce("test_3")).IsNil()
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(50020),
})
payload := "direct dokodemo request."
nBytes, err := conn.Write([]byte(payload))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload))
conn.CloseWrite()
response := make([]byte, 1024)
nBytes, err = conn.Read(response)
assert.Error(err).IsNil()
assert.StringLiteral("Processed: " + payload).Equals(string(response[:nBytes]))
conn.Close()
conn, err = net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(50022),
})
payload = "blocked dokodemo request."
nBytes, err = conn.Write([]byte(payload))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload))
conn.CloseWrite()
response = make([]byte, 1024)
nBytes, err = conn.Read(response)
assert.Error(err).IsNotNil()
assert.Int(nBytes).Equals(0)
assert.Bool(tcpServer2Accessed).IsFalse()
conn.Close()
}

View File

@ -24,10 +24,30 @@ import (
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
)
var (
serverup = make(map[string]bool)
)
func TestFile(filename string) string {
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
}
func InitializeServerSetOnce(testcase string) error {
if up, found := serverup[testcase]; found && up {
return nil
}
err := InitializeServer(TestFile(testcase + "_server.json"))
if err != nil {
return err
}
err = InitializeServer(TestFile(testcase + "_client.json"))
if err != nil {
return err
}
serverup[testcase] = true
return nil
}
func InitializeServer(configFile string) error {
config, err := jsonconf.LoadConfig(configFile)
if err != nil {

View File

@ -16,24 +16,6 @@ var (
serverUp = false
)
func setupServer() error {
if serverUp {
return nil
}
err := InitializeServer(TestFile("test_1_client.json"))
if err != nil {
return err
}
err = InitializeServer(TestFile("test_1_server.json"))
if err != nil {
return err
}
serverUp = true
return nil
}
func TestTCPConnection(t *testing.T) {
v2testing.Current(t)
@ -50,7 +32,7 @@ func TestTCPConnection(t *testing.T) {
_, err := tcpServer.Start()
assert.Error(err).IsNil()
assert.Error(setupServer()).IsNil()
assert.Error(InitializeServerSetOnce("test_1")).IsNil()
socksPort := v2net.Port(50000)
@ -117,7 +99,7 @@ func TestTCPBind(t *testing.T) {
_, err := tcpServer.Start()
assert.Error(err).IsNil()
assert.Error(setupServer()).IsNil()
assert.Error(InitializeServerSetOnce("test_1")).IsNil()
socksPort := v2net.Port(50000)
@ -165,7 +147,7 @@ func TestUDPAssociate(t *testing.T) {
_, err := udpServer.Start()
assert.Error(err).IsNil()
assert.Error(setupServer()).IsNil()
assert.Error(InitializeServerSetOnce("test_1")).IsNil()
socksPort := v2net.Port(50000)