forked from projectdiscovery/retryabledns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
83 lines (61 loc) · 2.02 KB
/
client_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
package retryabledns
import (
"testing"
"github.com/miekg/dns"
"github.com/stretchr/testify/require"
)
func TestConsistentResolve(t *testing.T) {
client, _ := New([]string{"8.8.8.8:53", "1.1.1.1:53"}, 5)
var last string
for i := 0; i < 10; i++ {
d, err := client.Resolve("example.com")
require.Nil(t, err, "could not resolve dns")
if last != "" {
require.Equal(t, last, d.A[0], "got another data from previous")
} else {
last = d.A[0]
}
}
}
func TestUDP(t *testing.T) {
client, _ := New([]string{"1.1.1.1:53", "udp:8.8.8.8"}, 5)
d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA})
require.Nil(t, err)
// From current dig result
require.True(t, len(d.A) > 0)
}
func TestTCP(t *testing.T) {
client, _ := New([]string{"tcp:1.1.1.1:53", "tcp:8.8.8.8"}, 5)
d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA})
require.Nil(t, err)
// From current dig result
require.True(t, len(d.A) > 0)
}
func TestDOH(t *testing.T) {
client, _ := New([]string{"doh:https://doh.opendns.com/dns-query:post", "doh:https://doh.opendns.com/dns-query:get"}, 5)
d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA})
require.Nil(t, err)
// From current dig result
require.True(t, len(d.A) > 0)
}
func TestDOT(t *testing.T) {
client, _ := New([]string{"dot:dns.google:853", "dot:1dot1dot1dot1.cloudflare-dns.com"}, 5)
d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA})
require.Nil(t, err)
// From current dig result
require.True(t, len(d.A) > 0)
}
func TestQueryMultiple(t *testing.T) {
client, _ := New([]string{"8.8.8.8:53", "1.1.1.1:53"}, 5)
d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA, dns.TypeAAAA})
require.Nil(t, err)
// From current dig result
require.True(t, len(d.A) > 0)
require.True(t, len(d.AAAA) > 0)
require.NotZero(t, d.TTL)
}
func TestTrace(t *testing.T) {
client, _ := New([]string{"8.8.8.8:53", "1.1.1.1:53"}, 5)
_, err := client.Trace("www.projectdiscovery.io", dns.TypeA, 100)
require.Nil(t, err, "could not resolve dns")
}