-
Notifications
You must be signed in to change notification settings - Fork 2
/
resolver_test.go
92 lines (87 loc) · 2.21 KB
/
resolver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package newdns
import (
"testing"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
)
func TestResolver(t *testing.T) {
ret, err := Query("tcp", "1.1.1.1:53", "example.newdns.256dpi.com.", "A", func(msg *dns.Msg) {
msg.RecursionDesired = true
})
assert.NoError(t, err)
equalJSON(t, &dns.Msg{
MsgHdr: dns.MsgHdr{
Response: true,
RecursionDesired: true,
RecursionAvailable: true,
},
Question: []dns.Question{
{Name: "example.newdns.256dpi.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET},
},
Answer: []dns.RR{
&dns.CNAME{
Hdr: dns.RR_Header{
Name: "example.newdns.256dpi.com.",
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
Ttl: ret.Answer[0].(*dns.CNAME).Hdr.Ttl,
Rdlength: 10,
},
Target: "example.com.",
},
&dns.A{
Hdr: dns.RR_Header{
Name: "example.com.",
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: ret.Answer[1].(*dns.A).Hdr.Ttl,
Rdlength: 4,
},
A: ret.Answer[1].(*dns.A).A,
},
},
}, ret)
addr := "0.0.0.0:53002"
mux := dns.NewServeMux()
mux.Handle("newdns.256dpi.com", Proxy(awsNS[0]+":53", nil))
mux.Handle("example.com", Proxy("a.iana-servers.net:53", nil))
handler := Resolver(mux)
serve(handler, addr, func() {
ret, err := Query("udp", addr, "example.newdns.256dpi.com.", "A", func(msg *dns.Msg) {
msg.RecursionDesired = true
})
assert.NoError(t, err)
equalJSON(t, &dns.Msg{
MsgHdr: dns.MsgHdr{
Response: true,
RecursionDesired: true,
RecursionAvailable: true,
},
Question: []dns.Question{
{Name: "example.newdns.256dpi.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET},
},
Answer: []dns.RR{
&dns.CNAME{
Hdr: dns.RR_Header{
Name: "example.newdns.256dpi.com.",
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
Ttl: ret.Answer[0].(*dns.CNAME).Hdr.Ttl,
Rdlength: 13,
},
Target: "example.com.",
},
&dns.A{
Hdr: dns.RR_Header{
Name: "example.com.",
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: ret.Answer[1].(*dns.A).Hdr.Ttl,
Rdlength: 4,
},
A: ret.Answer[1].(*dns.A).A,
},
},
}, ret)
})
}