mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-30 07:46:41 -04:00
update end 2 end test
This commit is contained in:
parent
5003afc85c
commit
9b830fc432
14
app/router/config/testing/config.go
Normal file
14
app/router/config/testing/config.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
type RouterConfig struct {
|
||||||
|
StrategyValue string
|
||||||
|
SettingsValue interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RouterConfig) Strategy() string {
|
||||||
|
return this.StrategyValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RouterConfig) Settings() interface{} {
|
||||||
|
return this.SettingsValue
|
||||||
|
}
|
17
app/router/rules/config/testing/router.go
Normal file
17
app/router/rules/config/testing/router.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2ray/v2ray-core/app/router/rules/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RouterRuleConfig struct {
|
||||||
|
RuleList []*TestRule
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RouterRuleConfig) Rules() []config.Rule {
|
||||||
|
rules := make([]config.Rule, len(this.RuleList))
|
||||||
|
for idx, rule := range this.RuleList {
|
||||||
|
rules[idx] = rule
|
||||||
|
}
|
||||||
|
return rules
|
||||||
|
}
|
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app/router"
|
"github.com/v2ray/v2ray-core/app/router"
|
||||||
"github.com/v2ray/v2ray-core/app/router/rules/config"
|
"github.com/v2ray/v2ray-core/app/router/rules/config"
|
||||||
"github.com/v2ray/v2ray-core/app/router/rules/config/json"
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ type RouterFactory struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *RouterFactory) Create(rawConfig interface{}) (router.Router, error) {
|
func (this *RouterFactory) Create(rawConfig interface{}) (router.Router, error) {
|
||||||
config := rawConfig.(*json.RouterRuleConfig)
|
config := rawConfig.(config.RouterRuleConfig)
|
||||||
rules := config.Rules()
|
rules := config.Rules()
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
if rule == nil {
|
if rule == nil {
|
||||||
|
@ -46,8 +46,8 @@ var (
|
|||||||
|
|
||||||
debugLogger = noOpLoggerInstance
|
debugLogger = noOpLoggerInstance
|
||||||
infoLogger = noOpLoggerInstance
|
infoLogger = noOpLoggerInstance
|
||||||
warningLogger = noOpLoggerInstance
|
warningLogger = streamLoggerInstance
|
||||||
errorLogger = noOpLoggerInstance
|
errorLogger = streamLoggerInstance
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogLevel int
|
type LogLevel int
|
||||||
|
@ -2,6 +2,7 @@ package mocks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
|
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
|
||||||
|
routertestingconfig "github.com/v2ray/v2ray-core/app/router/config/testing"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
"github.com/v2ray/v2ray-core/shell/point/config"
|
"github.com/v2ray/v2ray-core/shell/point/config"
|
||||||
)
|
)
|
||||||
@ -37,7 +38,7 @@ func (this *PortRange) To() v2net.Port {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InboundDetourConfig struct {
|
type InboundDetourConfig struct {
|
||||||
ConnectionConfig
|
*ConnectionConfig
|
||||||
PortRangeValue *PortRange
|
PortRangeValue *PortRange
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ func (this *InboundDetourConfig) PortRange() v2net.PortRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OutboundDetourConfig struct {
|
type OutboundDetourConfig struct {
|
||||||
ConnectionConfig
|
*ConnectionConfig
|
||||||
TagValue string
|
TagValue string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ func (config *LogConfig) AccessLog() string {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
PortValue v2net.Port
|
PortValue v2net.Port
|
||||||
LogConfigValue *LogConfig
|
LogConfigValue *LogConfig
|
||||||
RouterConfigValue routerconfig.RouterConfig
|
RouterConfigValue *routertestingconfig.RouterConfig
|
||||||
InboundConfigValue *ConnectionConfig
|
InboundConfigValue *ConnectionConfig
|
||||||
OutboundConfigValue *ConnectionConfig
|
OutboundConfigValue *ConnectionConfig
|
||||||
InboundDetoursValue []*InboundDetourConfig
|
InboundDetoursValue []*InboundDetourConfig
|
||||||
@ -73,19 +74,31 @@ func (config *Config) Port() v2net.Port {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) LogConfig() config.LogConfig {
|
func (config *Config) LogConfig() config.LogConfig {
|
||||||
|
if config.LogConfigValue == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return config.LogConfigValue
|
return config.LogConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Config) RouterConfig() routerconfig.RouterConfig {
|
func (this *Config) RouterConfig() routerconfig.RouterConfig {
|
||||||
|
if this.RouterConfigValue == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return this.RouterConfigValue
|
return this.RouterConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) InboundConfig() config.ConnectionConfig {
|
func (this *Config) InboundConfig() config.ConnectionConfig {
|
||||||
return config.InboundConfigValue
|
if this.InboundConfigValue == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return this.InboundConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) OutboundConfig() config.ConnectionConfig {
|
func (this *Config) OutboundConfig() config.ConnectionConfig {
|
||||||
return config.OutboundConfigValue
|
if this.OutboundConfigValue == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return this.OutboundConfigValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Config) InboundDetours() []config.InboundDetourConfig {
|
func (this *Config) InboundDetours() []config.InboundDetourConfig {
|
||||||
|
@ -3,6 +3,9 @@ package scenarios
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
routerconfig "github.com/v2ray/v2ray-core/app/router/config/testing"
|
||||||
|
_ "github.com/v2ray/v2ray-core/app/router/rules"
|
||||||
|
rulesconfig "github.com/v2ray/v2ray-core/app/router/rules/config/testing"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom"
|
||||||
@ -58,14 +61,14 @@ func socks5UDPRequest(address v2net.Address, payload []byte) []byte {
|
|||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUpV2Ray() (v2net.Port, error) {
|
func setUpV2Ray(routing func(v2net.Destination) bool) (v2net.Port, v2net.Port, error) {
|
||||||
id1, err := config.NewID("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
|
id1, err := config.NewID("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
id2, err := config.NewID("93ccfc71-b136-4015-ac85-e037bd1ead9e")
|
id2, err := config.NewID("93ccfc71-b136-4015-ac85-e037bd1ead9e")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
users := []*vmessjson.ConfigUser{
|
users := []*vmessjson.ConfigUser{
|
||||||
&vmessjson.ConfigUser{Id: id1},
|
&vmessjson.ConfigUser{Id: id1},
|
||||||
@ -88,14 +91,15 @@ func setUpV2Ray() (v2net.Port, error) {
|
|||||||
}
|
}
|
||||||
pointB, err := point.NewPoint(&configB)
|
pointB, err := point.NewPoint(&configB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
err = pointB.Start()
|
err = pointB.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
portA := v2nettesting.PickPort()
|
portA := v2nettesting.PickPort()
|
||||||
|
portA2 := v2nettesting.PickPort()
|
||||||
configA := mocks.Config{
|
configA := mocks.Config{
|
||||||
PortValue: portA,
|
PortValue: portA,
|
||||||
InboundConfigValue: &mocks.ConnectionConfig{
|
InboundConfigValue: &mocks.ConnectionConfig{
|
||||||
@ -117,16 +121,52 @@ func setUpV2Ray() (v2net.Port, error) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
InboundDetoursValue: []*mocks.InboundDetourConfig{
|
||||||
|
&mocks.InboundDetourConfig{
|
||||||
|
PortRangeValue: &mocks.PortRange{
|
||||||
|
FromValue: portA2,
|
||||||
|
ToValue: portA2,
|
||||||
|
},
|
||||||
|
ConnectionConfig: &mocks.ConnectionConfig{
|
||||||
|
ProtocolValue: "socks",
|
||||||
|
SettingsValue: &socksjson.SocksConfig{
|
||||||
|
AuthMethod: "noauth",
|
||||||
|
UDPEnabled: false,
|
||||||
|
HostIP: socksjson.IPAddress(net.IPv4(127, 0, 0, 1)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
OutboundDetoursValue: []*mocks.OutboundDetourConfig{
|
||||||
|
&mocks.OutboundDetourConfig{
|
||||||
|
TagValue: "direct",
|
||||||
|
ConnectionConfig: &mocks.ConnectionConfig{
|
||||||
|
ProtocolValue: "freedom",
|
||||||
|
SettingsValue: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RouterConfigValue: &routerconfig.RouterConfig{
|
||||||
|
StrategyValue: "rules",
|
||||||
|
SettingsValue: &rulesconfig.RouterRuleConfig{
|
||||||
|
RuleList: []*rulesconfig.TestRule{
|
||||||
|
&rulesconfig.TestRule{
|
||||||
|
TagValue: "direct",
|
||||||
|
Function: routing,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pointA, err := point.NewPoint(&configA)
|
pointA, err := point.NewPoint(&configA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
err = pointA.Start()
|
err = pointA.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return portA, nil
|
return portA, portA2, nil
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,12 @@ import (
|
|||||||
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
EmptyRouting = func(v2net.Destination) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func TestTCPConnection(t *testing.T) {
|
func TestTCPConnection(t *testing.T) {
|
||||||
v2testing.Current(t)
|
v2testing.Current(t)
|
||||||
|
|
||||||
@ -28,7 +34,7 @@ func TestTCPConnection(t *testing.T) {
|
|||||||
_, err := tcpServer.Start()
|
_, err := tcpServer.Start()
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
v2rayPort, err := setUpV2Ray()
|
v2rayPort, _, err := setUpV2Ray(EmptyRouting)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
@ -94,7 +100,7 @@ func TestTCPBind(t *testing.T) {
|
|||||||
_, err := tcpServer.Start()
|
_, err := tcpServer.Start()
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
v2rayPort, err := setUpV2Ray()
|
v2rayPort, _, err := setUpV2Ray(EmptyRouting)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||||
@ -141,7 +147,7 @@ func TestUDPAssociate(t *testing.T) {
|
|||||||
_, err := udpServer.Start()
|
_, err := udpServer.Start()
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
v2rayPort, err := setUpV2Ray()
|
v2rayPort, _, err := setUpV2Ray(EmptyRouting)
|
||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||||
|
Loading…
Reference in New Issue
Block a user