Exemple #1
0
func TestNormalGetRequest(t *testing.T) {
	assert := assert.On(t)

	testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)

	port := v2nettesting.PickPort()
	httpProxy := NewServer(
		&Config{},
		testPacketDispatcher,
		&proxy.InboundHandlerMeta{
			Address: v2net.LocalHostIP,
			Port:    port,
			StreamSettings: &internet.StreamSettings{
				Type: internet.StreamConnectionTypeRawTCP,
			}})
	defer httpProxy.Close()

	err := httpProxy.Start()
	assert.Error(err).IsNil()
	assert.Port(port).Equals(httpProxy.Port())

	httpClient := &http.Client{}
	resp, err := httpClient.Get("http://127.0.0.1:" + port.String() + "/")
	assert.Error(err).IsNil()
	assert.Int(resp.StatusCode).Equals(400)
}
Exemple #2
0
func TestNormalGetRequest(t *testing.T) {
	v2testing.Current(t)

	testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)

	httpProxy := NewHttpProxyServer(&Config{}, testPacketDispatcher)
	defer httpProxy.Close()

	port := v2nettesting.PickPort()
	err := httpProxy.Listen(port)
	assert.Error(err).IsNil()
	netassert.Port(port).Equals(httpProxy.Port())

	httpClient := &http.Client{}
	resp, err := httpClient.Get("http://127.0.0.1:" + port.String() + "/")
	assert.Error(err).IsNil()
	assert.Int(resp.StatusCode).Equals(400)
}
func TestDokodemoTCP(t *testing.T) {
	v2testing.Current(t)

	testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)

	data2Send := "Data to be sent to remote."

	dokodemo := NewDokodemoDoor(&Config{
		Address: v2net.IPAddress([]byte{1, 2, 3, 4}),
		Port:    128,
		Network: v2net.TCPNetwork.AsList(),
		Timeout: 600,
	}, testPacketDispatcher)
	defer dokodemo.Close()

	port := v2nettesting.PickPort()
	err := dokodemo.Listen(port)
	assert.Error(err).IsNil()
	netassert.Port(port).Equals(dokodemo.Port())

	tcpClient, err := net.DialTCP("tcp", nil, &net.TCPAddr{
		IP:   []byte{127, 0, 0, 1},
		Port: int(port),
		Zone: "",
	})
	assert.Error(err).IsNil()

	tcpClient.Write([]byte(data2Send))
	tcpClient.CloseWrite()

	lastPacket := <-testPacketDispatcher.LastPacket

	response := make([]byte, 1024)
	nBytes, err := tcpClient.Read(response)
	assert.Error(err).IsNil()
	tcpClient.Close()

	assert.StringLiteral("Processed: " + data2Send).Equals(string(response[:nBytes]))
	assert.Bool(lastPacket.Destination().IsTCP()).IsTrue()
	netassert.Address(lastPacket.Destination().Address()).Equals(v2net.IPAddress([]byte{1, 2, 3, 4}))
	netassert.Port(lastPacket.Destination().Port()).Equals(128)
}
func TestDokodemoUDP(t *testing.T) {
	v2testing.Current(t)

	testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)

	data2Send := "Data to be sent to remote."

	dokodemo := NewDokodemoDoor(&Config{
		Address: v2net.IPAddress([]byte{5, 6, 7, 8}),
		Port:    256,
		Network: v2net.UDPNetwork.AsList(),
		Timeout: 600,
	}, testPacketDispatcher)
	defer dokodemo.Close()

	port := v2nettesting.PickPort()
	err := dokodemo.Listen(port)
	assert.Error(err).IsNil()
	netassert.Port(port).Equals(dokodemo.Port())

	udpClient, err := net.DialUDP("udp", nil, &net.UDPAddr{
		IP:   []byte{127, 0, 0, 1},
		Port: int(port),
		Zone: "",
	})
	assert.Error(err).IsNil()

	udpClient.Write([]byte(data2Send))
	udpClient.Close()

	lastPacket := <-testPacketDispatcher.LastPacket

	assert.StringLiteral(data2Send).Equals(string(lastPacket.Chunk().Value))
	assert.Bool(lastPacket.Destination().IsUDP()).IsTrue()
	netassert.Address(lastPacket.Destination().Address()).Equals(v2net.IPAddress([]byte{5, 6, 7, 8}))
	netassert.Port(lastPacket.Destination().Port()).Equals(256)
}