2016-05-16 03:25:34 -04:00
|
|
|
package dns_test
|
2015-12-06 05:00:10 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2016-05-16 02:09:28 -04:00
|
|
|
"github.com/v2ray/v2ray-core/app"
|
|
|
|
"github.com/v2ray/v2ray-core/app/dispatcher"
|
2016-05-18 02:05:52 -04:00
|
|
|
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
|
2016-05-16 03:25:34 -04:00
|
|
|
. "github.com/v2ray/v2ray-core/app/dns"
|
2016-05-18 02:05:52 -04:00
|
|
|
"github.com/v2ray/v2ray-core/app/proxyman"
|
2016-05-16 02:09:28 -04:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
"github.com/v2ray/v2ray-core/proxy/freedom"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-12-06 05:00:10 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDnsAdd(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2015-12-06 05:00:10 -05:00
|
|
|
|
2016-05-18 02:05:52 -04:00
|
|
|
space := app.NewSpace()
|
|
|
|
|
2016-05-18 11:12:04 -04:00
|
|
|
outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
|
2016-05-22 16:30:08 -04:00
|
|
|
outboundHandlerManager.SetDefaultHandler(freedom.NewFreedomConnection(&freedom.Config{}, space))
|
2016-05-18 02:05:52 -04:00
|
|
|
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
|
|
|
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
2016-05-16 02:09:28 -04:00
|
|
|
|
2016-05-16 03:25:34 -04:00
|
|
|
domain := "local.v2ray.com"
|
|
|
|
server := NewCacheServer(space, &Config{
|
2016-05-16 02:09:28 -04:00
|
|
|
NameServers: []v2net.Destination{
|
|
|
|
v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
|
2015-12-11 06:08:07 -05:00
|
|
|
},
|
|
|
|
})
|
2016-05-18 11:12:04 -04:00
|
|
|
space.BindApp(APP_ID, server)
|
|
|
|
space.Initialize()
|
|
|
|
|
2016-05-18 02:05:52 -04:00
|
|
|
ips := server.Get(domain)
|
2016-05-16 03:25:34 -04:00
|
|
|
assert.Int(len(ips)).Equals(1)
|
2016-05-24 09:29:08 -04:00
|
|
|
assert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
|
2015-12-06 05:00:10 -05:00
|
|
|
}
|