|  | @@ -5,6 +5,7 @@ import (
 | 
	
		
			
				|  |  |  	"testing"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	v2net "v2ray.com/core/common/net"
 | 
	
		
			
				|  |  | +	"v2ray.com/core/proxy"
 | 
	
		
			
				|  |  |  	"v2ray.com/core/testing/assert"
 | 
	
		
			
				|  |  |  	. "v2ray.com/core/tools/conf"
 | 
	
		
			
				|  |  |  )
 | 
	
	
		
			
				|  | @@ -27,12 +28,22 @@ func TestChinaIPJson(t *testing.T) {
 | 
	
		
			
				|  |  |  	assert.String(rule.Tag).Equals("x")
 | 
	
		
			
				|  |  |  	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()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("121.14.1.189"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue() // sina.com.cn
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("101.226.103.106"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue() // qq.com
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("115.239.210.36"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue() // image.baidu.com
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("120.135.126.1"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(makeDestination("8.8.8.8"))).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("8.8.8.8"), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func TestChinaSitesJson(t *testing.T) {
 | 
	
	
		
			
				|  | @@ -45,12 +56,22 @@ func TestChinaSitesJson(t *testing.T) {
 | 
	
		
			
				|  |  |  	assert.String(rule.Tag).Equals("y")
 | 
	
		
			
				|  |  |  	cond, err := rule.BuildCondition()
 | 
	
		
			
				|  |  |  	assert.Error(err).IsNil()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(makeDomainDestination("v.qq.com"))).IsTrue()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(makeDomainDestination("www.163.com"))).IsTrue()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(makeDomainDestination("ngacn.cc"))).IsTrue()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(makeDomainDestination("12306.cn"))).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("v.qq.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("www.163.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("ngacn.cc"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("12306.cn"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(makeDomainDestination("v2ray.com"))).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("v2ray.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func TestDomainRule(t *testing.T) {
 | 
	
	
		
			
				|  | @@ -69,11 +90,21 @@ func TestDomainRule(t *testing.T) {
 | 
	
		
			
				|  |  |  	assert.Pointer(rule).IsNotNil()
 | 
	
		
			
				|  |  |  	cond, err := rule.BuildCondition()
 | 
	
		
			
				|  |  |  	assert.Error(err).IsNil()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsTrue()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.DomainAddress("www.aabb.com"), 80))).IsFalse()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.DomainAddress("www.12306.cn"), 80))).IsTrue()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.DomainAddress("www.acn.com"), 80))).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("www.ooxx.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("www.aabb.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("www.12306.cn"), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.ParseAddress("www.acn.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func TestIPRule(t *testing.T) {
 | 
	
	
		
			
				|  | @@ -91,8 +122,16 @@ func TestIPRule(t *testing.T) {
 | 
	
		
			
				|  |  |  	assert.Pointer(rule).IsNotNil()
 | 
	
		
			
				|  |  |  	cond, err := rule.BuildCondition()
 | 
	
		
			
				|  |  |  	assert.Error(err).IsNil()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsFalse()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}), 80))).IsTrue()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse()
 | 
	
		
			
				|  |  | -	assert.Bool(cond.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80))).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80),
 | 
	
		
			
				|  |  | +	})).IsFalse()
 | 
	
		
			
				|  |  | +	assert.Bool(cond.Apply(&proxy.SessionInfo{
 | 
	
		
			
				|  |  | +		Destination: v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80),
 | 
	
		
			
				|  |  | +	})).IsTrue()
 | 
	
		
			
				|  |  |  }
 |