1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-18 07:17:32 -05:00
v2fly/app/router/chinaip_json_test.go

35 lines
921 B
Go
Raw Normal View History

2016-02-01 16:30:00 -05:00
// +build json
2016-10-12 10:11:13 -04:00
package router_test
2016-02-01 16:30:00 -05:00
import (
2016-10-11 17:02:44 -04:00
"net"
2016-02-01 16:30:00 -05:00
"testing"
2016-10-12 10:11:13 -04:00
. "v2ray.com/core/app/router"
2016-10-11 17:02:44 -04:00
v2net "v2ray.com/core/common/net"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/testing/assert"
2016-02-01 16:30:00 -05:00
)
2016-10-11 17:02:44 -04:00
func makeDestination(ip string) v2net.Destination {
return v2net.TCPDestination(v2net.IPAddress(net.ParseIP(ip)), 80)
}
2016-02-01 16:30:00 -05:00
func TestChinaIPJson(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-01 16:30:00 -05:00
rule := ParseRule([]byte(`{
"type": "chinaip",
"outboundTag": "x"
}`))
2016-05-24 15:55:46 -04:00
assert.String(rule.Tag).Equals("x")
2016-10-11 17:02:44 -04:00
cond, err := rule.BuildCondition()
assert.Error(err).IsNil()
assert.Bool(cond.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn
assert.Bool(cond.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com
assert.Bool(cond.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com
assert.Bool(cond.Apply(makeDestination("120.135.126.1"))).IsTrue()
2016-02-01 16:30:00 -05:00
2016-10-11 17:02:44 -04:00
assert.Bool(cond.Apply(makeDestination("8.8.8.8"))).IsFalse()
2016-02-01 16:30:00 -05:00
}