mirror of https://github.com/v2ray/v2ray-core
				
				
				
			more tests for router rules
							parent
							
								
									fafc813f0e
								
							
						
					
					
						commit
						3f5bda898c
					
				|  | @ -1,9 +1,12 @@ | ||||||
| package rules | // +build json
 | ||||||
|  | 
 | ||||||
|  | package rules_test | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"net" | 	"net" | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
|  | 	. "github.com/v2ray/v2ray-core/app/router/rules" | ||||||
| 	v2net "github.com/v2ray/v2ray-core/common/net" | 	v2net "github.com/v2ray/v2ray-core/common/net" | ||||||
| 	v2testing "github.com/v2ray/v2ray-core/testing" | 	v2testing "github.com/v2ray/v2ray-core/testing" | ||||||
| 	"github.com/v2ray/v2ray-core/testing/assert" | 	"github.com/v2ray/v2ray-core/testing/assert" | ||||||
|  | @ -16,7 +19,9 @@ func makeDestination(ip string) v2net.Destination { | ||||||
| func TestChinaIP(t *testing.T) { | func TestChinaIP(t *testing.T) { | ||||||
| 	v2testing.Current(t) | 	v2testing.Current(t) | ||||||
| 
 | 
 | ||||||
| 	rule := NewIPv4Matcher(chinaIPNet) | 	rule := ParseRule([]byte(`{ | ||||||
|  |     "type": "chinaip" | ||||||
|  |   }`)) | ||||||
| 	assert.Bool(rule.Apply(makeDestination("121.14.1.189"))).IsTrue()    // sina.com.cn
 | 	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("101.226.103.106"))).IsTrue() // qq.com
 | ||||||
| 	assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue()  // image.baidu.com
 | 	assert.Bool(rule.Apply(makeDestination("115.239.210.36"))).IsTrue()  // image.baidu.com
 | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ func parseChinaSitesRule(data []byte) (*Rule, error) { | ||||||
| 	} | 	} | ||||||
| 	return &Rule{ | 	return &Rule{ | ||||||
| 		Tag:       rawRule.OutboundTag, | 		Tag:       rawRule.OutboundTag, | ||||||
| 		Condition: ChinaSitesConds, | 		Condition: chinaSitesConds, | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -35,7 +35,7 @@ const ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
| 	ChinaSitesConds Condition | 	chinaSitesConds Condition | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
|  | @ -357,5 +357,5 @@ func init() { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	anyConds := AnyCondition(conds) | 	anyConds := AnyCondition(conds) | ||||||
| 	ChinaSitesConds = &anyConds | 	chinaSitesConds = &anyConds | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,10 +1,11 @@ | ||||||
| // +build json
 | // +build json
 | ||||||
| 
 | 
 | ||||||
| package rules | package rules_test | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
|  | 	. "github.com/v2ray/v2ray-core/app/router/rules" | ||||||
| 	v2net "github.com/v2ray/v2ray-core/common/net" | 	v2net "github.com/v2ray/v2ray-core/common/net" | ||||||
| 	v2testing "github.com/v2ray/v2ray-core/testing" | 	v2testing "github.com/v2ray/v2ray-core/testing" | ||||||
| 	"github.com/v2ray/v2ray-core/testing/assert" | 	"github.com/v2ray/v2ray-core/testing/assert" | ||||||
|  | @ -17,7 +18,9 @@ func makeDomainDestination(domain string) v2net.Destination { | ||||||
| func TestChinaSites(t *testing.T) { | func TestChinaSites(t *testing.T) { | ||||||
| 	v2testing.Current(t) | 	v2testing.Current(t) | ||||||
| 
 | 
 | ||||||
| 	rule := ChinaSitesConds | 	rule := ParseRule([]byte(`{ | ||||||
|  |     "type": "chinasites" | ||||||
|  |   }`)) | ||||||
| 	assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue() | 	assert.Bool(rule.Apply(makeDomainDestination("v.qq.com"))).IsTrue() | ||||||
| 	assert.Bool(rule.Apply(makeDomainDestination("www.163.com"))).IsTrue() | 	assert.Bool(rule.Apply(makeDomainDestination("www.163.com"))).IsTrue() | ||||||
| 	assert.Bool(rule.Apply(makeDomainDestination("ngacn.cc"))).IsTrue() | 	assert.Bool(rule.Apply(makeDomainDestination("ngacn.cc"))).IsTrue() | ||||||
|  |  | ||||||
|  | @ -18,7 +18,8 @@ func TestDomainRule(t *testing.T) { | ||||||
|     "type": "field", |     "type": "field", | ||||||
|     "domain": [ |     "domain": [ | ||||||
|       "ooxx.com", |       "ooxx.com", | ||||||
|       "oxox.com" |       "oxox.com", | ||||||
|  |       "regexp:\\.cn$" | ||||||
|     ], |     ], | ||||||
|     "network": "tcp", |     "network": "tcp", | ||||||
|     "outboundTag": "direct" |     "outboundTag": "direct" | ||||||
|  | @ -27,7 +28,8 @@ func TestDomainRule(t *testing.T) { | ||||||
| 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsTrue() | 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsTrue() | ||||||
| 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.aabb.com"), 80))).IsFalse() | 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.aabb.com"), 80))).IsFalse() | ||||||
| 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse() | 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse() | ||||||
| 
 | 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.12306.cn"), 80))).IsTrue() | ||||||
|  | 	assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.acn.com"), 80))).IsFalse() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestIPRule(t *testing.T) { | func TestIPRule(t *testing.T) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 v2ray
						v2ray