1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/testing/scenarios/dns_test.go

100 lines
2.3 KiB
Go
Raw Normal View History

2017-01-27 15:19:46 -05:00
package scenarios
import (
"fmt"
"testing"
2019-02-03 13:46:53 -05:00
"time"
2017-01-27 15:19:46 -05:00
xproxy "golang.org/x/net/proxy"
"v2ray.com/core"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/app/router"
2019-02-02 16:19:30 -05:00
"v2ray.com/core/common"
"v2ray.com/core/common/net"
2017-01-27 15:19:46 -05:00
"v2ray.com/core/common/serial"
"v2ray.com/core/proxy/blackhole"
"v2ray.com/core/proxy/freedom"
"v2ray.com/core/proxy/socks"
"v2ray.com/core/testing/servers/tcp"
)
func TestResolveIP(t *testing.T) {
tcpServer := tcp.Server{
MsgProcessor: xor,
}
dest, err := tcpServer.Start()
2019-02-02 16:19:30 -05:00
common.Must(err)
2017-01-27 15:19:46 -05:00
defer tcpServer.Close()
2018-03-01 05:53:39 -05:00
serverPort := tcp.PickPort()
2017-01-27 15:19:46 -05:00
serverConfig := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&dns.Config{
Hosts: map[string]*net.IPOrDomain{
"google.com": net.NewIPOrDomain(dest.Address),
2017-01-27 15:19:46 -05:00
},
}),
serial.ToTypedMessage(&router.Config{
DomainStrategy: router.Config_IpIfNonMatch,
Rule: []*router.RoutingRule{
{
Cidr: []*router.CIDR{
{
Ip: []byte{127, 0, 0, 0},
Prefix: 8,
},
},
2018-11-07 19:01:53 -05:00
TargetTag: &router.RoutingRule_Tag{
Tag: "direct",
},
2017-01-27 15:19:46 -05:00
},
},
}),
},
Inbound: []*core.InboundHandlerConfig{
2017-01-27 15:19:46 -05:00
{
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
PortRange: net.SinglePortRange(serverPort),
Listen: net.NewIPOrDomain(net.LocalHostIP),
2017-01-27 15:19:46 -05:00
}),
ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
AuthType: socks.AuthType_NO_AUTH,
Accounts: map[string]string{
"Test Account": "Test Password",
},
Address: net.NewIPOrDomain(net.LocalHostIP),
2017-01-27 15:19:46 -05:00
UdpEnabled: false,
}),
},
},
Outbound: []*core.OutboundHandlerConfig{
2017-01-27 15:19:46 -05:00
{
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
},
{
Tag: "direct",
ProxySettings: serial.ToTypedMessage(&freedom.Config{
DomainStrategy: freedom.Config_USE_IP,
}),
},
},
}
2017-05-17 18:39:30 -04:00
servers, err := InitializeServerConfigs(serverConfig)
2019-02-02 16:19:30 -05:00
common.Must(err)
2019-02-03 13:46:53 -05:00
defer CloseAllServers(servers)
2017-01-27 15:19:46 -05:00
{
noAuthDialer, err := xproxy.SOCKS5("tcp", net.TCPDestination(net.LocalHostIP, serverPort).NetAddr(), nil, xproxy.Direct)
2019-02-02 16:19:30 -05:00
common.Must(err)
2017-01-27 15:19:46 -05:00
conn, err := noAuthDialer.Dial("tcp", fmt.Sprintf("google.com:%d", dest.Port))
2019-02-02 16:19:30 -05:00
common.Must(err)
2019-02-03 13:46:53 -05:00
defer conn.Close()
2017-01-27 15:19:46 -05:00
2019-02-03 13:46:53 -05:00
if err := testTCPConn2(conn, 1024, time.Second*5)(); err != nil {
t.Error(err)
}
2017-01-27 15:19:46 -05:00
}
}