func TestDokodemoUDP(t *testing.T) { assert := assert.On(t) udpServer := udp.Server{ MsgProcessor: xor, } dest, err := udpServer.Start() assert.Error(err).IsNil() defer udpServer.Close() userID := protocol.NewID(uuid.New()) serverPort := pickPort() serverConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ PortRange: v2net.SinglePortRange(serverPort), Listen: v2net.NewIPOrDomain(v2net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&inbound.Config{ User: []*protocol.User{ { Account: serial.ToTypedMessage(&vmess.Account{ Id: userID.String(), }), }, }, }), }, }, Outbound: []*proxyman.OutboundHandlerConfig{ { ProxySettings: serial.ToTypedMessage(&freedom.Config{}), }, }, } clientPort := uint32(pickPort()) clientPortRange := uint32(5) clientConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ PortRange: &v2net.PortRange{From: clientPort, To: clientPort + clientPortRange}, Listen: v2net.NewIPOrDomain(v2net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ Address: v2net.NewIPOrDomain(dest.Address), Port: uint32(dest.Port), NetworkList: &v2net.NetworkList{ Network: []v2net.Network{v2net.Network_UDP}, }, }), }, }, Outbound: []*proxyman.OutboundHandlerConfig{ { ProxySettings: serial.ToTypedMessage(&outbound.Config{ Receiver: []*protocol.ServerEndpoint{ { Address: v2net.NewIPOrDomain(v2net.LocalHostIP), Port: uint32(serverPort), User: []*protocol.User{ { Account: serial.ToTypedMessage(&vmess.Account{ Id: userID.String(), }), }, }, }, }, }), }, }, } assert.Error(InitializeServerConfig(serverConfig)).IsNil() assert.Error(InitializeServerConfig(clientConfig)).IsNil() for port := clientPort; port <= clientPort+clientPortRange; port++ { conn, err := net.DialUDP("udp", nil, &net.UDPAddr{ IP: []byte{127, 0, 0, 1}, Port: int(port), }) assert.Error(err).IsNil() payload := "dokodemo request." nBytes, err := conn.Write([]byte(payload)) assert.Error(err).IsNil() assert.Int(nBytes).Equals(len(payload)) response := make([]byte, 1024) nBytes, err = conn.Read(response) assert.Error(err).IsNil() assert.Bytes(response[:nBytes]).Equals(xor([]byte(payload))) assert.Error(conn.Close()).IsNil() } CloseAllServers() }
func TestSocksBridageUDP(t *testing.T) { assert := assert.On(t) udpServer := udp.Server{ MsgProcessor: xor, } dest, err := udpServer.Start() assert.Error(err).IsNil() defer udpServer.Close() serverPort := pickPort() serverConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ PortRange: v2net.SinglePortRange(serverPort), Listen: v2net.NewIPOrDomain(v2net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{ AuthType: socks.AuthType_PASSWORD, Accounts: map[string]string{ "Test Account": "Test Password", }, Address: v2net.NewIPOrDomain(v2net.LocalHostIP), UdpEnabled: true, }), }, }, Outbound: []*proxyman.OutboundHandlerConfig{ { ProxySettings: serial.ToTypedMessage(&freedom.Config{}), }, }, } clientPort := pickPort() clientConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ PortRange: v2net.SinglePortRange(clientPort), Listen: v2net.NewIPOrDomain(v2net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ Address: v2net.NewIPOrDomain(dest.Address), Port: uint32(dest.Port), NetworkList: &v2net.NetworkList{ Network: []v2net.Network{v2net.Network_TCP, v2net.Network_UDP}, }, }), }, }, Outbound: []*proxyman.OutboundHandlerConfig{ { ProxySettings: serial.ToTypedMessage(&socks.ClientConfig{ Server: []*protocol.ServerEndpoint{ { Address: v2net.NewIPOrDomain(v2net.LocalHostIP), Port: uint32(serverPort), User: []*protocol.User{ { Account: serial.ToTypedMessage(&socks.Account{ Username: "******", Password: "******", }), }, }, }, }, }), }, }, } assert.Error(InitializeServerConfig(serverConfig)).IsNil() assert.Error(InitializeServerConfig(clientConfig)).IsNil() conn, err := net.DialUDP("udp", nil, &net.UDPAddr{ IP: []byte{127, 0, 0, 1}, Port: int(clientPort), }) assert.Error(err).IsNil() payload := "dokodemo request." nBytes, err := conn.Write([]byte(payload)) assert.Error(err).IsNil() assert.Int(nBytes).Equals(len(payload)) response := make([]byte, 1024) nBytes, err = conn.Read(response) assert.Error(err).IsNil() assert.Bytes(response[:nBytes]).Equals(xor([]byte(payload))) assert.Error(conn.Close()).IsNil() CloseAllServers() }
func TestUDPConnection(t *testing.T) { assert := assert.On(t) udpServer := udp.Server{ MsgProcessor: xor, } dest, err := udpServer.Start() assert.Error(err).IsNil() defer udpServer.Close() clientPort := pickPort() clientConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ PortRange: v2net.SinglePortRange(clientPort), Listen: v2net.NewIPOrDomain(v2net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ Address: v2net.NewIPOrDomain(dest.Address), Port: uint32(dest.Port), NetworkList: &v2net.NetworkList{ Network: []v2net.Network{v2net.Network_UDP}, }, }), }, }, Outbound: []*proxyman.OutboundHandlerConfig{ { ProxySettings: serial.ToTypedMessage(&freedom.Config{}), }, }, } assert.Error(InitializeServerConfig(clientConfig)).IsNil() { conn, err := net.DialUDP("udp", nil, &net.UDPAddr{ IP: []byte{127, 0, 0, 1}, Port: int(clientPort), }) assert.Error(err).IsNil() payload := "dokodemo request." for i := 0; i < 5; i++ { nBytes, err := conn.Write([]byte(payload)) assert.Error(err).IsNil() assert.Int(nBytes).Equals(len(payload)) response := make([]byte, 1024) nBytes, err = conn.Read(response) assert.Error(err).IsNil() assert.Bytes(response[:nBytes]).Equals(xor([]byte(payload))) } assert.Error(conn.Close()).IsNil() } time.Sleep(20 * time.Second) { conn, err := net.DialUDP("udp", nil, &net.UDPAddr{ IP: []byte{127, 0, 0, 1}, Port: int(clientPort), }) assert.Error(err).IsNil() payload := "dokodemo request." nBytes, err := conn.Write([]byte(payload)) assert.Error(err).IsNil() assert.Int(nBytes).Equals(len(payload)) response := make([]byte, 1024) nBytes, err = conn.Read(response) assert.Error(err).IsNil() assert.Bytes(response[:nBytes]).Equals(xor([]byte(payload))) assert.Error(conn.Close()).IsNil() } CloseAllServers() }