github.com/ipfans/trojan-go@v0.11.0/test/scenario/custom_test.go (about)

     1  package scenario
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/ipfans/trojan-go/common"
     8  	_ "github.com/ipfans/trojan-go/proxy/custom"
     9  	"github.com/ipfans/trojan-go/test/util"
    10  )
    11  
    12  func TestCustom1(t *testing.T) {
    13  	serverPort := common.PickPort("tcp", "127.0.0.1")
    14  	socksPort := common.PickPort("tcp", "127.0.0.1")
    15  	clientData := fmt.Sprintf(`
    16  run-type: custom
    17  
    18  inbound:
    19    node:
    20      - protocol: adapter
    21        tag: adapter
    22        config:
    23          local-addr: 127.0.0.1
    24          local-port: %d
    25      - protocol: socks
    26        tag: socks
    27        config:
    28          local-addr: 127.0.0.1
    29          local-port: %d
    30    path:
    31      -
    32        - adapter
    33        - socks
    34  
    35  outbound:
    36    node:
    37      - protocol: transport
    38        tag: transport
    39        config:
    40          remote-addr: 127.0.0.1
    41          remote-port: %d
    42  
    43      - protocol: tls
    44        tag: tls
    45        config:
    46          ssl:
    47            sni: localhost
    48            key: server.key
    49            cert: server.crt
    50  
    51      - protocol: trojan
    52        tag: trojan
    53        config:
    54          password:
    55            - "12345678"
    56  
    57    path:
    58      - 
    59        - transport
    60        - tls
    61        - trojan
    62  
    63  `, socksPort, socksPort, serverPort)
    64  	serverData := fmt.Sprintf(`
    65  run-type: custom
    66  
    67  inbound:
    68    node:
    69      - protocol: transport
    70        tag: transport
    71        config:
    72          local-addr: 127.0.0.1
    73          local-port: %d
    74          remote-addr: 127.0.0.1
    75          remote-port: %s
    76  
    77      - protocol: tls
    78        tag: tls
    79        config:
    80          ssl:
    81            sni: localhost
    82            key: server.key
    83            cert: server.crt
    84  
    85      - protocol: trojan
    86        tag: trojan
    87        config:
    88          disable-http-check: true
    89          password:
    90            - "12345678"
    91  
    92      - protocol: mux
    93        tag: mux
    94  
    95      - protocol: simplesocks
    96        tag: simplesocks
    97       
    98  
    99    path:
   100      - 
   101        - transport
   102        - tls
   103        - trojan
   104      - 
   105        - transport
   106        - tls
   107        - trojan
   108        - mux
   109        - simplesocks
   110  
   111  outbound:
   112    node:
   113      - protocol: freedom
   114        tag: freedom
   115  
   116    path:
   117      - 
   118        - freedom
   119  
   120  `, serverPort, util.HTTPPort)
   121  
   122  	if !CheckClientServer(clientData, serverData, socksPort) {
   123  		t.Fail()
   124  	}
   125  }
   126  
   127  func TestCustom2(t *testing.T) {
   128  	serverPort := common.PickPort("tcp", "127.0.0.1")
   129  	socksPort := common.PickPort("tcp", "127.0.0.1")
   130  	clientData := fmt.Sprintf(`
   131  run-type: custom
   132  log-level: 0
   133  
   134  inbound:
   135    node:
   136      - protocol: adapter
   137        tag: adapter
   138        config:
   139          local-addr: 127.0.0.1
   140          local-port: %d
   141      - protocol: socks
   142        tag: socks
   143        config:
   144          local-addr: 127.0.0.1
   145          local-port: %d
   146    path:
   147      -
   148        - adapter
   149        - socks
   150  
   151  outbound:
   152    node:
   153      - protocol: transport
   154        tag: transport
   155        config:
   156          remote-addr: 127.0.0.1
   157          remote-port: %d
   158  
   159      - protocol: tls
   160        tag: tls
   161        config:
   162          ssl:
   163            sni: localhost
   164            key: server.key
   165            cert: server.crt
   166  
   167      - protocol: trojan
   168        tag: trojan
   169        config:
   170          password:
   171            - "12345678"
   172  
   173      - protocol: shadowsocks
   174        tag: shadowsocks
   175        config:
   176          remote-addr: 127.0.0.1
   177          remote-port: 80
   178          shadowsocks:
   179            enabled: true
   180            password: "12345678"
   181  
   182      - protocol: websocket
   183        tag: websocket
   184        config:
   185          websocket:
   186            host: localhost
   187            path: /ws
   188  
   189    path:
   190      - 
   191        - transport
   192        - tls
   193        - websocket
   194        - shadowsocks 
   195        - trojan
   196  
   197  `, socksPort, socksPort, serverPort)
   198  	serverData := fmt.Sprintf(`
   199  run-type: custom
   200  log-level: 0
   201  
   202  inbound:
   203    node:
   204      - protocol: transport
   205        tag: transport
   206        config:
   207          local-addr: 127.0.0.1
   208          local-port: %d
   209          remote-addr: 127.0.0.1
   210          remote-port: %s
   211  
   212      - protocol: tls
   213        tag: tls
   214        config:
   215          ssl:
   216            sni: localhost
   217            key: server.key
   218            cert: server.crt
   219  
   220      - protocol: trojan
   221        tag: trojan
   222        config:
   223          disable-http-check: true
   224          password:
   225            - "12345678"
   226  
   227      - protocol: trojan
   228        tag: trojan2
   229        config:
   230          disable-http-check: true
   231          password:
   232            - "12345678"
   233  
   234      - protocol: websocket
   235        tag: websocket
   236        config:
   237          websocket:
   238            enabled: true
   239            host: localhost
   240            path: /ws
   241  
   242      - protocol: mux
   243        tag: mux
   244  
   245      - protocol: simplesocks
   246        tag: simplesocks
   247  
   248      - protocol: shadowsocks
   249        tag: shadowsocks
   250        config:
   251          remote-addr: 127.0.0.1
   252          remote-port: 80
   253          shadowsocks:
   254            enabled: true
   255            password: "12345678"
   256  
   257      - protocol: shadowsocks
   258        tag: shadowsocks2
   259        config:
   260          remote-addr: 127.0.0.1
   261          remote-port: 80
   262          shadowsocks:
   263            enabled: true
   264            password: "12345678"
   265       
   266    path:
   267      - 
   268        - transport
   269        - tls
   270        - shadowsocks 
   271        - trojan
   272      - 
   273        - transport
   274        - tls
   275        - websocket
   276        - shadowsocks2
   277        - trojan2
   278      - 
   279        - transport
   280        - tls
   281        - shadowsocks
   282        - trojan
   283        - mux
   284        - simplesocks
   285  
   286  outbound:
   287    node:
   288      - protocol: freedom
   289        tag: freedom
   290  
   291    path:
   292      - 
   293        - freedom
   294  
   295  `, serverPort, util.HTTPPort)
   296  
   297  	if !CheckClientServer(clientData, serverData, socksPort) {
   298  		t.Fail()
   299  	}
   300  }