1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/proxy/freedom/freedom_test.go

58 lines
1.7 KiB
Go
Raw Normal View History

2016-02-04 05:11:11 -05:00
package freedom_test
2015-09-24 12:01:02 -04:00
import (
"testing"
2016-02-04 05:11:11 -05:00
"github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net"
2015-11-01 15:32:08 -05:00
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
2016-02-04 05:11:11 -05:00
. "github.com/v2ray/v2ray-core/proxy/freedom"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
2015-10-04 14:22:52 -04:00
"github.com/v2ray/v2ray-core/testing/servers/tcp"
2016-02-04 05:11:11 -05:00
"github.com/v2ray/v2ray-core/transport/ray"
2015-09-24 12:01:02 -04:00
)
2016-02-04 05:11:11 -05:00
func TestSinglePacket(t *testing.T) {
v2testing.Current(t)
2015-11-01 15:32:08 -05:00
port := v2nettesting.PickPort()
2015-10-04 14:22:52 -04:00
tcpServer := &tcp.Server{
Port: port,
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
buffer = append(buffer, data...)
return buffer
},
}
_, err := tcpServer.Start()
assert.Error(err).IsNil()
2015-09-24 12:01:02 -04:00
2016-02-04 05:11:11 -05:00
freedom := &FreedomConnection{}
traffic := ray.NewRay()
data2Send := "Data to be sent to remote"
payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send))
2015-09-24 12:01:02 -04:00
2016-04-25 18:13:26 -04:00
go freedom.Dispatch(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), port), payload, traffic)
2016-04-18 12:44:10 -04:00
traffic.InboundInput().Close()
2015-09-24 12:01:02 -04:00
2016-04-18 12:44:10 -04:00
respPayload, err := traffic.InboundOutput().Read()
assert.Error(err).IsNil()
2016-02-04 05:11:11 -05:00
assert.Bytes(respPayload.Value).Equals([]byte("Processed: Data to be sent to remote"))
2015-09-24 12:01:02 -04:00
2016-02-04 05:11:11 -05:00
tcpServer.Close()
}
2015-09-24 12:01:02 -04:00
2016-02-04 05:11:11 -05:00
func TestUnreachableDestination(t *testing.T) {
v2testing.Current(t)
2015-09-24 12:01:02 -04:00
2016-02-04 05:11:11 -05:00
freedom := &FreedomConnection{}
traffic := ray.NewRay()
data2Send := "Data to be sent to remote"
payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send))
2016-04-25 18:13:26 -04:00
err := freedom.Dispatch(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 128), payload, traffic)
2016-02-04 05:11:11 -05:00
assert.Error(err).IsNotNil()
2015-09-24 12:01:02 -04:00
}