github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/infra/conf/v4/vless_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/vless"
    13  	"github.com/v2fly/v2ray-core/v5/proxy/vless/inbound"
    14  	"github.com/v2fly/v2ray-core/v5/proxy/vless/outbound"
    15  )
    16  
    17  func TestVLessOutbound(t *testing.T) {
    18  	creator := func() cfgcommon.Buildable {
    19  		return new(v4.VLessOutboundConfig)
    20  	}
    21  
    22  	testassist.RunMultiTestCase(t, []testassist.TestCase{
    23  		{
    24  			Input: `{
    25  				"vnext": [{
    26  					"address": "example.com",
    27  					"port": 443,
    28  					"users": [
    29  						{
    30  							"id": "27848739-7e62-4138-9fd3-098a63964b6b",
    31  							"encryption": "none",
    32  							"level": 0
    33  						}
    34  					]
    35  				}]
    36  			}`,
    37  			Parser: testassist.LoadJSON(creator),
    38  			Output: &outbound.Config{
    39  				Vnext: []*protocol.ServerEndpoint{
    40  					{
    41  						Address: &net.IPOrDomain{
    42  							Address: &net.IPOrDomain_Domain{
    43  								Domain: "example.com",
    44  							},
    45  						},
    46  						Port: 443,
    47  						User: []*protocol.User{
    48  							{
    49  								Account: serial.ToTypedMessage(&vless.Account{
    50  									Id:         "27848739-7e62-4138-9fd3-098a63964b6b",
    51  									Encryption: "none",
    52  								}),
    53  								Level: 0,
    54  							},
    55  						},
    56  					},
    57  				},
    58  			},
    59  		},
    60  	})
    61  }
    62  
    63  func TestVLessInbound(t *testing.T) {
    64  	creator := func() cfgcommon.Buildable {
    65  		return new(v4.VLessInboundConfig)
    66  	}
    67  
    68  	testassist.RunMultiTestCase(t, []testassist.TestCase{
    69  		{
    70  			Input: `{
    71  				"clients": [
    72  					{
    73  						"id": "27848739-7e62-4138-9fd3-098a63964b6b",
    74  						"level": 0,
    75  						"email": "love@v2fly.org"
    76  					}
    77  				],
    78  				"decryption": "none",
    79  				"fallbacks": [
    80  					{
    81  						"dest": 80
    82  					},
    83  					{
    84  						"alpn": "h2",
    85  						"dest": "@/dev/shm/domain.socket",
    86  						"xver": 2
    87  					},
    88  					{
    89  						"path": "/innerws",
    90  						"dest": "serve-ws-none"
    91  					}
    92  				]
    93  			}`,
    94  			Parser: testassist.LoadJSON(creator),
    95  			Output: &inbound.Config{
    96  				Clients: []*protocol.User{
    97  					{
    98  						Account: serial.ToTypedMessage(&vless.Account{
    99  							Id: "27848739-7e62-4138-9fd3-098a63964b6b",
   100  						}),
   101  						Level: 0,
   102  						Email: "love@v2fly.org",
   103  					},
   104  				},
   105  				Decryption: "none",
   106  				Fallbacks: []*inbound.Fallback{
   107  					{
   108  						Alpn: "",
   109  						Path: "",
   110  						Type: "tcp",
   111  						Dest: "127.0.0.1:80",
   112  						Xver: 0,
   113  					},
   114  					{
   115  						Alpn: "h2",
   116  						Path: "",
   117  						Type: "unix",
   118  						Dest: "@/dev/shm/domain.socket",
   119  						Xver: 2,
   120  					},
   121  					{
   122  						Alpn: "",
   123  						Path: "/innerws",
   124  						Type: "serve",
   125  						Dest: "serve-ws-none",
   126  						Xver: 0,
   127  					},
   128  				},
   129  			},
   130  		},
   131  	})
   132  }