1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00
v2fly/proxy/freedom/freedom_test.go

74 lines
1.8 KiB
Go
Raw Normal View History

2015-09-24 18:01:02 +02:00
package freedom
import (
2015-11-01 21:32:08 +01:00
"fmt"
2015-09-24 18:01:02 +02:00
"net"
"testing"
"golang.org/x/net/proxy"
2016-01-29 13:39:55 +00:00
v2io "github.com/v2ray/v2ray-core/common/io"
2015-11-01 21:32:08 +01:00
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
2015-09-24 18:01:02 +02:00
_ "github.com/v2ray/v2ray-core/proxy/socks"
2015-11-29 14:45:32 +01:00
"github.com/v2ray/v2ray-core/shell/point"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
2015-10-04 20:22:52 +02:00
"github.com/v2ray/v2ray-core/testing/servers/tcp"
2015-09-24 18:01:02 +02:00
)
2015-10-04 20:22:52 +02:00
func TestSocksTcpConnect(t *testing.T) {
v2testing.Current(t)
2015-11-01 21:32:08 +01:00
port := v2nettesting.PickPort()
2015-10-04 20:22:52 +02:00
data2Send := "Data to be sent to remote"
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 18:01:02 +02:00
2015-11-01 21:32:08 +01:00
pointPort := v2nettesting.PickPort()
2016-01-17 21:43:10 +01:00
config := &point.Config{
Port: pointPort,
InboundConfig: &point.ConnectionConfig{
Protocol: "socks",
Settings: []byte(`{"auth": "noauth"}`),
2015-09-24 18:01:02 +02:00
},
2016-01-17 21:43:10 +01:00
OutboundConfig: &point.ConnectionConfig{
Protocol: "freedom",
Settings: nil,
2015-09-24 18:01:02 +02:00
},
}
2016-01-17 21:43:10 +01:00
point, err := point.NewPoint(config)
2015-09-24 18:01:02 +02:00
assert.Error(err).IsNil()
err = point.Start()
assert.Error(err).IsNil()
2015-11-01 21:32:08 +01:00
socks5Client, err := proxy.SOCKS5("tcp", fmt.Sprintf("127.0.0.1:%d", pointPort), nil, proxy.Direct)
2015-09-24 18:01:02 +02:00
assert.Error(err).IsNil()
2015-11-01 21:32:08 +01:00
targetServer := fmt.Sprintf("127.0.0.1:%d", port)
2015-09-24 18:01:02 +02:00
conn, err := socks5Client.Dial("tcp", targetServer)
assert.Error(err).IsNil()
conn.Write([]byte(data2Send))
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.CloseWrite()
}
2016-01-29 13:39:55 +00:00
dataReturned, err := v2io.ReadFrom(conn, nil)
2015-09-24 18:01:02 +02:00
assert.Error(err).IsNil()
conn.Close()
2015-12-15 16:00:47 +01:00
assert.Bytes(dataReturned.Value).Equals([]byte("Processed: Data to be sent to remote"))
2015-09-24 18:01:02 +02:00
}