chinaip_json_test.go 921 B

12345678910111213141516171819202122232425262728293031323334
  1. // +build json
  2. package router_test
  3. import (
  4. "net"
  5. "testing"
  6. . "v2ray.com/core/app/router"
  7. v2net "v2ray.com/core/common/net"
  8. "v2ray.com/core/testing/assert"
  9. )
  10. func makeDestination(ip string) v2net.Destination {
  11. return v2net.TCPDestination(v2net.IPAddress(net.ParseIP(ip)), 80)
  12. }
  13. func TestChinaIPJson(t *testing.T) {
  14. assert := assert.On(t)
  15. rule := ParseRule([]byte(`{
  16. "type": "chinaip",
  17. "outboundTag": "x"
  18. }`))
  19. assert.String(rule.Tag).Equals("x")
  20. cond, err := rule.BuildCondition()
  21. assert.Error(err).IsNil()
  22. assert.Bool(cond.Apply(makeDestination("121.14.1.189"))).IsTrue() // sina.com.cn
  23. assert.Bool(cond.Apply(makeDestination("101.226.103.106"))).IsTrue() // qq.com
  24. assert.Bool(cond.Apply(makeDestination("115.239.210.36"))).IsTrue() // image.baidu.com
  25. assert.Bool(cond.Apply(makeDestination("120.135.126.1"))).IsTrue()
  26. assert.Bool(cond.Apply(makeDestination("8.8.8.8"))).IsFalse()
  27. }