mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-09 12:58:40 +00:00
API: Add ListInbounds and ListOutbounds (#4723)
This commit is contained in:
parent
d44c78b819
commit
af7a76da67
19 changed files with 791 additions and 140 deletions
|
@ -91,6 +91,20 @@ func (mr *OutboundManagerMockRecorder) GetHandler(arg0 interface{}) *gomock.Call
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHandler", reflect.TypeOf((*OutboundManager)(nil).GetHandler), arg0)
|
||||
}
|
||||
|
||||
// ListHandlers mocks base method
|
||||
func (m *OutboundManager) ListHandlers(arg0 context.Context) []outbound.Handler {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListHandlers", arg0)
|
||||
ret0, _ := ret[0].([]outbound.Handler)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ListHandlers indicates an expected call of ListHandlers
|
||||
func (mr *OutboundManagerMockRecorder) ListHandlers(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListHandlers", reflect.TypeOf((*OutboundManager)(nil).ListHandlers), arg0)
|
||||
}
|
||||
|
||||
// RemoveHandler mocks base method
|
||||
func (m *OutboundManager) RemoveHandler(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/xtls/xray-core/testing/servers/tcp"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
)
|
||||
|
||||
func TestCommanderListenConfigurationItem(t *testing.T) {
|
||||
|
@ -202,6 +203,104 @@ func TestCommanderRemoveHandler(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCommanderListHandlers(t *testing.T) {
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
dest, err := tcpServer.Start()
|
||||
common.Must(err)
|
||||
defer tcpServer.Close()
|
||||
|
||||
clientPort := tcp.PickPort()
|
||||
cmdPort := tcp.PickPort()
|
||||
clientConfig := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&commander.Config{
|
||||
Tag: "api",
|
||||
Service: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&command.Config{}),
|
||||
},
|
||||
}),
|
||||
serial.ToTypedMessage(&router.Config{
|
||||
Rule: []*router.RoutingRule{
|
||||
{
|
||||
InboundTag: []string{"api"},
|
||||
TargetTag: &router.RoutingRule_Tag{
|
||||
Tag: "api",
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
Inbound: []*core.InboundHandlerConfig{
|
||||
{
|
||||
Tag: "d",
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
Networks: []net.Network{net.Network_TCP},
|
||||
}),
|
||||
},
|
||||
{
|
||||
Tag: "api",
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(cmdPort)}},
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
Networks: []net.Network{net.Network_TCP},
|
||||
}),
|
||||
},
|
||||
},
|
||||
Outbound: []*core.OutboundHandlerConfig{
|
||||
{
|
||||
Tag: "default-outbound",
|
||||
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{}),
|
||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := InitializeServerConfigs(clientConfig)
|
||||
common.Must(err)
|
||||
defer CloseAllServers(servers)
|
||||
|
||||
if err := testTCPConn(clientPort, 1024, time.Second*5)(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
|
||||
common.Must(err)
|
||||
defer cmdConn.Close()
|
||||
|
||||
hsClient := command.NewHandlerServiceClient(cmdConn)
|
||||
inboundResp, err := hsClient.ListInbounds(context.Background(), &command.ListInboundsRequest{})
|
||||
common.Must(err)
|
||||
if inboundResp == nil {
|
||||
t.Error("unexpected nil response")
|
||||
}
|
||||
|
||||
if !cmp.Equal(inboundResp.Inbounds, clientConfig.Inbound, protocmp.Transform()) {
|
||||
t.Fatal("inbound response doesn't match config")
|
||||
}
|
||||
|
||||
outboundResp, err := hsClient.ListOutbounds(context.Background(), &command.ListOutboundsRequest{})
|
||||
common.Must(err)
|
||||
if outboundResp == nil {
|
||||
t.Error("unexpected nil response")
|
||||
}
|
||||
|
||||
if !cmp.Equal(outboundResp.Outbounds, clientConfig.Outbound, protocmp.Transform()) {
|
||||
t.Fatal("outbound response doesn't match config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommanderAddRemoveUser(t *testing.T) {
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue