mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
[app/dns] Add tests for idn support (#2213)
Co-authored-by: kallydev <kallydev@gmail.com> Co-authored-by: kallydev <kallydev@gmail.com>
This commit is contained in:
parent
a1ee432d29
commit
32475d9239
@ -18,6 +18,7 @@ import (
|
||||
"github.com/v2fly/v2ray-core/v5/common"
|
||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||
"github.com/v2fly/v2ray-core/v5/common/strmatcher"
|
||||
feature_dns "github.com/v2fly/v2ray-core/v5/features/dns"
|
||||
"github.com/v2fly/v2ray-core/v5/proxy/freedom"
|
||||
"github.com/v2fly/v2ray-core/v5/testing/servers/udp"
|
||||
@ -104,6 +105,16 @@ func (*staticHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||
case q.Name == "Mijia\\ Cloud." && q.Qtype == dns.TypeA:
|
||||
rr, _ := dns.NewRR("Mijia\\ Cloud. IN A 127.0.0.1")
|
||||
ans.Answer = append(ans.Answer, rr)
|
||||
|
||||
case q.Name == "xn--vi8h.ws." /* 🍕.ws */ && q.Qtype == dns.TypeA:
|
||||
rr, err := dns.NewRR("xn--vi8h.ws. IN A 208.100.42.200")
|
||||
common.Must(err)
|
||||
ans.Answer = append(ans.Answer, rr)
|
||||
|
||||
case q.Name == "xn--l8jaaa.com." /* ああああ.com */ && q.Qtype == dns.TypeA:
|
||||
rr, err := dns.NewRR("xn--l8jaaa.com. IN AAAA a:a:a:a::aaaa")
|
||||
common.Must(err)
|
||||
ans.Answer = append(ans.Answer, rr)
|
||||
}
|
||||
}
|
||||
w.WriteMsg(ans)
|
||||
@ -251,6 +262,28 @@ func TestUDPServer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ips, err := client.LookupIP(common.Must2(strmatcher.ToDomain("🍕.ws")).(string))
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error: ", err)
|
||||
}
|
||||
|
||||
if r := cmp.Diff(ips, []net.IP{{208, 100, 42, 200}}); r != "" {
|
||||
t.Fatal(r)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ips, err := client.LookupIP(common.Must2(strmatcher.ToDomain("ああああ.com")).(string))
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error: ", err)
|
||||
}
|
||||
|
||||
if r := cmp.Diff(ips, []net.IP{{0, 0xa, 0, 0xa, 0, 0xa, 0, 0xa, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa}}); r != "" {
|
||||
t.Fatal(r)
|
||||
}
|
||||
}
|
||||
|
||||
dnsServer.Shutdown()
|
||||
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ func ToDomain(pattern string) (string, error) {
|
||||
}
|
||||
if !isASCII {
|
||||
var err error
|
||||
pattern, err = idna.New().ToASCII(pattern)
|
||||
pattern, err = idna.Punycode.ToASCII(pattern)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user