2020-11-25 13:01:53 +02:00
|
|
|
package core_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-04 03:36:16 +02:00
|
|
|
"github.com/xtls/xray-core/app/dispatcher"
|
|
|
|
"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/features/dns"
|
|
|
|
"github.com/xtls/xray-core/features/dns/localdns"
|
|
|
|
_ "github.com/xtls/xray-core/main/distro/all"
|
|
|
|
"github.com/xtls/xray-core/proxy/dokodemo"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess"
|
|
|
|
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
|
|
|
"github.com/xtls/xray-core/testing/servers/tcp"
|
2023-08-10 07:43:34 +03:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-11-25 13:01:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestXrayDependency(t *testing.T) {
|
|
|
|
instance := new(Instance)
|
|
|
|
|
|
|
|
wait := make(chan bool, 1)
|
|
|
|
instance.RequireFeatures(func(d dns.Client) {
|
|
|
|
if d == nil {
|
|
|
|
t.Error("expected dns client fulfilled, but actually nil")
|
|
|
|
}
|
|
|
|
wait <- true
|
|
|
|
})
|
|
|
|
instance.AddFeature(localdns.New())
|
|
|
|
<-wait
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestXrayClose(t *testing.T) {
|
|
|
|
port := tcp.PickPort()
|
|
|
|
|
|
|
|
userID := uuid.New()
|
|
|
|
config := &Config{
|
|
|
|
App: []*serial.TypedMessage{
|
|
|
|
serial.ToTypedMessage(&dispatcher.Config{}),
|
|
|
|
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
|
|
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
|
|
|
},
|
|
|
|
Inbound: []*InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2021-11-12 12:12:32 +02:00
|
|
|
PortList: &net.PortList{
|
|
|
|
Range: []*net.PortRange{net.SinglePortRange(port)},
|
|
|
|
},
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(0),
|
2024-09-19 04:05:59 +03:00
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2020-11-25 13:01:53 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(0),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgBytes, err := proto.Marshal(config)
|
|
|
|
common.Must(err)
|
|
|
|
|
|
|
|
server, err := StartInstance("protobuf", cfgBytes)
|
|
|
|
common.Must(err)
|
|
|
|
server.Close()
|
|
|
|
}
|