mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
9 years ago
|
package dns_test
|
||
9 years ago
|
|
||
|
import (
|
||
|
"net"
|
||
|
"testing"
|
||
|
|
||
9 years ago
|
"github.com/v2ray/v2ray-core/app"
|
||
|
"github.com/v2ray/v2ray-core/app/dispatcher"
|
||
9 years ago
|
. "github.com/v2ray/v2ray-core/app/dns"
|
||
9 years ago
|
apptesting "github.com/v2ray/v2ray-core/app/testing"
|
||
9 years ago
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||
9 years ago
|
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
||
9 years ago
|
"github.com/v2ray/v2ray-core/proxy/freedom"
|
||
9 years ago
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||
9 years ago
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||
|
"github.com/v2ray/v2ray-core/transport/ray"
|
||
9 years ago
|
)
|
||
|
|
||
9 years ago
|
type TestDispatcher struct {
|
||
|
freedom *freedom.FreedomConnection
|
||
|
}
|
||
|
|
||
|
func (this *TestDispatcher) DispatchToOutbound(context app.Context, dest v2net.Destination) ray.InboundRay {
|
||
|
direct := ray.NewRay()
|
||
|
|
||
|
go func() {
|
||
|
payload, err := direct.OutboundInput().Read()
|
||
|
if err != nil {
|
||
|
direct.OutboundInput().Release()
|
||
|
direct.OutboundOutput().Release()
|
||
|
return
|
||
|
}
|
||
|
this.freedom.Dispatch(dest, payload, direct)
|
||
|
}()
|
||
|
return direct
|
||
|
}
|
||
|
|
||
9 years ago
|
func TestDnsAdd(t *testing.T) {
|
||
|
v2testing.Current(t)
|
||
|
|
||
9 years ago
|
d := &TestDispatcher{
|
||
|
freedom: &freedom.FreedomConnection{},
|
||
|
}
|
||
|
spaceController := app.NewController()
|
||
|
spaceController.Bind(dispatcher.APP_ID, d)
|
||
|
space := spaceController.ForContext("test")
|
||
|
|
||
9 years ago
|
domain := "local.v2ray.com"
|
||
|
server := NewCacheServer(space, &Config{
|
||
9 years ago
|
NameServers: []v2net.Destination{
|
||
|
v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
|
||
9 years ago
|
},
|
||
|
})
|
||
9 years ago
|
ips := server.Get(&apptesting.Context{
|
||
|
CallerTagValue: "a",
|
||
|
}, domain)
|
||
9 years ago
|
assert.Int(len(ips)).Equals(1)
|
||
|
netassert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
|
||
9 years ago
|
}
|