v2ray-core/app/dns/server_test.go

57 lines
1.3 KiB
Go
Raw Normal View History

2016-05-16 07:25:34 +00:00
package dns_test
2015-12-06 10:00:10 +00:00
import (
"net"
"testing"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
dispatchers "v2ray.com/core/app/dispatcher/impl"
. "v2ray.com/core/app/dns"
"v2ray.com/core/app/proxyman"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/proxy/freedom"
"v2ray.com/core/testing/assert"
"v2ray.com/core/transport/internet"
2015-12-06 10:00:10 +00:00
)
func TestDnsAdd(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2015-12-06 10:00:10 +00:00
2016-05-18 06:05:52 +00:00
space := app.NewSpace()
2016-05-18 15:12:04 +00:00
outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
2016-06-14 20:54:08 +00:00
outboundHandlerManager.SetDefaultHandler(
freedom.NewFreedomConnection(
&freedom.Config{},
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
2016-10-02 21:43:58 +00:00
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
2016-06-14 20:54:08 +00:00
},
}))
2016-05-18 06:05:52 +00:00
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
2016-05-16 06:09:28 +00:00
2016-05-16 07:25:34 +00:00
domain := "local.v2ray.com"
server := NewCacheServer(space, &Config{
2016-10-12 16:43:55 +00:00
NameServers: []*v2net.Endpoint{{
2016-09-20 14:05:35 +00:00
Network: v2net.Network_UDP,
2016-10-12 16:43:55 +00:00
Address: &v2net.IPOrDomain{
Address: &v2net.IPOrDomain_Ip{
2016-09-20 14:05:35 +00:00
Ip: []byte{8, 8, 8, 8},
},
},
Port: 53,
}},
})
2016-05-18 15:12:04 +00:00
space.BindApp(APP_ID, server)
space.Initialize()
2016-05-18 06:05:52 +00:00
ips := server.Get(domain)
2016-05-16 07:25:34 +00:00
assert.Int(len(ips)).Equals(1)
2016-05-24 13:29:08 +00:00
assert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
2015-12-06 10:00:10 +00:00
}