-
Notifications
You must be signed in to change notification settings - Fork 105
/
dns_test.go
154 lines (127 loc) · 3.5 KB
/
dns_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package tests
import (
"fmt"
"testing"
"time"
commonIface "github.com/taubyte/tau/core/common"
"github.com/taubyte/tau/dream"
"gotest.tools/v3/assert"
dns "github.com/miekg/dns"
seerClient "github.com/taubyte/tau/clients/p2p/seer"
_ "github.com/taubyte/tau/services/auth"
_ "github.com/taubyte/tau/services/hoarder"
_ "github.com/taubyte/tau/services/monkey"
_ "github.com/taubyte/tau/services/patrick"
_ "github.com/taubyte/tau/services/substrate"
)
var (
fqdn = "testing_website_builder.com."
regexFqdn = "qkfkkvlaw2.g.tau.link."
failedFqdn = "asdhw23.g.tau.link.net."
)
func createDnsClient(net string) *dns.Client {
c := &dns.Client{
Net: net,
}
return c
}
func TestDns(t *testing.T) {
u := dream.New(dream.UniverseConfig{Name: t.Name()})
defer u.Stop()
dnsPort, err := u.PortFor("seer", "dns")
assert.NilError(t, err)
defaultTestPort := fmt.Sprintf("127.0.0.1:%d", dnsPort)
seerClient.DefaultUsageBeaconInterval = 100 * time.Millisecond
seerClient.DefaultAnnounceBeaconInterval = 100 * time.Millisecond
seerClient.DefaultGeoBeaconInterval = 100 * time.Millisecond
err = u.StartWithConfig(&dream.Config{
Services: map[string]commonIface.ServiceConfig{
"seer": {Others: map[string]int{"dns": dnsPort, "mock": 1}},
"tns": {},
"monkey": {},
"patrick": {},
"auth": {},
"substrate": {},
"gateway": {},
},
})
if err != nil {
t.Error(err)
return
}
time.Sleep(15 * time.Second)
// Create Tcp Client
tcpClient := createDnsClient("tcp")
m := new(dns.Msg)
resolver := u.Seer().Resolver()
cname, err := resolver.LookupCNAME(u.Context(), fqdn)
if err != nil {
t.Error(err)
return
}
m.SetQuestion(cname, dns.TypeA)
tcpResp, _, err := tcpClient.Exchange(m, defaultTestPort)
if err != nil {
t.Errorf("Failed tcp exchange error: %v", err)
return
}
if len(tcpResp.Answer) != 1 {
t.Errorf("Expected 1 tcp answers got %d on tcp", len(tcpResp.Answer))
return
}
m.SetQuestion(regexFqdn, dns.TypeA)
tcpResp, _, err = tcpClient.Exchange(m, defaultTestPort)
if err != nil {
t.Errorf("Failed tcp exchange error: %v", err)
return
}
if len(tcpResp.Answer) != 1 {
t.Errorf("Expected 1 tcp for domain regex answers got %d on tcp", len(tcpResp.Answer))
return
}
// Expected to Fail
m.SetQuestion(failedFqdn, dns.TypeA)
tcpResp, _, err = tcpClient.Exchange(m, defaultTestPort)
if err != nil {
t.Errorf("Failed tcp exchange error: %v", err)
return
}
if len(tcpResp.Answer) > 0 {
t.Errorf("The domain %s should have 0 answer reponse on tcp", failedFqdn)
return
}
// Create Udp client
udpClient := createDnsClient("udp")
m = new(dns.Msg)
m.SetQuestion(cname, dns.TypeA)
udpResp, _, err := udpClient.Exchange(m, defaultTestPort)
if err != nil {
t.Errorf("Failed udp exchange error: %v", err)
return
}
if len(udpResp.Answer) != 1 {
t.Errorf("Expected 2 upd answers got %d on udp", len(udpResp.Answer))
return
}
m.SetQuestion(regexFqdn, dns.TypeA)
udpResp, _, err = udpClient.Exchange(m, defaultTestPort)
if err != nil {
t.Errorf("Failed udp exchange error: %v", err)
return
}
if len(udpResp.Answer) != 1 {
t.Errorf("Expected 2 upd for domain regex answers got %d on udp", len(udpResp.Answer))
return
}
// Expected to fail
m.SetQuestion(failedFqdn, dns.TypeA)
udpResp, _, err = udpClient.Exchange(m, defaultTestPort)
if err != nil {
t.Errorf("Failed udp exchange error: %v", err)
return
}
if len(udpResp.Answer) > 0 {
t.Errorf("The domain %s should have 0 answer reponse on udp", failedFqdn)
return
}
}