mirror of https://github.com/v2ray/v2ray-core
Test case for inbound detour network
parent
1c6b66eacf
commit
1cec5ac643
|
@ -8,9 +8,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type InboundDetourConfig struct {
|
type InboundDetourConfig struct {
|
||||||
ProtocolValue string
|
ProtocolValue string `json:"protocol"`
|
||||||
PortRangeValue *PortRange
|
PortRangeValue *PortRange `json:"port"`
|
||||||
SettingsValue json.RawMessage
|
SettingsValue json.RawMessage `json:"settings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InboundDetourConfig) Protocol() string {
|
func (this *InboundDetourConfig) Protocol() string {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app/point/config/json"
|
"github.com/v2ray/v2ray-core/app/point/config/json"
|
||||||
|
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/config/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
||||||
|
@ -51,3 +52,22 @@ func TestServerSampleConfig(t *testing.T) {
|
||||||
assert.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
|
assert.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
|
||||||
assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
|
assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDetourConfig(t *testing.T) {
|
||||||
|
assert := unit.Assert(t)
|
||||||
|
|
||||||
|
// TODO: fix for Windows
|
||||||
|
baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
|
||||||
|
|
||||||
|
pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_dns_detour.json"))
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
|
detours := pointConfig.InboundDetours()
|
||||||
|
assert.Int(len(detours)).Equals(1)
|
||||||
|
|
||||||
|
detour := detours[0]
|
||||||
|
assert.String(detour.Protocol()).Equals("dokodemo-door")
|
||||||
|
assert.Uint16(detour.PortRange().From()).Equals(uint16(53))
|
||||||
|
assert.Uint16(detour.PortRange().To()).Equals(uint16(53))
|
||||||
|
assert.Pointer(detour.Settings()).IsNotNil()
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
|
@ -9,17 +10,30 @@ import (
|
||||||
|
|
||||||
type NetworkList []string
|
type NetworkList []string
|
||||||
|
|
||||||
|
func NewNetworkList(networks []string) NetworkList {
|
||||||
|
list := NetworkList(make([]string, len(networks)))
|
||||||
|
for idx, network := range networks {
|
||||||
|
list[idx] = strings.ToLower(strings.TrimSpace(network))
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
func (this *NetworkList) UnmarshalJSON(data []byte) error {
|
func (this *NetworkList) UnmarshalJSON(data []byte) error {
|
||||||
var strList []string
|
var strList []string
|
||||||
err := json.Unmarshal(data, &strList)
|
err := json.Unmarshal(data, &strList)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return err
|
*this = NewNetworkList(strList)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
*this = make([]string, len(strList))
|
|
||||||
for idx, str := range strList {
|
var str string
|
||||||
(*this)[idx] = strings.ToLower(str)
|
err = json.Unmarshal(data, &str)
|
||||||
|
if err == nil {
|
||||||
|
strList := strings.Split(str, ",")
|
||||||
|
*this = NewNetworkList(strList)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return errors.New("Unknown format of network list: " + string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NetworkList) HasNetwork(network v2net.Network) bool {
|
func (this *NetworkList) HasNetwork(network v2net.Network) bool {
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package json
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/v2ray/v2ray-core/testing/unit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestArrayNetworkList(t *testing.T) {
|
||||||
|
assert := unit.Assert(t)
|
||||||
|
|
||||||
|
var list NetworkList
|
||||||
|
err := json.Unmarshal([]byte("[\"Tcp\"]"), &list)
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
assert.Bool(list.HasNetwork("tcp")).IsTrue()
|
||||||
|
assert.Bool(list.HasNetwork("udp")).IsFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStringNetworkList(t *testing.T) {
|
||||||
|
assert := unit.Assert(t)
|
||||||
|
|
||||||
|
var list NetworkList
|
||||||
|
err := json.Unmarshal([]byte("\"TCP, ip\""), &list)
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
assert.Bool(list.HasNetwork("tcp")).IsTrue()
|
||||||
|
assert.Bool(list.HasNetwork("udp")).IsFalse()
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"port": 1080,
|
||||||
|
"log": {
|
||||||
|
"access": ""
|
||||||
|
},
|
||||||
|
"inbound": {
|
||||||
|
"protocol": "socks",
|
||||||
|
"settings": {
|
||||||
|
"auth": "noauth",
|
||||||
|
"udp": false,
|
||||||
|
"ip": "127.0.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outbound": {
|
||||||
|
"protocol": "vmess",
|
||||||
|
"settings": {
|
||||||
|
"vnext": [
|
||||||
|
{
|
||||||
|
"address": "127.0.0.1",
|
||||||
|
"port": 27183,
|
||||||
|
"users": [
|
||||||
|
{"id": "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"}
|
||||||
|
],
|
||||||
|
"network": "tcp"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"inboundDetour": [
|
||||||
|
{
|
||||||
|
"protocol": "dokodemo-door",
|
||||||
|
"port": 53,
|
||||||
|
"settings": {
|
||||||
|
"address": "8.8.8.8",
|
||||||
|
"port": 53,
|
||||||
|
"network": "tcp",
|
||||||
|
"timeout": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue