test.py 6.69 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

''' ANY query type. '''

61
# ANY to SOA record
62 63 64
resp = knot.dig("flags", "ANY", udp=True)
resp.cmp(bind)

65
# ANY to A record
66 67 68
resp = knot.dig("dns1.flags", "ANY", udp=True)
resp.cmp(bind)

69
# ANY to delegation point
70
resp = knot.dig("sub.flags", "ANY", udp=True)
71
resp.cmp(bind, additional=True)
72

73
# ANY to CNAME record
74 75 76
resp = knot.dig("cname.flags", "ANY", udp=True)
resp.cmp(bind)

77
# ANY to DNAME record
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
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)
98
resp.cmp(bind, additional=True)
99 100 101

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

104
# CNAME leading out
105 106 107
resp = knot.dig("cname-out.flags", "A", udp=True)
resp.cmp(bind)

108 109 110 111 112 113 114 115 116
# 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
117
resp = knot.dig("cname-dname.flags", "A", udp=True)
118 119 120
resp.cmp(bind)

# CNAME leading to DNAME tree (NXDOMAIN)
121
resp = knot.dig("cname-dname-nx.flags", "A", udp=True)
122 123 124
resp.cmp(bind)

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

128 129 130 131 132
# 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.")

133 134 135
''' CNAME in Additional '''

# Leading to existing name
136
resp = knot.dig("cname-mx.flags", "MX", udp=True)
137 138 139
resp.cmp(bind)

# Leading to delegation
140
resp = knot.dig("cname-mx-deleg.flags", "MX", udp=True)
141 142 143
resp.cmp(bind)

# Leading to wildcard-covered name
144
resp = knot.dig("cname-mx-wc.flags", "MX", udp=True)
145 146 147
resp.cmp(bind)

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

151 152 153 154 155 156 157 158 159 160
''' DNAME answers. '''

# DNAME query
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)

161 162 163 164
# DNAME query leading out of zone
resp = knot.dig("a.dname-out.flags", "A", udp=True)
resp.cmp(bind)

165 166 167 168 169 170 171 172
# 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)

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
# 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)

189 190 191 192 193 194
''' Wildcard answers. '''

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

195
# Wildcard leading to A
196 197 198 199 200 201 202
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)

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
# 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
232
resp = knot.dig("a.wildcard.dname.flags", "A", udp=True)
233 234 235
resp.cmp(bind)

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

239
# Wildcard chain to A
240 241 242
resp = knot.dig("a.wildcard-cname.flags", "A", udp=True)
resp.cmp(bind)

243
# Wildcard chain to A (NODATA)
244 245 246
resp = knot.dig("a.wildcard-cname.flags", "TXT", udp=True)
resp.cmp(bind)

247
# Wildcard chain to NS
248
resp = knot.dig("a.wildcard-deleg.flags", "NS", udp=True)
249
resp.cmp(bind, additional=True)
250 251 252 253 254

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

255 256 257 258
# Wildcard leading to CNAME loop
resp = knot.dig("test.loop-entry.flags", "A", udp=True)
resp.cmp(bind)

259 260 261 262
# Wildcard-covered additional record discovery
resp = knot.dig("mx-additional.flags", "MX", udp=True)
resp.cmp(bind)

263 264 265 266
''' Varied case tests. '''

# Negative (case preservation in question)
resp = knot.dig("ANOTHER.world", "SOA", udp=True)
267
resp.check(rcode="REFUSED")
268 269 270 271 272 273 274 275 276 277 278 279
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)

280
t.end()