github.com/EagleQL/Xray-core@v1.4.3/infra/conf/vmess_test.go (about)

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