2016-01-17 10:20:49 -05:00
|
|
|
package rules
|
2015-12-08 12:19:40 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
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-01-17 10:20:49 -05:00
|
|
|
rule := NewIPv4Matcher(chinaIPNet)
|
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()
|
|
|
|
}
|