1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-16 12:45:24 +00:00
v2fly/app/router/rules/config_json_test.go

52 lines
1.6 KiB
Go
Raw Normal View History

2016-01-24 13:40:46 +00:00
// +build json
package rules_test
import (
"testing"
2016-08-20 18:55:45 +00:00
. "v2ray.com/core/app/router/rules"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
2016-01-24 13:40:46 +00:00
)
2016-01-24 14:36:55 +00:00
func TestDomainRule(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2016-01-24 13:40:46 +00:00
rule := ParseRule([]byte(`{
"type": "field",
"domain": [
"ooxx.com",
2016-01-24 16:36:55 +00:00
"oxox.com",
"regexp:\\.cn$"
2016-01-24 13:40:46 +00:00
],
2016-01-24 14:36:55 +00:00
"network": "tcp",
2016-01-24 13:40:46 +00:00
"outboundTag": "direct"
}`))
assert.Pointer(rule).IsNotNil()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsTrue()
2016-01-24 14:36:55 +00:00
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()
2016-01-24 16:36:55 +00:00
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()
2016-01-24 14:36:55 +00:00
}
func TestIPRule(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2016-01-24 14:36:55 +00:00
rule := ParseRule([]byte(`{
"type": "field",
"ip": [
"10.0.0.0/8",
"192.0.0.0/24"
],
"network": "tcp",
"outboundTag": "direct"
}`))
assert.Pointer(rule).IsNotNil()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsFalse()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}), 80))).IsTrue()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80))).IsTrue()
2016-01-24 13:40:46 +00:00
}