test.py 7.62 KB
Newer Older
1 2 3 4
#!/usr/bin/env python3

''' For various query processing states. '''

5
from dnstest.utils import *
6
from dnstest.test import Test
7

8
t = Test()
9
knot = t.server("knot")
10
knot.DIG_TIMEOUT = 2
11 12 13 14 15 16 17 18 19 20 21 22 23

bind = t.server("bind")
zone = t.zone("flags.")

t.link(zone, knot)
t.link(zone, bind)

t.start()

''' Negative answers. '''

# Negative (REFUSED)
resp = knot.dig("another.world", "SOA", udp=True)
24
resp.check(rcode="REFUSED", flags="QR", noflags="AA TC AD RA")
25 26 27 28
resp.cmp(bind)

# Negative (NXDOMAIN)
resp = knot.dig("nxdomain.flags", "A", udp=True)
29
resp.check(rcode="NXDOMAIN", flags="QR AA", noflags="TC AD RA")
30 31 32 33
resp.cmp(bind)

''' Positive answers. '''

34 35
# Positive (SOA)
resp = knot.dig("flags", "SOA", udp=True)
36
resp.check(rcode="NOERROR", flags="QR AA", noflags="TC AD RA")
37 38
resp.cmp(bind)

39
# Positive (DATA)
40
resp = knot.dig("dns1.flags", "A", udp=True)
41
resp.check(rcode="NOERROR", flags="QR AA", noflags="TC AD RA")
42 43
resp.cmp(bind)

44
# Positive (NODATA)
45
resp = knot.dig("dns1.flags", "TXT", udp=True)
46
resp.check(rcode="NOERROR", flags="QR AA", noflags="TC AD RA")
47 48 49 50
resp.cmp(bind)

# Positive (REFERRAL)
resp = knot.dig("sub.flags", "NS", udp=True)
51
resp.check(rcode="NOERROR", flags="QR", noflags="AA TC AD RA")
52
resp.cmp(bind, additional=True)
53 54 55

# Positive (REFERRAL, below delegation)
resp = knot.dig("ns.sub.flags", "A", udp=True)
56
resp.check(rcode="NOERROR", flags="QR", noflags="AA TC AD RA")
57
resp.cmp(bind, additional=True)
58

59 60 61 62 63
# Positive (REFERRAL, below delegation, ignoring empty-nonterminal during lookup)
resp = knot.dig("bellow.ns.sub.flags", "A", udp=True)
resp.check(rcode="NOERROR", flags="QR", noflags="AA TC AD RA")
resp.cmp(bind, additional=True)

64 65 66 67 68 69 70 71 72 73
# Positive (NODATA, at delegation, DS type)
resp = knot.dig("ds-sub.flags", "DS", udp=True)
resp.check(rcode="NOERROR", flags="QR AA", noflags="TC AD RA")
resp.cmp(bind, additional=True)

# Positive (REFERRAL, below delegation, DS type)
resp = knot.dig("net.ds-sub.flags", "DS", udp=True)
resp.check(rcode="NOERROR", flags="QR", noflags="AA TC AD RA")
resp.cmp(bind, additional=True)

74 75
''' ANY query type. '''

76
# ANY to SOA record
77 78 79
resp = knot.dig("flags", "ANY", udp=True)
resp.cmp(bind)

80
# ANY to A record
81 82 83
resp = knot.dig("dns1.flags", "ANY", udp=True)
resp.cmp(bind)

84
# ANY to delegation point
85
resp = knot.dig("sub.flags", "ANY", udp=True)
86
resp.cmp(bind, additional=True)
87

88
# ANY to CNAME record
89 90 91
resp = knot.dig("cname.flags", "ANY", udp=True)
resp.cmp(bind)

92
# ANY to DNAME record
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
resp = knot.dig("dname.flags", "ANY", udp=True)
resp.cmp(bind)


''' CNAME answers. '''

# CNAME query
resp = knot.dig("cname.flags", "CNAME", udp=True)
resp.cmp(bind)

# CNAME leading to A
resp = knot.dig("cname.flags", "A", udp=True)
resp.cmp(bind)

# CNAME leading to A (NODATA)
resp = knot.dig("cname.flags", "TXT", udp=True)
resp.cmp(bind)

# CNAME leading to delegation
resp = knot.dig("cname-ns.flags", "NS", udp=True)
113
resp.cmp(bind, additional=True)
114 115

# CNAME leading below delegation
116
resp = knot.dig("cname-below-ns.flags", "A", udp=True)
117
resp.cmp(bind, additional=True)
118

119
# CNAME leading out
120 121 122
resp = knot.dig("cname-out.flags", "A", udp=True)
resp.cmp(bind)

123 124 125 126 127 128 129 130 131
# CNAME leading to wildcard-covered name
resp = knot.dig("cname-wildcard.flags", "A", udp=True)
resp.cmp(bind)

# CNAME leading to wildcard-covered name (NODATA)
resp = knot.dig("cname-wildcard.flags", "TXT", udp=True)
resp.cmp(bind)

# CNAME leading to DNAME tree
132
resp = knot.dig("cname-dname.flags", "A", udp=True)
133 134 135
resp.cmp(bind)

# CNAME leading to DNAME tree (NXDOMAIN)
136
resp = knot.dig("cname-dname-nx.flags", "A", udp=True)
137 138 139
resp.cmp(bind)

# CNAME leading to DNAME tree (NODATA)
140
resp = knot.dig("cname-dname.flags", "TXT", udp=True)
141 142
resp.cmp(bind)

143 144 145 146 147
# Long CNAME loop (Bind truncates the loop at 17 records)
resp = knot.dig("ab.flags", "A", udp=True)
resp.check(rcode="NOERROR")
compare(resp.count(rtype="CNAME", section="answer"), 23, "Count of CNAME records in loop.")

148 149 150 151 152 153 154
''' CNAME in MX EXCHANGE. '''

# Knot puts A/AAAA for MX, SRV, and NS into Additional section of the answer.
# However, when the domain name in RDATA is an in-zone CNAME, it doesn't try
# to solve it. We expect that the resolver will be picking only useful
# information from the Additional section and following a CNAME in Additional
# is not simple.
155 156

# Leading to existing name
157
resp = knot.dig("cname-mx.flags", "MX", udp=True)
158 159 160
resp.cmp(bind)

# Leading to delegation
161
resp = knot.dig("cname-mx-deleg.flags", "MX", udp=True)
162 163 164
resp.cmp(bind)

# Leading to wildcard-covered name
165
resp = knot.dig("cname-mx-wc.flags", "MX", udp=True)
166 167 168
resp.cmp(bind)

# Leading to name outside zone
169
resp = knot.dig("cname-mx-out.flags", "MX", udp=True)
170 171
resp.cmp(bind)

172 173
''' DNAME answers. '''

174
# DNAME query (NODATA)
175 176 177 178 179 180 181
resp = knot.dig("dname.flags", "A", udp=True)
resp.cmp(bind)

# DNAME type query
resp = knot.dig("dname.flags", "DNAME", udp=True)
resp.cmp(bind)

182 183 184 185
# DNAME query leading out of zone
resp = knot.dig("a.dname-out.flags", "A", udp=True)
resp.cmp(bind)

186 187 188 189 190 191 192 193
# DNAME subtree query leading to A
resp = knot.dig("a.dname.flags", "A", udp=True)
resp.cmp(bind)

# DNAME subtree query leading to NODATA
resp = knot.dig("a.dname.flags", "TXT", udp=True)
resp.cmp(bind)

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
# DNAME subtree query leading to CNAME
resp = knot.dig("c.dname.flags", "A", udp=True)
resp.cmp(bind)

# DNAME subtree query leading to CNAME leading to wildcard
resp = knot.dig("d.dname.flags", "A", udp=True)
resp.cmp(bind) 

# DNAME-CNAME-DNAME loop
resp = knot.dig("e.dname.flags", "A", udp=True)
resp.cmp(bind)

# DNAME-DNAME loop
resp = knot.dig("f.dname.flags", "A", udp=True)
resp.cmp(bind)

210 211 212 213 214 215
''' Wildcard answers. '''

# Wildcard query
resp = knot.dig("wildcard.flags", "A", udp=True)
resp.cmp(bind)

216
# Wildcard leading to A
217 218 219 220 221 222 223
resp = knot.dig("a.wildcard.flags", "A", udp=True)
resp.cmp(bind)

# Wildcard leading to A (NODATA)
resp = knot.dig("a.wildcard.flags", "TXT", udp=True)
resp.cmp(bind)

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
# Deeper wildcard usage
resp = knot.dig("a.a.a.wildcard.flags", "A", udp=True)
resp.cmp(bind)

# Asterisk label
resp = knot.dig("sub.*.wildcard.flags", "A", udp=True)
resp.cmp(bind)

# Asterisk label (NODATA)
resp = knot.dig("sub.*.wildcard.flags", "TXT", udp=True)
resp.cmp(bind)

# Wildcard node under asterisk label
resp = knot.dig("*.*.wildcard.flags", "A", udp=True)
resp.cmp(bind)

# Wildcard node under asterisk label (NODATA)
resp = knot.dig("*.*.wildcard.flags", "TXT", udp=True)
resp.cmp(bind)

# Wildcard under asterisk label
resp = knot.dig("a.*.wildcard.flags", "A", udp=True)
resp.cmp(bind)

# Wildcard under asterisk label (NODATA)
resp = knot.dig("a.*.wildcard.flags", "TXT", udp=True)
resp.cmp(bind)

# Wildcard under DNAME subtree
253
resp = knot.dig("a.wildcard.dname.flags", "A", udp=True)
254 255 256
resp.cmp(bind)

# Wildcard under DNAME subtree (NODATA)
257
resp = knot.dig("a.wildcard.dname.flags", "TXT", udp=True)
258 259
resp.cmp(bind)

260
# Wildcard chain to A
261 262 263
resp = knot.dig("a.wildcard-cname.flags", "A", udp=True)
resp.cmp(bind)

264
# Wildcard chain to A (NODATA)
265 266 267
resp = knot.dig("a.wildcard-cname.flags", "TXT", udp=True)
resp.cmp(bind)

268
# Wildcard chain to NS
269
resp = knot.dig("a.wildcard-deleg.flags", "NS", udp=True)
270
resp.cmp(bind, additional=True)
271 272 273 274 275

# Wildcard leading out
resp = knot.dig("a.wildcard-out.flags", "A", udp=True)
resp.cmp(bind)

276 277 278 279
# Wildcard leading to CNAME loop
resp = knot.dig("test.loop-entry.flags", "A", udp=True)
resp.cmp(bind)

280 281 282 283
# Wildcard-covered additional record discovery
resp = knot.dig("mx-additional.flags", "MX", udp=True)
resp.cmp(bind)

284 285 286 287
''' Varied case tests. '''

# Negative (case preservation in question)
resp = knot.dig("ANOTHER.world", "SOA", udp=True)
288
resp.check(rcode="REFUSED")
289 290 291 292 293 294 295 296 297 298 299 300
resp.cmp(bind)

# Positive (varied name in zone) 
resp = knot.dig("dNS1.flags", "A", udp=True)
resp.check(rcode="NOERROR")
resp.cmp(bind)

# Positive (varied zone name)
resp = knot.dig("dns1.flAGs", "A", udp=True)
resp.check(rcode="NOERROR")
resp.cmp(bind)

301
t.end()