2020-11-25 14:01:53 +03:00
|
|
|
package scenarios
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/app/proxyman"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
|
|
"github.com/xtls/xray-core/common/serial"
|
|
|
|
"github.com/xtls/xray-core/common/uuid"
|
|
|
|
"github.com/xtls/xray-core/core"
|
|
|
|
"github.com/xtls/xray-core/proxy/dokodemo"
|
|
|
|
"github.com/xtls/xray-core/proxy/freedom"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess/inbound"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
|
|
|
"github.com/xtls/xray-core/testing/servers/tcp"
|
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/domainsocket"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/headers/http"
|
|
|
|
tcptransport "github.com/xtls/xray-core/transport/internet/tcp"
|
2020-11-25 14:01:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHTTPConnectionHeader(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 13:12:32 +03:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 14:01:53 +03:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_TCP,
|
|
|
|
Settings: serial.ToTypedMessage(&tcptransport.Config{
|
|
|
|
HeaderSettings: serial.ToTypedMessage(&http.Config{}),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 13:12:32 +03:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 14:01:53 +03:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_TCP,
|
|
|
|
Settings: serial.ToTypedMessage(&tcptransport.Config{
|
|
|
|
HeaderSettings: serial.ToTypedMessage(&http.Config{}),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDomainSocket(t *testing.T) {
|
2020-12-24 22:45:35 +03:00
|
|
|
if runtime.GOOS == "windows" || runtime.GOOS == "android" {
|
2020-12-25 13:53:17 +03:00
|
|
|
t.Skip("Not supported on windows or android")
|
2020-11-25 14:01:53 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
const dsPath = "/tmp/ds_scenario"
|
|
|
|
os.Remove(dsPath)
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
serverConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 13:12:32 +03:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 14:01:53 +03:00
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_DomainSocket,
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_DomainSocket,
|
|
|
|
Settings: serial.ToTypedMessage(&domainsocket.Config{
|
|
|
|
Path: dsPath,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
clientConfig := &core.Config{
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 13:12:32 +03:00
|
|
|
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 14:01:53 +03:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
|
|
StreamSettings: &internet.StreamConfig{
|
|
|
|
Protocol: internet.TransportProtocol_DomainSocket,
|
|
|
|
TransportSettings: []*internet.TransportConfig{
|
|
|
|
{
|
|
|
|
Protocol: internet.TransportProtocol_DomainSocket,
|
|
|
|
Settings: serial.ToTypedMessage(&domainsocket.Config{
|
|
|
|
Path: dsPath,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
common.Must(err)
|
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|