github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/infra/conf/v4/vmess_test.go (about)

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