1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/infra/conf/v4/vless_test.go

133 lines
2.7 KiB
Go
Raw Normal View History

package v4_test
2020-07-28 11:00:23 -04:00
import (
2021-06-19 08:04:50 -04:00
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
2021-06-19 08:28:20 -04:00
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/testassist"
"github.com/v2fly/v2ray-core/v4/infra/conf/v4"
2020-07-28 11:00:23 -04:00
"testing"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/protocol"
"github.com/v2fly/v2ray-core/v4/common/serial"
"github.com/v2fly/v2ray-core/v4/proxy/vless"
"github.com/v2fly/v2ray-core/v4/proxy/vless/inbound"
"github.com/v2fly/v2ray-core/v4/proxy/vless/outbound"
2020-07-28 11:00:23 -04:00
)
func TestVLessOutbound(t *testing.T) {
2021-06-19 08:04:50 -04:00
creator := func() cfgcommon.Buildable {
return new(v4.VLessOutboundConfig)
2020-07-28 11:00:23 -04:00
}
2021-06-19 08:28:20 -04:00
testassist.RunMultiTestCase(t, []testassist.TestCase{
2020-07-28 11:00:23 -04:00
{
Input: `{
"vnext": [{
"address": "example.com",
"port": 443,
"users": [
{
"id": "27848739-7e62-4138-9fd3-098a63964b6b",
"encryption": "none",
"level": 0
}
]
}]
}`,
2021-06-19 08:28:20 -04:00
Parser: testassist.LoadJSON(creator),
2020-07-28 11:00:23 -04:00
Output: &outbound.Config{
2020-08-28 03:51:09 -04:00
Vnext: []*protocol.ServerEndpoint{
2020-07-28 11:00:23 -04:00
{
Address: &net.IPOrDomain{
Address: &net.IPOrDomain_Domain{
Domain: "example.com",
},
},
Port: 443,
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&vless.Account{
Id: "27848739-7e62-4138-9fd3-098a63964b6b",
Encryption: "none",
}),
Level: 0,
},
},
},
},
},
},
})
}
func TestVLessInbound(t *testing.T) {
2021-06-19 08:04:50 -04:00
creator := func() cfgcommon.Buildable {
return new(v4.VLessInboundConfig)
2020-07-28 11:00:23 -04:00
}
2021-06-19 08:28:20 -04:00
testassist.RunMultiTestCase(t, []testassist.TestCase{
2020-07-28 11:00:23 -04:00
{
Input: `{
"clients": [
{
"id": "27848739-7e62-4138-9fd3-098a63964b6b",
"level": 0,
"email": "love@v2fly.org"
}
],
"decryption": "none",
2020-08-28 03:51:09 -04:00
"fallbacks": [
{
"dest": 80
},
{
"alpn": "h2",
"dest": "@/dev/shm/domain.socket",
"xver": 2
},
{
"path": "/innerws",
"dest": "serve-ws-none"
}
]
2020-07-28 11:00:23 -04:00
}`,
2021-06-19 08:28:20 -04:00
Parser: testassist.LoadJSON(creator),
2020-07-28 11:00:23 -04:00
Output: &inbound.Config{
2020-08-28 03:51:09 -04:00
Clients: []*protocol.User{
2020-07-28 11:00:23 -04:00
{
Account: serial.ToTypedMessage(&vless.Account{
Id: "27848739-7e62-4138-9fd3-098a63964b6b",
2020-07-28 11:00:23 -04:00
}),
Level: 0,
Email: "love@v2fly.org",
},
},
Decryption: "none",
2020-08-28 03:51:09 -04:00
Fallbacks: []*inbound.Fallback{
{
Alpn: "",
Path: "",
Type: "tcp",
Dest: "127.0.0.1:80",
Xver: 0,
2020-07-28 11:00:23 -04:00
},
2020-08-28 03:51:09 -04:00
{
Alpn: "h2",
Path: "",
Type: "unix",
2020-09-07 04:39:53 -04:00
Dest: "@/dev/shm/domain.socket",
2020-08-28 03:51:09 -04:00
Xver: 2,
},
{
Alpn: "",
Path: "/innerws",
Type: "serve",
Dest: "serve-ws-none",
Xver: 0,
2020-08-03 02:13:26 -04:00
},
2020-07-28 11:00:23 -04:00
},
},
},
})
}