diff --git a/app/router/rules/chinaip_test.go b/app/router/rules/chinaip_test.go index 9848d564..aa36489c 100644 --- a/app/router/rules/chinaip_test.go +++ b/app/router/rules/chinaip_test.go @@ -1,9 +1,12 @@ -package rules +// +build json + +package rules_test import ( "net" "testing" + . "github.com/v2ray/v2ray-core/app/router/rules" v2net "github.com/v2ray/v2ray-core/common/net" v2testing "github.com/v2ray/v2ray-core/testing" "github.com/v2ray/v2ray-core/testing/assert" @@ -16,7 +19,9 @@ func makeDestination(ip string) v2net.Destination { func TestChinaIP(t *testing.T) { v2testing.Current(t) - rule := NewIPv4Matcher(chinaIPNet) + rule := ParseRule([]byte(`{ + "type": "chinaip" + }`)) assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com diff --git a/app/router/rules/chinasites.go b/app/router/rules/chinasites.go index 87882ef0..527f5f8d 100644 --- a/app/router/rules/chinasites.go +++ b/app/router/rules/chinasites.go @@ -16,7 +16,7 @@ func parseChinaSitesRule(data []byte) (*Rule, error) { } return &Rule{ Tag: rawRule.OutboundTag, - Condition: ChinaSitesConds, + Condition: chinaSitesConds, }, nil } @@ -35,7 +35,7 @@ const ( ) var ( - ChinaSitesConds Condition + chinaSitesConds Condition ) func init() { @@ -357,5 +357,5 @@ func init() { } anyConds := AnyCondition(conds) - ChinaSitesConds = &anyConds + chinaSitesConds = &anyConds } diff --git a/app/router/rules/chinasites_test.go b/app/router/rules/chinasites_test.go index 23799bb2..505a5548 100644 --- a/app/router/rules/chinasites_test.go +++ b/app/router/rules/chinasites_test.go @@ -1,10 +1,11 @@ // +build json -package rules +package rules_test import ( "testing" + . "github.com/v2ray/v2ray-core/app/router/rules" v2net "github.com/v2ray/v2ray-core/common/net" v2testing "github.com/v2ray/v2ray-core/testing" "github.com/v2ray/v2ray-core/testing/assert" @@ -17,7 +18,9 @@ func makeDomainDestination(domain string) v2net.Destination { func TestChinaSites(t *testing.T) { v2testing.Current(t) - rule := ChinaSitesConds + rule := ParseRule([]byte(`{ + "type": "chinasites" + }`)) assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue() assert.Bool(rule.Apply(makeDomainDestination("www.163.com"))).IsTrue() assert.Bool(rule.Apply(makeDomainDestination("ngacn.cc"))).IsTrue() diff --git a/app/router/rules/router_config_test.go b/app/router/rules/router_config_test.go index 3d354c44..41478b0e 100644 --- a/app/router/rules/router_config_test.go +++ b/app/router/rules/router_config_test.go @@ -18,7 +18,8 @@ func TestDomainRule(t *testing.T) { "type": "field", "domain": [ "ooxx.com", - "oxox.com" + "oxox.com", + "regexp:\\.cn$" ], "network": "tcp", "outboundTag": "direct" @@ -27,7 +28,8 @@ func TestDomainRule(t *testing.T) { assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsTrue() assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.aabb.com"), 80))).IsFalse() assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse() - + assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.12306.cn"), 80))).IsTrue() + assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.acn.com"), 80))).IsFalse() } func TestIPRule(t *testing.T) {