server_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dns_test
  2. import (
  3. "net"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/app"
  6. "github.com/v2ray/v2ray-core/app/dispatcher"
  7. dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
  8. . "github.com/v2ray/v2ray-core/app/dns"
  9. "github.com/v2ray/v2ray-core/app/proxyman"
  10. v2net "github.com/v2ray/v2ray-core/common/net"
  11. "github.com/v2ray/v2ray-core/proxy"
  12. "github.com/v2ray/v2ray-core/proxy/freedom"
  13. "github.com/v2ray/v2ray-core/testing/assert"
  14. )
  15. func TestDnsAdd(t *testing.T) {
  16. assert := assert.On(t)
  17. space := app.NewSpace()
  18. outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
  19. outboundHandlerManager.SetDefaultHandler(freedom.NewFreedomConnection(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{Address: v2net.AnyIP}))
  20. space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
  21. space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
  22. domain := "local.v2ray.com"
  23. server := NewCacheServer(space, &Config{
  24. NameServers: []v2net.Destination{
  25. v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
  26. },
  27. })
  28. space.BindApp(APP_ID, server)
  29. space.Initialize()
  30. ips := server.Get(domain)
  31. assert.Int(len(ips)).Equals(1)
  32. assert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
  33. }