mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
update test for router refactor
This commit is contained in:
parent
3c56a7f947
commit
98ee44befd
@ -1,6 +1,7 @@
|
|||||||
package dns_test
|
package dns_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -14,7 +15,6 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v4/app/policy"
|
"github.com/v2fly/v2ray-core/v4/app/policy"
|
||||||
"github.com/v2fly/v2ray-core/v4/app/proxyman"
|
"github.com/v2fly/v2ray-core/v4/app/proxyman"
|
||||||
_ "github.com/v2fly/v2ray-core/v4/app/proxyman/outbound"
|
_ "github.com/v2fly/v2ray-core/v4/app/proxyman/outbound"
|
||||||
"github.com/v2fly/v2ray-core/v4/app/router"
|
|
||||||
"github.com/v2fly/v2ray-core/v4/common"
|
"github.com/v2fly/v2ray-core/v4/common"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/net"
|
"github.com/v2fly/v2ray-core/v4/common/net"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/serial"
|
"github.com/v2fly/v2ray-core/v4/common/serial"
|
||||||
@ -430,7 +430,7 @@ func TestStaticHostDomain(t *testing.T) {
|
|||||||
Port: uint32(port),
|
Port: uint32(port),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StaticHosts: []*Config_HostMapping{
|
StaticHosts: []*HostMapping{
|
||||||
{
|
{
|
||||||
Type: DomainMatchingType_Full,
|
Type: DomainMatchingType_Full,
|
||||||
Domain: "example.com",
|
Domain: "example.com",
|
||||||
@ -496,10 +496,10 @@ func TestIPMatch(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Port: uint32(port),
|
Port: uint32(port),
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
CountryCode: "local",
|
CountryCode: "local",
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
// inner ip, will not match
|
// inner ip, will not match
|
||||||
Ip: []byte{192, 168, 11, 1},
|
Ip: []byte{192, 168, 11, 1},
|
||||||
@ -520,10 +520,10 @@ func TestIPMatch(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Port: uint32(port),
|
Port: uint32(port),
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
CountryCode: "test",
|
CountryCode: "test",
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{8, 8, 8, 8},
|
Ip: []byte{8, 8, 8, 8},
|
||||||
Prefix: 32,
|
Prefix: 32,
|
||||||
@ -532,7 +532,7 @@ func TestIPMatch(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
CountryCode: "test",
|
CountryCode: "test",
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{8, 8, 8, 4},
|
Ip: []byte{8, 8, 8, 4},
|
||||||
Prefix: 32,
|
Prefix: 32,
|
||||||
@ -620,10 +620,10 @@ func TestLocalDomain(t *testing.T) {
|
|||||||
// Equivalent of dotless:localhost
|
// Equivalent of dotless:localhost
|
||||||
{Type: DomainMatchingType_Regex, Domain: "^[^.]*localhost[^.]*$"},
|
{Type: DomainMatchingType_Regex, Domain: "^[^.]*localhost[^.]*$"},
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{ // Will match localhost, localhost-a and localhost-b,
|
{ // Will match localhost, localhost-a and localhost-b,
|
||||||
CountryCode: "local",
|
CountryCode: "local",
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{Ip: []byte{127, 0, 0, 2}, Prefix: 32},
|
{Ip: []byte{127, 0, 0, 2}, Prefix: 32},
|
||||||
{Ip: []byte{127, 0, 0, 3}, Prefix: 32},
|
{Ip: []byte{127, 0, 0, 3}, Prefix: 32},
|
||||||
{Ip: []byte{127, 0, 0, 4}, Prefix: 32},
|
{Ip: []byte{127, 0, 0, 4}, Prefix: 32},
|
||||||
@ -649,7 +649,7 @@ func TestLocalDomain(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StaticHosts: []*Config_HostMapping{
|
StaticHosts: []*HostMapping{
|
||||||
{
|
{
|
||||||
Type: DomainMatchingType_Full,
|
Type: DomainMatchingType_Full,
|
||||||
Domain: "hostnamestatic",
|
Domain: "hostnamestatic",
|
||||||
@ -818,9 +818,9 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
|
|||||||
Domain: "google.com",
|
Domain: "google.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{ // Will only match 8.8.8.8 and 8.8.4.4
|
{ // Will only match 8.8.8.8 and 8.8.4.4
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{Ip: []byte{8, 8, 8, 8}, Prefix: 32},
|
{Ip: []byte{8, 8, 8, 8}, Prefix: 32},
|
||||||
{Ip: []byte{8, 8, 4, 4}, Prefix: 32},
|
{Ip: []byte{8, 8, 4, 4}, Prefix: 32},
|
||||||
},
|
},
|
||||||
@ -843,9 +843,9 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
|
|||||||
Domain: "google.com",
|
Domain: "google.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{ // Will match 8.8.8.8 and 8.8.8.7, etc
|
{ // Will match 8.8.8.8 and 8.8.8.7, etc
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{Ip: []byte{8, 8, 8, 7}, Prefix: 24},
|
{Ip: []byte{8, 8, 8, 7}, Prefix: 24},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -867,9 +867,9 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
|
|||||||
Domain: "api.google.com",
|
Domain: "api.google.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{ // Will only match 8.8.7.7 (api.google.com)
|
{ // Will only match 8.8.7.7 (api.google.com)
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{Ip: []byte{8, 8, 7, 7}, Prefix: 32},
|
{Ip: []byte{8, 8, 7, 7}, Prefix: 32},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -891,9 +891,9 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
|
|||||||
Domain: "v2.api.google.com",
|
Domain: "v2.api.google.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{ // Will only match 8.8.7.8 (v2.api.google.com)
|
{ // Will only match 8.8.7.8 (v2.api.google.com)
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{Ip: []byte{8, 8, 7, 8}, Prefix: 32},
|
{Ip: []byte{8, 8, 7, 8}, Prefix: 32},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStaticHosts(t *testing.T) {
|
func TestStaticHosts(t *testing.T) {
|
||||||
pb := []*Config_HostMapping{
|
pb := []*HostMapping{
|
||||||
{
|
{
|
||||||
Type: DomainMatchingType_Full,
|
Type: DomainMatchingType_Full,
|
||||||
Domain: "v2fly.org",
|
Domain: "v2fly.org",
|
||||||
|
@ -2,6 +2,7 @@ package command_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -232,11 +233,11 @@ func TestSerivceTestRoute(t *testing.T) {
|
|||||||
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
|
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{{Type: router.Domain_RootDomain, Value: "com"}},
|
Domain: []*routercommon.Domain{{Type: routercommon.Domain_RootDomain, Value: "com"}},
|
||||||
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
|
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SourceGeoip: []*router.GeoIP{{CountryCode: "private", Cidr: []*router.CIDR{{Ip: []byte{127, 0, 0, 0}, Prefix: 8}}}},
|
SourceGeoip: []*routercommon.GeoIP{{CountryCode: "private", Cidr: []*routercommon.CIDR{{Ip: []byte{127, 0, 0, 0}, Prefix: 8}}}},
|
||||||
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
|
TargetTag: &router.RoutingRule_Tag{Tag: "out"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@ package router_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -38,17 +39,17 @@ func init() {
|
|||||||
func TestGeoIPMatcherContainer(t *testing.T) {
|
func TestGeoIPMatcherContainer(t *testing.T) {
|
||||||
container := &router.GeoIPMatcherContainer{}
|
container := &router.GeoIPMatcherContainer{}
|
||||||
|
|
||||||
m1, err := container.Add(&router.GeoIP{
|
m1, err := container.Add(&routercommon.GeoIP{
|
||||||
CountryCode: "CN",
|
CountryCode: "CN",
|
||||||
})
|
})
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
m2, err := container.Add(&router.GeoIP{
|
m2, err := container.Add(&routercommon.GeoIP{
|
||||||
CountryCode: "US",
|
CountryCode: "US",
|
||||||
})
|
})
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
m3, err := container.Add(&router.GeoIP{
|
m3, err := container.Add(&routercommon.GeoIP{
|
||||||
CountryCode: "CN",
|
CountryCode: "CN",
|
||||||
})
|
})
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
@ -194,12 +195,12 @@ func TestGeoIPMatcher6US(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadGeoIP(country string) ([]*router.CIDR, error) {
|
func loadGeoIP(country string) ([]*routercommon.CIDR, error) {
|
||||||
geoipBytes, err := filesystem.ReadAsset("geoip.dat")
|
geoipBytes, err := filesystem.ReadAsset("geoip.dat")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var geoipList router.GeoIPList
|
var geoipList routercommon.GeoIPList
|
||||||
if err := proto.Unmarshal(geoipBytes, &geoipList); err != nil {
|
if err := proto.Unmarshal(geoipBytes, &geoipList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package router_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -79,18 +80,18 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
rule: &router.RoutingRule{
|
rule: &router.RoutingRule{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Value: "v2fly.org",
|
Value: "v2fly.org",
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Value: "google.com",
|
Value: "google.com",
|
||||||
Type: router.Domain_RootDomain,
|
Type: routercommon.Domain_RootDomain,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Value: "^facebook\\.com$",
|
Value: "^facebook\\.com$",
|
||||||
Type: router.Domain_Regex,
|
Type: routercommon.Domain_Regex,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -127,7 +128,7 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
rule: &router.RoutingRule{
|
rule: &router.RoutingRule{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{8, 8, 8, 8},
|
Ip: []byte{8, 8, 8, 8},
|
||||||
Prefix: 32,
|
Prefix: 32,
|
||||||
@ -163,9 +164,9 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
rule: &router.RoutingRule{
|
rule: &router.RoutingRule{
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{8, 8, 8, 8},
|
Ip: []byte{8, 8, 8, 8},
|
||||||
Prefix: 32,
|
Prefix: 32,
|
||||||
@ -203,7 +204,7 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
rule: &router.RoutingRule{
|
rule: &router.RoutingRule{
|
||||||
SourceCidr: []*router.CIDR{
|
SourceCidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{192, 168, 0, 0},
|
Ip: []byte{192, 168, 0, 0},
|
||||||
Prefix: 16,
|
Prefix: 16,
|
||||||
@ -351,12 +352,12 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadGeoSite(country string) ([]*router.Domain, error) {
|
func loadGeoSite(country string) ([]*routercommon.Domain, error) {
|
||||||
geositeBytes, err := filesystem.ReadAsset("geosite.dat")
|
geositeBytes, err := filesystem.ReadAsset("geosite.dat")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var geositeList router.GeoSiteList
|
var geositeList routercommon.GeoSiteList
|
||||||
if err := proto.Unmarshal(geositeBytes, &geositeList); err != nil {
|
if err := proto.Unmarshal(geositeBytes, &geositeList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -502,12 +503,12 @@ func BenchmarkDomainMatcher(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkMultiGeoIPMatcher(b *testing.B) {
|
func BenchmarkMultiGeoIPMatcher(b *testing.B) {
|
||||||
var geoips []*router.GeoIP
|
var geoips []*routercommon.GeoIP
|
||||||
|
|
||||||
{
|
{
|
||||||
ips, err := loadGeoIP("CN")
|
ips, err := loadGeoIP("CN")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
geoips = append(geoips, &router.GeoIP{
|
geoips = append(geoips, &routercommon.GeoIP{
|
||||||
CountryCode: "CN",
|
CountryCode: "CN",
|
||||||
Cidr: ips,
|
Cidr: ips,
|
||||||
})
|
})
|
||||||
@ -516,7 +517,7 @@ func BenchmarkMultiGeoIPMatcher(b *testing.B) {
|
|||||||
{
|
{
|
||||||
ips, err := loadGeoIP("JP")
|
ips, err := loadGeoIP("JP")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
geoips = append(geoips, &router.GeoIP{
|
geoips = append(geoips, &routercommon.GeoIP{
|
||||||
CountryCode: "JP",
|
CountryCode: "JP",
|
||||||
Cidr: ips,
|
Cidr: ips,
|
||||||
})
|
})
|
||||||
@ -525,7 +526,7 @@ func BenchmarkMultiGeoIPMatcher(b *testing.B) {
|
|||||||
{
|
{
|
||||||
ips, err := loadGeoIP("CA")
|
ips, err := loadGeoIP("CA")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
geoips = append(geoips, &router.GeoIP{
|
geoips = append(geoips, &routercommon.GeoIP{
|
||||||
CountryCode: "CA",
|
CountryCode: "CA",
|
||||||
Cidr: ips,
|
Cidr: ips,
|
||||||
})
|
})
|
||||||
@ -534,7 +535,7 @@ func BenchmarkMultiGeoIPMatcher(b *testing.B) {
|
|||||||
{
|
{
|
||||||
ips, err := loadGeoIP("US")
|
ips, err := loadGeoIP("US")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
geoips = append(geoips, &router.GeoIP{
|
geoips = append(geoips, &routercommon.GeoIP{
|
||||||
CountryCode: "US",
|
CountryCode: "US",
|
||||||
Cidr: ips,
|
Cidr: ips,
|
||||||
})
|
})
|
||||||
|
@ -2,6 +2,7 @@ package router_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
@ -145,13 +146,13 @@ func TestLeastLoadBalancer(t *testing.T) {
|
|||||||
|
|
||||||
func TestIPOnDemand(t *testing.T) {
|
func TestIPOnDemand(t *testing.T) {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
DomainStrategy: Config_IpOnDemand,
|
DomainStrategy: DomainStrategy_IpOnDemand,
|
||||||
Rule: []*RoutingRule{
|
Rule: []*RoutingRule{
|
||||||
{
|
{
|
||||||
TargetTag: &RoutingRule_Tag{
|
TargetTag: &RoutingRule_Tag{
|
||||||
Tag: "test",
|
Tag: "test",
|
||||||
},
|
},
|
||||||
Cidr: []*CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{192, 168, 0, 0},
|
Ip: []byte{192, 168, 0, 0},
|
||||||
Prefix: 16,
|
Prefix: 16,
|
||||||
@ -180,13 +181,13 @@ func TestIPOnDemand(t *testing.T) {
|
|||||||
|
|
||||||
func TestIPIfNonMatchDomain(t *testing.T) {
|
func TestIPIfNonMatchDomain(t *testing.T) {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
DomainStrategy: Config_IpIfNonMatch,
|
DomainStrategy: DomainStrategy_IpIfNonMatch,
|
||||||
Rule: []*RoutingRule{
|
Rule: []*RoutingRule{
|
||||||
{
|
{
|
||||||
TargetTag: &RoutingRule_Tag{
|
TargetTag: &RoutingRule_Tag{
|
||||||
Tag: "test",
|
Tag: "test",
|
||||||
},
|
},
|
||||||
Cidr: []*CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{192, 168, 0, 0},
|
Ip: []byte{192, 168, 0, 0},
|
||||||
Prefix: 16,
|
Prefix: 16,
|
||||||
@ -215,13 +216,13 @@ func TestIPIfNonMatchDomain(t *testing.T) {
|
|||||||
|
|
||||||
func TestIPIfNonMatchIP(t *testing.T) {
|
func TestIPIfNonMatchIP(t *testing.T) {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
DomainStrategy: Config_IpIfNonMatch,
|
DomainStrategy: DomainStrategy_IpIfNonMatch,
|
||||||
Rule: []*RoutingRule{
|
Rule: []*RoutingRule{
|
||||||
{
|
{
|
||||||
TargetTag: &RoutingRule_Tag{
|
TargetTag: &RoutingRule_Tag{
|
||||||
Tag: "test",
|
Tag: "test",
|
||||||
},
|
},
|
||||||
Cidr: []*CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{127, 0, 0, 0},
|
Ip: []byte{127, 0, 0, 0},
|
||||||
Prefix: 8,
|
Prefix: 8,
|
||||||
|
@ -112,7 +112,7 @@ func TestDNSConfigParsing(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StaticHosts: []*dns.Config_HostMapping{
|
StaticHosts: []*dns.HostMapping{
|
||||||
{
|
{
|
||||||
Type: dns.DomainMatchingType_Subdomain,
|
Type: dns.DomainMatchingType_Subdomain,
|
||||||
Domain: "example.com",
|
Domain: "example.com",
|
||||||
|
@ -2,6 +2,7 @@ package router_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
|
||||||
router2 "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router"
|
router2 "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router"
|
||||||
"testing"
|
"testing"
|
||||||
@ -108,7 +109,7 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
}`,
|
}`,
|
||||||
Parser: createParser(),
|
Parser: createParser(),
|
||||||
Output: &router.Config{
|
Output: &router.Config{
|
||||||
DomainStrategy: router.Config_AsIs,
|
DomainStrategy: router.DomainStrategy_AsIs,
|
||||||
BalancingRule: []*router.BalancingRule{
|
BalancingRule: []*router.BalancingRule{
|
||||||
{
|
{
|
||||||
Tag: "b1",
|
Tag: "b1",
|
||||||
@ -140,13 +141,13 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "baidu.com",
|
Value: "baidu.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "qq.com",
|
Value: "qq.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -155,13 +156,13 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "v2fly.org",
|
Value: "v2fly.org",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "github.com",
|
Value: "github.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -170,9 +171,9 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{10, 0, 0, 0},
|
Ip: []byte{10, 0, 0, 0},
|
||||||
Prefix: 8,
|
Prefix: 8,
|
||||||
@ -248,16 +249,16 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
}`,
|
}`,
|
||||||
Parser: createParser(),
|
Parser: createParser(),
|
||||||
Output: &router.Config{
|
Output: &router.Config{
|
||||||
DomainStrategy: router.Config_IpIfNonMatch,
|
DomainStrategy: router.DomainStrategy_IpIfNonMatch,
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "baidu.com",
|
Value: "baidu.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "qq.com",
|
Value: "qq.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -266,13 +267,13 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "v2fly.org",
|
Value: "v2fly.org",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "github.com",
|
Value: "github.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -281,9 +282,9 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{10, 0, 0, 0},
|
Ip: []byte{10, 0, 0, 0},
|
||||||
Prefix: 8,
|
Prefix: 8,
|
||||||
@ -334,16 +335,16 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
}`,
|
}`,
|
||||||
Parser: createParser(),
|
Parser: createParser(),
|
||||||
Output: &router.Config{
|
Output: &router.Config{
|
||||||
DomainStrategy: router.Config_AsIs,
|
DomainStrategy: router.DomainStrategy_AsIs,
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "baidu.com",
|
Value: "baidu.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "qq.com",
|
Value: "qq.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -352,13 +353,13 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "v2fly.org",
|
Value: "v2fly.org",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: router.Domain_Plain,
|
Type: routercommon.Domain_Plain,
|
||||||
Value: "github.com",
|
Value: "github.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -367,9 +368,9 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{10, 0, 0, 0},
|
Ip: []byte{10, 0, 0, 0},
|
||||||
Prefix: 8,
|
Prefix: 8,
|
||||||
|
@ -2,6 +2,7 @@ package v4_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/muxcfg"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/muxcfg"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/v4"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/v4"
|
||||||
@ -158,12 +159,12 @@ func TestV2RayConfig(t *testing.T) {
|
|||||||
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
||||||
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||||
serial.ToTypedMessage(&router.Config{
|
serial.ToTypedMessage(&router.Config{
|
||||||
DomainStrategy: router.Config_AsIs,
|
DomainStrategy: router.DomainStrategy_AsIs,
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Geoip: []*router.GeoIP{
|
Geoip: []*routercommon.GeoIP{
|
||||||
{
|
{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{10, 0, 0, 0},
|
Ip: []byte{10, 0, 0, 0},
|
||||||
Prefix: 8,
|
Prefix: 8,
|
||||||
|
@ -2,6 +2,7 @@ package scenarios
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -38,10 +39,10 @@ func TestResolveIP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
serial.ToTypedMessage(&router.Config{
|
serial.ToTypedMessage(&router.Config{
|
||||||
DomainStrategy: router.Config_IpIfNonMatch,
|
DomainStrategy: router.DomainStrategy_IpIfNonMatch,
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Cidr: []*router.CIDR{
|
Cidr: []*routercommon.CIDR{
|
||||||
{
|
{
|
||||||
Ip: []byte{127, 0, 0, 0},
|
Ip: []byte{127, 0, 0, 0},
|
||||||
Prefix: 8,
|
Prefix: 8,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/router/routercommon"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -54,8 +55,8 @@ func TestReverseProxy(t *testing.T) {
|
|||||||
serial.ToTypedMessage(&router.Config{
|
serial.ToTypedMessage(&router.Config{
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{Type: router.Domain_Full, Value: "test.v2fly.org"},
|
{Type: routercommon.Domain_Full, Value: "test.v2fly.org"},
|
||||||
},
|
},
|
||||||
TargetTag: &router.RoutingRule_Tag{
|
TargetTag: &router.RoutingRule_Tag{
|
||||||
Tag: "portal",
|
Tag: "portal",
|
||||||
@ -123,8 +124,8 @@ func TestReverseProxy(t *testing.T) {
|
|||||||
serial.ToTypedMessage(&router.Config{
|
serial.ToTypedMessage(&router.Config{
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{Type: router.Domain_Full, Value: "test.v2fly.org"},
|
{Type: routercommon.Domain_Full, Value: "test.v2fly.org"},
|
||||||
},
|
},
|
||||||
TargetTag: &router.RoutingRule_Tag{
|
TargetTag: &router.RoutingRule_Tag{
|
||||||
Tag: "reverse",
|
Tag: "reverse",
|
||||||
@ -239,8 +240,8 @@ func TestReverseProxyLongRunning(t *testing.T) {
|
|||||||
serial.ToTypedMessage(&router.Config{
|
serial.ToTypedMessage(&router.Config{
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{Type: router.Domain_Full, Value: "test.v2fly.org"},
|
{Type: routercommon.Domain_Full, Value: "test.v2fly.org"},
|
||||||
},
|
},
|
||||||
TargetTag: &router.RoutingRule_Tag{
|
TargetTag: &router.RoutingRule_Tag{
|
||||||
Tag: "portal",
|
Tag: "portal",
|
||||||
@ -322,8 +323,8 @@ func TestReverseProxyLongRunning(t *testing.T) {
|
|||||||
serial.ToTypedMessage(&router.Config{
|
serial.ToTypedMessage(&router.Config{
|
||||||
Rule: []*router.RoutingRule{
|
Rule: []*router.RoutingRule{
|
||||||
{
|
{
|
||||||
Domain: []*router.Domain{
|
Domain: []*routercommon.Domain{
|
||||||
{Type: router.Domain_Full, Value: "test.v2fly.org"},
|
{Type: routercommon.Domain_Full, Value: "test.v2fly.org"},
|
||||||
},
|
},
|
||||||
TargetTag: &router.RoutingRule_Tag{
|
TargetTag: &router.RoutingRule_Tag{
|
||||||
Tag: "reverse",
|
Tag: "reverse",
|
||||||
|
Loading…
Reference in New Issue
Block a user