mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-10-07 11:11:38 -07:00
able to redirect to another destination in freedom
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
xproxy "golang.org/x/net/proxy"
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/router"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"v2ray.com/core/proxy/blackhole"
|
||||
"v2ray.com/core/proxy/dokodemo"
|
||||
"v2ray.com/core/proxy/freedom"
|
||||
"v2ray.com/core/proxy/socks"
|
||||
"v2ray.com/core/proxy/vmess"
|
||||
"v2ray.com/core/proxy/vmess/inbound"
|
||||
"v2ray.com/core/proxy/vmess/outbound"
|
||||
@@ -498,3 +500,68 @@ func TestBlackhole(t *testing.T) {
|
||||
|
||||
CloseAllServers()
|
||||
}
|
||||
|
||||
func TestForward(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
dest, err := tcpServer.Start()
|
||||
assert.Error(err).IsNil()
|
||||
defer tcpServer.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_NO_AUTH,
|
||||
Accounts: map[string]string{
|
||||
"Test Account": "Test Password",
|
||||
},
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
UdpEnabled: false,
|
||||
}),
|
||||
},
|
||||
},
|
||||
Outbound: []*proxyman.OutboundHandlerConfig{
|
||||
{
|
||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||
DestinationOverride: &freedom.DestinationOverride{
|
||||
Server: &protocol.ServerEndpoint{
|
||||
Address: v2net.NewIPOrDomain(v2net.LocalHostIP),
|
||||
Port: uint32(dest.Port),
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Error(InitializeServerConfig(serverConfig)).IsNil()
|
||||
|
||||
{
|
||||
noAuthDialer, err := xproxy.SOCKS5("tcp", v2net.TCPDestination(v2net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
|
||||
assert.Error(err).IsNil()
|
||||
conn, err := noAuthDialer.Dial("tcp", "google.com:80")
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
payload := "test payload"
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user