chinaip_test.go 884 B

12345678910111213141516171819202122232425262728293031
  1. // +build json
  2. package rules_test
  3. import (
  4. "net"
  5. "testing"
  6. . "github.com/v2ray/v2ray-core/app/router/rules"
  7. v2net "github.com/v2ray/v2ray-core/common/net"
  8. v2testing "github.com/v2ray/v2ray-core/testing"
  9. "github.com/v2ray/v2ray-core/testing/assert"
  10. )
  11. func makeDestination(ip string) v2net.Destination {
  12. return v2net.TCPDestination(v2net.IPAddress(net.ParseIP(ip)), 80)
  13. }
  14. func TestChinaIP(t *testing.T) {
  15. v2testing.Current(t)
  16. rule := ParseRule([]byte(`{
  17. "type": "chinaip"
  18. }`))
  19. assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn
  20. assert.Bool(rule.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com
  21. assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com
  22. assert.Bool(rule.Apply(makeDestination("120.135.126.1"))).IsTrue()
  23. assert.Bool(rule.Apply(makeDestination("8.8.8.8"))).IsFalse()
  24. }