github.com/v2fly/v2ray-core/v4@v4.45.2/infra/conf/vless_test.go (about)

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