Hunter0x7c7
2022-08-11 a82f9cb69f63aaeba40c024960deda7d75b9fece
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package v4_test
 
import (
    "testing"
 
    "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"
)
 
func TestVMessOutbound(t *testing.T) {
    creator := func() cfgcommon.Buildable {
        return new(v4.VMessOutboundConfig)
    }
 
    testassist.RunMultiTestCase(t, []testassist.TestCase{
        {
            Input: `{
                "vnext": [{
                    "address": "127.0.0.1",
                    "port": 80,
                    "users": [
                        {
                            "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
                            "email": "love@v2fly.org",
                            "level": 255
                        }
                    ]
                }]
            }`,
            Parser: testassist.LoadJSON(creator),
            Output: &outbound.Config{
                Receiver: []*protocol.ServerEndpoint{
                    {
                        Address: &net.IPOrDomain{
                            Address: &net.IPOrDomain_Ip{
                                Ip: []byte{127, 0, 0, 1},
                            },
                        },
                        Port: 80,
                        User: []*protocol.User{
                            {
                                Email: "love@v2fly.org",
                                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) {
    creator := func() cfgcommon.Buildable {
        return new(v4.VMessInboundConfig)
    }
 
    testassist.RunMultiTestCase(t, []testassist.TestCase{
        {
            Input: `{
                "clients": [
                    {
                        "id": "27848739-7e62-4138-9fd3-098a63964b6b",
                        "level": 0,
                        "alterId": 16,
                        "email": "love@v2fly.org",
                        "security": "aes-128-gcm"
                    }
                ],
                "default": {
                    "level": 0,
                    "alterId": 32
                },
                "detour": {
                    "to": "tag_to_detour"
                },
                "disableInsecureEncryption": true
            }`,
            Parser: testassist.LoadJSON(creator),
            Output: &inbound.Config{
                User: []*protocol.User{
                    {
                        Level: 0,
                        Email: "love@v2fly.org",
                        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,
            },
        },
    })
}