1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 19:06:43 -05:00
v2fly/app/proxy/proxy_test.go

72 lines
1.7 KiB
Go
Raw Normal View History

2016-11-10 17:41:28 -05:00
package proxy_test
import (
"testing"
"v2ray.com/core/app"
. "v2ray.com/core/app/proxy"
"v2ray.com/core/app/proxyman"
2017-01-06 09:32:36 -05:00
_ "v2ray.com/core/app/proxyman/outbound"
2016-12-28 18:58:00 -05:00
"v2ray.com/core/common"
2016-11-10 17:41:28 -05:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/proxy/freedom"
"v2ray.com/core/testing/assert"
"v2ray.com/core/testing/servers/tcp"
"v2ray.com/core/transport/internet"
2016-12-28 18:56:17 -05:00
_ "v2ray.com/core/transport/internet/tcp"
2016-11-10 17:41:28 -05:00
)
func TestProxyDial(t *testing.T) {
assert := assert.On(t)
space := app.NewSpace()
2017-01-06 09:32:36 -05:00
assert.Error(space.AddApp(new(proxyman.OutboundConfig)))
outboundManager := proxyman.OutboundHandlerManagerFromSpace(space)
2016-12-28 18:58:00 -05:00
common.Must(outboundManager.SetHandler("tag", freedom.New(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{
2016-11-10 17:41:28 -05:00
Tag: "tag",
StreamSettings: &internet.StreamConfig{
Protocol: internet.TransportProtocol_TCP,
2016-11-10 17:41:28 -05:00
},
2016-12-28 18:58:00 -05:00
})))
2016-11-10 17:41:28 -05:00
2017-01-06 09:32:36 -05:00
assert.Error(space.AddApp(new(Config))).IsNil()
proxy := OutboundProxyFromSpace(space)
2016-11-10 17:41:28 -05:00
assert.Error(space.Initialize()).IsNil()
xor := func(b []byte) []byte {
for idx, x := range b {
b[idx] = x ^ 'c'
}
return b
}
tcpServer := &tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
assert.Error(err).IsNil()
conn, err := proxy.Dial(v2net.LocalHostIP, dest, internet.DialerOptions{
Stream: &internet.StreamConfig{
Protocol: internet.TransportProtocol_TCP,
2016-11-10 17:41:28 -05:00
},
Proxy: &internet.ProxyConfig{
Tag: "tag",
},
})
assert.Error(err).IsNil()
_, err = conn.Write([]byte{'a', 'b', 'c', 'd'})
assert.Error(err).IsNil()
b := make([]byte, 10)
nBytes, err := conn.Read(b)
assert.Error(err).IsNil()
assert.Bytes(xor(b[:nBytes])).Equals([]byte{'a', 'b', 'c', 'd'})
2016-12-28 18:58:00 -05:00
common.Must(conn.Close())
2016-11-10 17:41:28 -05:00
tcpServer.Close()
}