2021-06-19 08:45:43 -04:00
|
|
|
package v4_test
|
2019-02-10 13:04:11 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/protocol"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon/testassist"
|
|
|
|
v4 "github.com/v2fly/v2ray-core/v5/infra/conf/v4"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/inbound"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound"
|
2019-02-10 13:04:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVMessOutbound(t *testing.T) {
|
2021-06-19 08:04:50 -04:00
|
|
|
creator := func() cfgcommon.Buildable {
|
2021-06-19 08:45:43 -04:00
|
|
|
return new(v4.VMessOutboundConfig)
|
2019-02-10 13:04:11 -05:00
|
|
|
}
|
|
|
|
|
2021-06-19 08:28:20 -04:00
|
|
|
testassist.RunMultiTestCase(t, []testassist.TestCase{
|
2019-02-10 13:04:11 -05:00
|
|
|
{
|
|
|
|
Input: `{
|
|
|
|
"vnext": [{
|
|
|
|
"address": "127.0.0.1",
|
|
|
|
"port": 80,
|
|
|
|
"users": [
|
|
|
|
{
|
|
|
|
"id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
|
2021-02-16 15:31:50 -05:00
|
|
|
"email": "love@v2fly.org",
|
2019-02-10 13:04:11 -05:00
|
|
|
"level": 255
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
}`,
|
2021-06-19 08:28:20 -04:00
|
|
|
Parser: testassist.LoadJSON(creator),
|
2019-02-10 13:04:11 -05:00
|
|
|
Output: &outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: &net.IPOrDomain{
|
|
|
|
Address: &net.IPOrDomain_Ip{
|
|
|
|
Ip: []byte{127, 0, 0, 1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Port: 80,
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
2021-02-16 15:31:50 -05:00
|
|
|
Email: "love@v2fly.org",
|
2019-02-10 13:04:11 -05:00
|
|
|
Level: 255,
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: "e641f5ad-9397-41e3-bf1a-e8740dfed019",
|
|
|
|
AlterId: 0,
|
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
|
|
|
Type: protocol.SecurityType_AUTO,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVMessInbound(t *testing.T) {
|
2021-06-19 08:04:50 -04:00
|
|
|
creator := func() cfgcommon.Buildable {
|
2021-06-19 08:45:43 -04:00
|
|
|
return new(v4.VMessInboundConfig)
|
2019-02-10 13:04:11 -05:00
|
|
|
}
|
|
|
|
|
2021-06-19 08:28:20 -04:00
|
|
|
testassist.RunMultiTestCase(t, []testassist.TestCase{
|
2019-02-10 13:04:11 -05:00
|
|
|
{
|
|
|
|
Input: `{
|
|
|
|
"clients": [
|
|
|
|
{
|
|
|
|
"id": "27848739-7e62-4138-9fd3-098a63964b6b",
|
|
|
|
"level": 0,
|
|
|
|
"alterId": 16,
|
2021-02-16 15:31:50 -05:00
|
|
|
"email": "love@v2fly.org",
|
2019-02-10 13:04:11 -05:00
|
|
|
"security": "aes-128-gcm"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"default": {
|
|
|
|
"level": 0,
|
|
|
|
"alterId": 32
|
|
|
|
},
|
|
|
|
"detour": {
|
|
|
|
"to": "tag_to_detour"
|
|
|
|
},
|
|
|
|
"disableInsecureEncryption": true
|
|
|
|
}`,
|
2021-06-19 08:28:20 -04:00
|
|
|
Parser: testassist.LoadJSON(creator),
|
2019-02-10 13:04:11 -05:00
|
|
|
Output: &inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Level: 0,
|
2021-02-16 15:31:50 -05:00
|
|
|
Email: "love@v2fly.org",
|
2019-02-10 13:04:11 -05:00
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: "27848739-7e62-4138-9fd3-098a63964b6b",
|
|
|
|
AlterId: 16,
|
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
|
|
|
Type: protocol.SecurityType_AES128_GCM,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Default: &inbound.DefaultConfig{
|
|
|
|
Level: 0,
|
|
|
|
AlterId: 32,
|
|
|
|
},
|
|
|
|
Detour: &inbound.DetourConfig{
|
|
|
|
To: "tag_to_detour",
|
|
|
|
},
|
|
|
|
SecureEncryptionOnly: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|