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

more tests for router rules

This commit is contained in:
v2ray 2016-01-24 17:36:55 +01:00
parent fafc813f0e
commit 3f5bda898c
4 changed files with 19 additions and 9 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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()

View File

@ -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) {