2016-01-24 11:36:55 -05:00
|
|
|
package rules_test
|
2015-12-08 12:19:40 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-24 11:36:55 -05:00
|
|
|
. "github.com/v2ray/v2ray-core/app/router/rules"
|
2015-12-08 12:19:40 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func makeDestination(ip string) v2net.Destination {
|
2015-12-16 17:53:38 -05:00
|
|
|
return v2net.TCPDestination(v2net.IPAddress(net.ParseIP(ip)), 80)
|
2015-12-08 12:19:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChinaIP(t *testing.T) {
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
2016-02-01 16:30:00 -05:00
|
|
|
rule := NewChinaIPRule("tag")
|
2015-12-08 12:19:40 -05:00
|
|
|
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
|
2015-12-12 14:47:29 -05:00
|
|
|
assert.Bool(rule.Apply(makeDestination("120.135.126.1"))).IsTrue()
|
2015-12-08 12:19:40 -05:00
|
|
|
|
|
|
|
assert.Bool(rule.Apply(makeDestination("8.8.8.8"))).IsFalse()
|
|
|
|
}
|