Debian Codegraph @

parse_test.go

raw symbols SCIP
1 package dns
2
3 import (
4 "bytes"
5 "crypto/rsa"
6 "encoding/hex"
7 "fmt"
8 "math/rand"
9 "net"
10 "reflect"
11 "regexp"
12 "strconv"
13 "strings"
14 "testing"
15 "testing/quick"
16 )
17
18 func TestDotInName(t *testing.T) {
19 buf := make([]byte, 20)
20 PackDomainName("aa\\.bb.nl.", buf, 0, nil, false)
21 // index 3 must be a real dot
22 if buf[3] != '.' {
23 t.Error("dot should be a real dot")
24 }
25
26 if buf[6] != 2 {
27 t.Error("this must have the value 2")
28 }
29 dom, _, _ := UnpackDomainName(buf, 0)
30 // printing it should yield the backspace again
31 if dom != "aa\\.bb.nl." {
32 t.Error("dot should have been escaped: ", dom)
33 }
34 }
35
36 func TestDotLastInLabel(t *testing.T) {
37 sample := "aa\\..au."
38 buf := make([]byte, 20)
39 _, err := PackDomainName(sample, buf, 0, nil, false)
40 if err != nil {
41 t.Fatalf("unexpected error packing domain: %v", err)
42 }
43 dom, _, _ := UnpackDomainName(buf, 0)
44 if dom != sample {
45 t.Fatalf("unpacked domain `%s' doesn't match packed domain", dom)
46 }
47 }
48
49 func TestTooLongDomainName(t *testing.T) {
50 l := "aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrsssttt."
51 dom := l + l + l + l + l + l + l
52 _, err := NewRR(dom + " IN A 127.0.0.1")
53 if err == nil {
54 t.Error("should be too long")
55 }
56 _, err = NewRR("..com. IN A 127.0.0.1")
57 if err == nil {
58 t.Error("should fail")
59 }
60 }
61
62 func TestDomainName(t *testing.T) {
63 tests := []string{"r\\.gieben.miek.nl.", "www\\.www.miek.nl.",
64 "www.*.miek.nl.", "www.*.miek.nl.",
65 }
66 dbuff := make([]byte, 40)
67
68 for _, ts := range tests {
69 if _, err := PackDomainName(ts, dbuff, 0, nil, false); err != nil {
70 t.Error("not a valid domain name")
71 continue
72 }
73 n, _, err := UnpackDomainName(dbuff, 0)
74 if err != nil {
75 t.Error("failed to unpack packed domain name")
76 continue
77 }
78 if ts != n {
79 t.Errorf("must be equal: in: %s, out: %s", ts, n)
80 }
81 }
82 }
83
84 func TestDomainNameAndTXTEscapes(t *testing.T) {
85 tests := []byte{'.', '(', ')', ';', ' ', '@', '"', '\\', 9, 13, 10, 0, 255}
86 for _, b := range tests {
87 rrbytes := []byte{
88 1, b, 0, // owner
89 byte(TypeTXT >> 8), byte(TypeTXT),
90 byte(ClassINET >> 8), byte(ClassINET),
91 0, 0, 0, 1, // TTL
92 0, 2, 1, b, // Data
93 }
94 rr1, _, err := UnpackRR(rrbytes, 0)
95 if err != nil {
96 panic(err)
97 }
98 s := rr1.String()
99 rr2, err := NewRR(s)
100 if err != nil {
101 t.Errorf("error parsing unpacked RR's string: %v", err)
102 }
103 repacked := make([]byte, len(rrbytes))
104 if _, err := PackRR(rr2, repacked, 0, nil, false); err != nil {
105 t.Errorf("error packing parsed RR: %v", err)
106 }
107 if !bytes.Equal(repacked, rrbytes) {
108 t.Error("packed bytes don't match original bytes")
109 }
110 }
111 }
112
113 func TestTXTEscapeParsing(t *testing.T) {
114 test := [][]string{
115 {`";"`, `";"`},
116 {`\;`, `";"`},
117 {`"\t"`, `"t"`},
118 {`"\r"`, `"r"`},
119 {`"\ "`, `" "`},
120 {`"\;"`, `";"`},
121 {`"\;\""`, `";\""`},
122 {`"\(a\)"`, `"(a)"`},
123 {`"\(a)"`, `"(a)"`},
124 {`"(a\)"`, `"(a)"`},
125 {`"(a)"`, `"(a)"`},
126 {`"\048"`, `"0"`},
127 {`"\` + "\t" + `"`, `"\009"`},
128 {`"\` + "\n" + `"`, `"\010"`},
129 {`"\` + "\r" + `"`, `"\013"`},
130 {`"\` + "\x11" + `"`, `"\017"`},
131 {`"\'"`, `"'"`},
132 }
133 for _, s := range test {
134 rr, err := NewRR(fmt.Sprintf("example.com. IN TXT %v", s[0]))
135 if err != nil {
136 t.Errorf("could not parse %v TXT: %s", s[0], err)
137 continue
138 }
139
140 txt := sprintTxt(rr.(*TXT).Txt)
141 if txt != s[1] {
142 t.Errorf("mismatch after parsing `%v` TXT record: `%v` != `%v`", s[0], txt, s[1])
143 }
144 }
145 }
146
147 func GenerateDomain(r *rand.Rand, size int) []byte {
148 dnLen := size % 70 // artificially limit size so there's less to interpret if a failure occurs
149 var dn []byte
150 done := false
151 for i := 0; i < dnLen && !done; {
152 max := dnLen - i
153 if max > 63 {
154 max = 63
155 }
156 lLen := max
157 if lLen != 0 {
158 lLen = int(r.Int31()) % max
159 }
160 done = lLen == 0
161 if done {
162 continue
163 }
164 l := make([]byte, lLen+1)
165 l[0] = byte(lLen)
166 for j := 0; j < lLen; j++ {
167 l[j+1] = byte(rand.Int31())
168 }
169 dn = append(dn, l...)
170 i += 1 + lLen
171 }
172 return append(dn, 0)
173 }
174
175 func TestDomainQuick(t *testing.T) {
176 r := rand.New(rand.NewSource(0))
177 f := func(l int) bool {
178 db := GenerateDomain(r, l)
179 ds, _, err := UnpackDomainName(db, 0)
180 if err != nil {
181 panic(err)
182 }
183 buf := make([]byte, 255)
184 off, err := PackDomainName(ds, buf, 0, nil, false)
185 if err != nil {
186 t.Errorf("error packing domain: %v", err)
187 t.Errorf(" bytes: %v", db)
188 t.Errorf("string: %v", ds)
189 return false
190 }
191 if !bytes.Equal(db, buf[:off]) {
192 t.Errorf("repacked domain doesn't match original:")
193 t.Errorf("src bytes: %v", db)
194 t.Errorf(" string: %v", ds)
195 t.Errorf("out bytes: %v", buf[:off])
196 return false
197 }
198 return true
199 }
200 if err := quick.Check(f, nil); err != nil {
201 t.Error(err)
202 }
203 }
204
205 func GenerateTXT(r *rand.Rand, size int) []byte {
206 rdLen := size % 300 // artificially limit size so there's less to interpret if a failure occurs
207 var rd []byte
208 for i := 0; i < rdLen; {
209 max := rdLen - 1
210 if max > 255 {
211 max = 255
212 }
213 sLen := max
214 if max != 0 {
215 sLen = int(r.Int31()) % max
216 }
217 s := make([]byte, sLen+1)
218 s[0] = byte(sLen)
219 for j := 0; j < sLen; j++ {
220 s[j+1] = byte(rand.Int31())
221 }
222 rd = append(rd, s...)
223 i += 1 + sLen
224 }
225 return rd
226 }
227
228 func TestParseDirectiveMisc(t *testing.T) {
229 tests := map[string]string{
230 "$ORIGIN miek.nl.\na IN NS b": "a.miek.nl.\t3600\tIN\tNS\tb.miek.nl.",
231 "$TTL 2H\nmiek.nl. IN NS b.": "miek.nl.\t7200\tIN\tNS\tb.",
232 "miek.nl. 1D IN NS b.": "miek.nl.\t86400\tIN\tNS\tb.",
233 `name. IN SOA a6.nstld.com. hostmaster.nic.name. (
234 203362132 ; serial
235 5m ; refresh (5 minutes)
236 5m ; retry (5 minutes)
237 2w ; expire (2 weeks)
238 300 ; minimum (5 minutes)
239 )`: "name.\t3600\tIN\tSOA\ta6.nstld.com. hostmaster.nic.name. 203362132 300 300 1209600 300",
240 ". 3600000 IN NS ONE.MY-ROOTS.NET.": ".\t3600000\tIN\tNS\tONE.MY-ROOTS.NET.",
241 "ONE.MY-ROOTS.NET. 3600000 IN A 192.168.1.1": "ONE.MY-ROOTS.NET.\t3600000\tIN\tA\t192.168.1.1",
242 }
243 for i, o := range tests {
244 rr, err := NewRR(i)
245 if err != nil {
246 t.Error("failed to parse RR: ", err)
247 continue
248 }
249 if rr.String() != o {
250 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
251 }
252 }
253 }
254
255 func TestNSEC(t *testing.T) {
256 nsectests := map[string]string{
257 "nl. IN NSEC3PARAM 1 0 5 30923C44C6CBBB8F": "nl.\t3600\tIN\tNSEC3PARAM\t1 0 5 30923C44C6CBBB8F",
258 "p2209hipbpnm681knjnu0m1febshlv4e.nl. IN NSEC3 1 1 5 30923C44C6CBBB8F P90DG1KE8QEAN0B01613LHQDG0SOJ0TA NS SOA TXT RRSIG DNSKEY NSEC3PARAM": "p2209hipbpnm681knjnu0m1febshlv4e.nl.\t3600\tIN\tNSEC3\t1 1 5 30923C44C6CBBB8F P90DG1KE8QEAN0B01613LHQDG0SOJ0TA NS SOA TXT RRSIG DNSKEY NSEC3PARAM",
259 "localhost.dnssex.nl. IN NSEC www.dnssex.nl. A RRSIG NSEC": "localhost.dnssex.nl.\t3600\tIN\tNSEC\twww.dnssex.nl. A RRSIG NSEC",
260 "localhost.dnssex.nl. IN NSEC www.dnssex.nl. A RRSIG NSEC TYPE65534": "localhost.dnssex.nl.\t3600\tIN\tNSEC\twww.dnssex.nl. A RRSIG NSEC TYPE65534",
261 "localhost.dnssex.nl. IN NSEC www.dnssex.nl. A RRSIG NSec Type65534": "localhost.dnssex.nl.\t3600\tIN\tNSEC\twww.dnssex.nl. A RRSIG NSEC TYPE65534",
262 "44ohaq2njb0idnvolt9ggthvsk1e1uv8.skydns.test. NSEC3 1 0 0 - 44OHAQ2NJB0IDNVOLT9GGTHVSK1E1UVA": "44ohaq2njb0idnvolt9ggthvsk1e1uv8.skydns.test.\t3600\tIN\tNSEC3\t1 0 0 - 44OHAQ2NJB0IDNVOLT9GGTHVSK1E1UVA",
263 }
264 for i, o := range nsectests {
265 rr, err := NewRR(i)
266 if err != nil {
267 t.Error("failed to parse RR: ", err)
268 continue
269 }
270 if rr.String() != o {
271 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
272 }
273 }
274 rr, err := NewRR("nl. IN NSEC3PARAM 1 0 5 30923C44C6CBBB8F")
275 if err != nil {
276 t.Fatal("failed to parse RR: ", err)
277 }
278 if nsec3param, ok := rr.(*NSEC3PARAM); ok {
279 if nsec3param.SaltLength != 8 {
280 t.Fatalf("nsec3param saltlen %d != 8", nsec3param.SaltLength)
281 }
282 } else {
283 t.Fatal("not nsec3 param: ", err)
284 }
285 }
286
287 func TestParseLOC(t *testing.T) {
288 lt := map[string]string{
289 "SW1A2AA.find.me.uk. LOC 51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 30 12.748 N 00 07 39.611 W 0m 0.00m 0.00m 0.00m",
290 "SW1A2AA.find.me.uk. LOC 51 0 0.0 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 00 0.000 N 00 07 39.611 W 0m 0.00m 0.00m 0.00m",
291 "SW1A2AA.find.me.uk. LOC 51 30 12.748 N 00 07 39.611 W 0.00m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 30 12.748 N 00 07 39.611 W 0m 1m 10000m 10m",
292 // Exercise boundary cases
293 "SW1A2AA.find.me.uk. LOC 90 0 0.0 N 180 0 0.0 W 42849672.95 90000000.00m 90000000.00m 90000000.00m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t90 00 0.000 N 180 00 0.000 W 42849672.95m 90000000m 90000000m 90000000m",
294 "SW1A2AA.find.me.uk. LOC 89 59 59.999 N 179 59 59.999 W -100000 90000000.00m 90000000.00m 90000000m": "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t89 59 59.999 N 179 59 59.999 W -100000m 90000000m 90000000m 90000000m",
295 // use float64 to have enough precision.
296 "example.com. LOC 42 21 43.952 N 71 5 6.344 W -24m 1m 200m 10m": "example.com.\t3600\tIN\tLOC\t42 21 43.952 N 71 05 6.344 W -24m 1m 200m 10m",
297 }
298 for i, o := range lt {
299 rr, err := NewRR(i)
300 if err != nil {
301 t.Error("failed to parse RR: ", err)
302 continue
303 }
304 if rr.String() != o {
305 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
306 }
307 }
308
309 // Invalid cases (out of range values)
310 lt = map[string]string{ // Pair of (invalid) RDATA and the bad field name
311 // One of the subfields is out of range.
312 "91 0 0.0 N 00 07 39.611 W 0m": "Latitude",
313 "89 60 0.0 N 00 07 39.611 W 0m": "Latitude",
314 "89 00 60.0 N 00 07 39.611 W 0m": "Latitude",
315 "1 00 -1 N 00 07 39.611 W 0m": "Latitude",
316 "0 0 0.0 N 181 00 0.0 W 0m": "Longitude",
317 "0 0 0.0 N 179 60 0.0 W 0m": "Longitude",
318 "0 0 0.0 N 179 00 60.0 W 0m": "Longitude",
319 "0 0 0.0 N 1 00 -1 W 0m": "Longitude",
320
321 // Each subfield is valid, but resulting latitude would be out of range.
322 "90 01 00.0 N 00 07 39.611 W 0m": "Latitude",
323 "0 0 0.0 N 180 01 0.0 W 0m": "Longitude",
324 }
325 for rdata, field := range lt {
326 _, err := NewRR(fmt.Sprintf("example.com. LOC %s", rdata))
327 if err == nil || !strings.Contains(err.Error(), field) {
328 t.Errorf("expected error to contain %q, but got %v", field, err)
329 }
330 }
331 }
332
333 // this tests a subroutine for the LOC RR parser. It's complicated enough to test separately.
334 func TestStringToCm(t *testing.T) {
335 tests := []struct {
336 // Test description: the input token and the expected return values from stringToCm.
337 token string
338 e uint8
339 m uint8
340 ok bool
341 }{
342 {"100", 4, 1, true},
343 {"0100", 4, 1, true}, // leading 0 (allowed)
344 {"100.99", 4, 1, true},
345 {"90000000", 9, 9, true},
346 {"90000000.00", 9, 9, true},
347 {"0", 0, 0, true},
348 {"0.00", 0, 0, true},
349 {"0.01", 0, 1, true},
350 {".01", 0, 1, true}, // empty 'meter' part (allowed)
351 {"0.1", 1, 1, true},
352
353 // out of range (too large)
354 {"90000001", 0, 0, false},
355 {"90000000.01", 0, 0, false},
356
357 // more than 2 digits in 'cmeter' part
358 {"0.000", 0, 0, false},
359 {"0.001", 0, 0, false},
360 {"0.999", 0, 0, false},
361 // with plus or minus sign (disallowed)
362 {"-100", 0, 0, false},
363 {"+100", 0, 0, false},
364 {"0.-10", 0, 0, false},
365 {"0.+10", 0, 0, false},
366 {"0a.00", 0, 0, false}, // invalid string for 'meter' part
367 {".1x", 0, 0, false}, // invalid string for 'cmeter' part
368 {".", 0, 0, false}, // empty 'cmeter' part (disallowed)
369 {"1.", 0, 0, false}, // ditto
370 {"m", 0, 0, false}, // only the "m" suffix
371 }
372 for _, tc := range tests {
373 tc := tc
374 t.Run(tc.token, func(t *testing.T) {
375 // In all cases the expected result is the same with or without the 'm' suffix.
376 // So we test both cases using the same test code.
377 for _, sfx := range []string{"", "m"} {
378 token := tc.token + sfx
379 e, m, ok := stringToCm(token)
380 if ok != tc.ok {
381 t.Fatal("unexpected validation result")
382 }
383 if m != tc.m {
384 t.Fatalf("Expected %d, got %d", tc.m, m)
385 }
386 if e != tc.e {
387 t.Fatalf("Expected %d, got %d", tc.e, e)
388 }
389 }
390 })
391 }
392 }
393
394 func TestParseDS(t *testing.T) {
395 dt := map[string]string{
396 "example.net. 3600 IN DS 40692 12 3 22261A8B0E0D799183E35E24E2AD6BB58533CBA7E3B14D659E9CA09B 2071398F": "example.net.\t3600\tIN\tDS\t40692 12 3 22261A8B0E0D799183E35E24E2AD6BB58533CBA7E3B14D659E9CA09B2071398F",
397 }
398 for i, o := range dt {
399 rr, err := NewRR(i)
400 if err != nil {
401 t.Error("failed to parse RR: ", err)
402 continue
403 }
404 if rr.String() != o {
405 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
406 }
407 }
408 }
409
410 func TestQuotes(t *testing.T) {
411 tests := map[string]string{
412 `t.example.com. IN TXT "a bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a bc\"",
413 `t.example.com. IN TXT "a
414 bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a\\010 bc\"",
415 `t.example.com. IN TXT ""`: "t.example.com.\t3600\tIN\tTXT\t\"\"",
416 `t.example.com. IN TXT "a"`: "t.example.com.\t3600\tIN\tTXT\t\"a\"",
417 `t.example.com. IN TXT "aa"`: "t.example.com.\t3600\tIN\tTXT\t\"aa\"",
418 `t.example.com. IN TXT "aaa" ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
419 `t.example.com. IN TXT "abc" "DEF"`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
420 `t.example.com. IN TXT "abc" ( "DEF" )`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
421 `t.example.com. IN TXT aaa ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
422 `t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\" \"aaa\"",
423 `t.example.com. IN TXT aaa aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\" \"aaa\"",
424 `t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
425 "cid.urn.arpa. NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.": "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.",
426 "cid.urn.arpa. NAPTR 100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.": "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.",
427 "cid.urn.arpa. NAPTR 100 50 \"s\" \"http+I2L+I2C+I2R\" \"\" _http._tcp.gatech.edu.": "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"http+I2L+I2C+I2R\" \"\" _http._tcp.gatech.edu.",
428 "cid.urn.arpa. NAPTR 100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .": "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 10 \"\" \"\" \"/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i\" .",
429 }
430 for i, o := range tests {
431 rr, err := NewRR(i)
432 if err != nil {
433 t.Error("failed to parse RR: ", err)
434 continue
435 }
436 if rr.String() != o {
437 t.Errorf("`%s' should be equal to\n`%s', but is\n`%s'", i, o, rr.String())
438 }
439 }
440 }
441
442 func TestParseClass(t *testing.T) {
443 tests := map[string]string{
444 "t.example.com. IN A 127.0.0.1": "t.example.com. 3600 IN A 127.0.0.1",
445 "t.example.com. CS A 127.0.0.1": "t.example.com. 3600 CS A 127.0.0.1",
446 "t.example.com. CH A 127.0.0.1": "t.example.com. 3600 CH A 127.0.0.1",
447 // ClassANY can not occur in zone files
448 // "t.example.com. ANY A 127.0.0.1": "t.example.com. 3600 ANY A 127.0.0.1",
449 "t.example.com. NONE A 127.0.0.1": "t.example.com. 3600 NONE A 127.0.0.1",
450 "t.example.com. CLASS255 A 127.0.0.1": "t.example.com. 3600 CLASS255 A 127.0.0.1",
451 }
452 for i, o := range tests {
453 rr, err := NewRR(i)
454 if err != nil {
455 t.Error("failed to parse RR: ", err)
456 continue
457 }
458 if rr.String() != o {
459 t.Errorf("`%s' should be equal to\n`%s', but is\n`%s'", i, o, rr.String())
460 }
461 }
462 }
463
464 func TestBrace(t *testing.T) {
465 tests := map[string]string{
466 "(miek.nl.) 3600 IN A 127.0.1.1": "miek.nl.\t3600\tIN\tA\t127.0.1.1",
467 "miek.nl. (3600) IN MX (10) elektron.atoom.net.": "miek.nl.\t3600\tIN\tMX\t10 elektron.atoom.net.",
468 `miek.nl. IN (
469 3600 A 127.0.0.1)`: "miek.nl.\t3600\tIN\tA\t127.0.0.1",
470 "(miek.nl.) (A) (127.0.2.1)": "miek.nl.\t3600\tIN\tA\t127.0.2.1",
471 "miek.nl A 127.0.3.1": "miek.nl.\t3600\tIN\tA\t127.0.3.1",
472 "_ssh._tcp.local. 60 IN (PTR) stora._ssh._tcp.local.": "_ssh._tcp.local.\t60\tIN\tPTR\tstora._ssh._tcp.local.",
473 "miek.nl. NS ns.miek.nl": "miek.nl.\t3600\tIN\tNS\tns.miek.nl.",
474 `(miek.nl.) (
475 (IN)
476 (AAAA)
477 (::1) )`: "miek.nl.\t3600\tIN\tAAAA\t::1",
478 `(miek.nl.) (
479 (IN)
480 (AAAA)
481 (::1))`: "miek.nl.\t3600\tIN\tAAAA\t::1",
482 "miek.nl. IN AAAA ::2": "miek.nl.\t3600\tIN\tAAAA\t::2",
483 `((m)(i)ek.(n)l.) (SOA) (soa.) (soa.) (
484 2009032802 ; serial
485 21600 ; refresh (6 hours)
486 7(2)00 ; retry (2 hours)
487 604()800 ; expire (1 week)
488 3600 ; minimum (1 hour)
489 )`: "miek.nl.\t3600\tIN\tSOA\tsoa. soa. 2009032802 21600 7200 604800 3600",
490 "miek\\.nl. IN A 127.0.0.10": "miek\\.nl.\t3600\tIN\tA\t127.0.0.10",
491 "miek.nl. IN A 127.0.0.11": "miek.nl.\t3600\tIN\tA\t127.0.0.11",
492 "miek.nl. A 127.0.0.12": "miek.nl.\t3600\tIN\tA\t127.0.0.12",
493 `miek.nl. 86400 IN SOA elektron.atoom.net. miekg.atoom.net. (
494 2009032802 ; serial
495 21600 ; refresh (6 hours)
496 7200 ; retry (2 hours)
497 604800 ; expire (1 week)
498 3600 ; minimum (1 hour)
499 )`: "miek.nl.\t86400\tIN\tSOA\telektron.atoom.net. miekg.atoom.net. 2009032802 21600 7200 604800 3600",
500 }
501 for i, o := range tests {
502 rr, err := NewRR(i)
503 if err != nil {
504 t.Errorf("failed to parse RR: %v\n\t%s", err, i)
505 continue
506 }
507 if rr.String() != o {
508 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
509 }
510 }
511 }
512
513 func TestParseFailure(t *testing.T) {
514 tests := []string{"miek.nl. IN A 327.0.0.1",
515 "miek.nl. IN AAAA ::x",
516 "miek.nl. IN MX a0 miek.nl.",
517 "miek.nl aap IN MX mx.miek.nl.",
518 "miek.nl 200 IN mxx 10 mx.miek.nl.",
519 "miek.nl. inn MX 10 mx.miek.nl.",
520 // "miek.nl. IN CNAME ", // actually valid nowadays, zero size rdata
521 "miek.nl. IN CNAME ..",
522 "miek.nl. PA MX 10 miek.nl.",
523 "miek.nl. ) IN MX 10 miek.nl.",
524 }
525
526 for _, s := range tests {
527 _, err := NewRR(s)
528 if err == nil {
529 t.Errorf("should have triggered an error: \"%s\"", s)
530 }
531 }
532 }
533
534 func TestOmittedTTL(t *testing.T) {
535 zone := `
536 $ORIGIN example.com.
537 example.com. 42 IN SOA ns1.example.com. hostmaster.example.com. 1 86400 60 86400 3600 ; TTL=42 SOA
538 example.com. NS 2 ; TTL=42 absolute owner name
539 @ MD 3 ; TTL=42 current-origin owner name
540 MF 4 ; TTL=42 leading-space implied owner name
541 43 TYPE65280 \# 1 05 ; TTL=43 implied owner name explicit TTL
542 MB 6 ; TTL=43 leading-tab implied owner name
543 $TTL 1337
544 example.com. 88 MG 7 ; TTL=88 explicit TTL
545 example.com. MR 8 ; TTL=1337 after first $TTL
546 $TTL 314
547 1 TXT 9 ; TTL=1 implied owner name explicit TTL
548 example.com. DNAME 10 ; TTL=314 after second $TTL
549 `
550 reCaseFromComment := regexp.MustCompile(`TTL=(\d+)\s+(.*)`)
551 z := NewZoneParser(strings.NewReader(zone), "", "")
552 var i int
553
554 for rr, ok := z.Next(); ok; rr, ok = z.Next() {
555 i++
556 expected := reCaseFromComment.FindStringSubmatch(z.Comment())
557 if len(expected) != 3 {
558 t.Errorf("regexp didn't match for record %d", i)
559 continue
560 }
561 expectedTTL, _ := strconv.ParseUint(expected[1], 10, 32)
562 ttl := rr.Header().Ttl
563 if ttl != uint32(expectedTTL) {
564 t.Errorf("%s: expected TTL %d, got %d", expected[2], expectedTTL, ttl)
565 }
566 }
567 if err := z.Err(); err != nil {
568 t.Error(err)
569 }
570 if i != 10 {
571 t.Errorf("expected %d records, got %d", 5, i)
572 }
573 }
574
575 func TestRelativeNameErrors(t *testing.T) {
576 var badZones = []struct {
577 label string
578 zoneContents string
579 expectedErr string
580 }{
581 {
582 "relative owner name without origin",
583 "example.com 3600 IN SOA ns.example.com. hostmaster.example.com. 1 86400 60 86400 3600",
584 "bad owner name",
585 },
586 {
587 "relative owner name in RDATA",
588 "example.com. 3600 IN SOA ns hostmaster 1 86400 60 86400 3600",
589 "bad SOA Ns",
590 },
591 {
592 "origin reference without origin",
593 "@ 3600 IN SOA ns.example.com. hostmaster.example.com. 1 86400 60 86400 3600",
594 "bad owner name",
595 },
596 {
597 "relative owner name in $INCLUDE",
598 "$INCLUDE file.db example.com",
599 "bad origin name",
600 },
601 {
602 "relative owner name in $ORIGIN",
603 "$ORIGIN example.com",
604 "bad origin name",
605 },
606 }
607 for _, errorCase := range badZones {
608 z := NewZoneParser(strings.NewReader(errorCase.zoneContents), "", "")
609 z.Next()
610 if err := z.Err(); err == nil {
611 t.Errorf("%s: expected error, got nil", errorCase.label)
612 } else if !strings.Contains(err.Error(), errorCase.expectedErr) {
613 t.Errorf("%s: expected error `%s`, got `%s`", errorCase.label, errorCase.expectedErr, err)
614 }
615 }
616 }
617
618 func TestHIP(t *testing.T) {
619 h := `www.example.com. IN HIP ( 2 200100107B1A74DF365639CC39F1D578
620 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p
621 9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQ
622 b1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D
623 rvs1.example.com.
624 rvs2.example.com. )`
625 rr, err := NewRR(h)
626 if err != nil {
627 t.Fatalf("failed to parse RR: %v", err)
628 }
629 msg := new(Msg)
630 msg.Answer = []RR{rr, rr}
631 bytes, err := msg.Pack()
632 if err != nil {
633 t.Fatalf("failed to pack msg: %v", err)
634 }
635 if err := msg.Unpack(bytes); err != nil {
636 t.Fatalf("failed to unpack msg: %v", err)
637 }
638 if len(msg.Answer) != 2 {
639 t.Fatalf("2 answers expected: %v", msg)
640 }
641 for i, rr := range msg.Answer {
642 rr := rr.(*HIP)
643 if l := len(rr.RendezvousServers); l != 2 {
644 t.Fatalf("2 servers expected, only %d in record %d:\n%v", l, i, msg)
645 }
646 for j, s := range []string{"rvs1.example.com.", "rvs2.example.com."} {
647 if rr.RendezvousServers[j] != s {
648 t.Fatalf("expected server %d of record %d to be %s:\n%v", j, i, s, msg)
649 }
650 }
651 }
652 }
653
654 // Test with no known RR on the line
655 func TestLineNumberError2(t *testing.T) {
656 tests := map[string]string{
657 "example.com. 1000 SO master.example.com. admin.example.com. 1 4294967294 4294967293 4294967295 100": "dns: expecting RR type or class, not this...: \"SO\" at line: 1:21",
658 "example.com 1000 IN TALINK a.example.com. b..example.com.": "dns: bad TALINK NextName: \"b..example.com.\" at line: 1:57",
659 "example.com 1000 IN TALINK ( a.example.com. b..example.com. )": "dns: bad TALINK NextName: \"b..example.com.\" at line: 1:60",
660 `example.com 1000 IN TALINK ( a.example.com.
661 bb..example.com. )`: "dns: bad TALINK NextName: \"bb..example.com.\" at line: 2:18",
662 // This is a bug, it should report an error on line 1, but the new is already processed.
663 `example.com 1000 IN TALINK ( a.example.com. b...example.com.
664 )`: "dns: bad TALINK NextName: \"b...example.com.\" at line: 2:1"}
665
666 for in, errStr := range tests {
667 _, err := NewRR(in)
668 if err == nil {
669 t.Error("err is nil")
670 } else {
671 if err.Error() != errStr {
672 t.Errorf("%s: error should be %s is %v", in, errStr, err)
673 }
674 }
675 }
676 }
677
678 // Test if the calculations are correct
679 func TestRfc1982(t *testing.T) {
680 // If the current time and the timestamp are more than 68 years apart
681 // it means the date has wrapped. 0 is 1970
682
683 // fall in the current 68 year span
684 strtests := []string{"20120525134203", "19700101000000", "20380119031408"}
685 for _, v := range strtests {
686 if x, _ := StringToTime(v); v != TimeToString(x) {
687 t.Errorf("1982 arithmetic string failure %s (%s:%d)", v, TimeToString(x), x)
688 }
689 }
690
691 inttests := map[uint32]string{0: "19700101000000",
692 1 << 31: "20380119031408",
693 1<<32 - 1: "21060207062815",
694 }
695 for i, v := range inttests {
696 if TimeToString(i) != v {
697 t.Errorf("1982 arithmetic int failure %d:%s (%s)", i, v, TimeToString(i))
698 }
699 }
700
701 // Future tests, these dates get parsed to a date within the current 136 year span
702 future := map[string]string{"22680119031408": "20631123173144",
703 "19010101121212": "20370206184028",
704 "19210101121212": "20570206184028",
705 "19500101121212": "20860206184028",
706 "19700101000000": "19700101000000",
707 "19690101000000": "21050207062816",
708 "29210101121212": "21040522212236",
709 }
710 for from, to := range future {
711 x, _ := StringToTime(from)
712 y := TimeToString(x)
713 if y != to {
714 t.Errorf("1982 arithmetic future failure %s:%s (%s)", from, to, y)
715 }
716 }
717 }
718
719 func TestEmpty(t *testing.T) {
720 z := NewZoneParser(strings.NewReader(""), "", "")
721 for _, ok := z.Next(); ok; _, ok = z.Next() {
722 t.Errorf("should be empty")
723 }
724 if err := z.Err(); err != nil {
725 t.Error("got an error when it shouldn't")
726 }
727 }
728
729 func TestLowercaseTokens(t *testing.T) {
730 var testrecords = []string{
731 "example.org. 300 IN a 1.2.3.4",
732 "example.org. 300 in A 1.2.3.4",
733 "example.org. 300 in a 1.2.3.4",
734 "example.org. 300 a 1.2.3.4",
735 "example.org. 300 A 1.2.3.4",
736 "example.org. IN a 1.2.3.4",
737 "example.org. in A 1.2.3.4",
738 "example.org. in a 1.2.3.4",
739 "example.org. a 1.2.3.4",
740 "example.org. A 1.2.3.4",
741 "example.org. a 1.2.3.4",
742 "$ORIGIN example.org.\n a 1.2.3.4",
743 "$Origin example.org.\n a 1.2.3.4",
744 "$origin example.org.\n a 1.2.3.4",
745 "example.org. Class1 Type1 1.2.3.4",
746 }
747 for _, testrr := range testrecords {
748 _, err := NewRR(testrr)
749 if err != nil {
750 t.Errorf("failed to parse %#v, got %v", testrr, err)
751 }
752 }
753 }
754
755 func TestSRVPacking(t *testing.T) {
756 msg := Msg{}
757
758 things := []string{"1.2.3.4:8484",
759 "45.45.45.45:8484",
760 "84.84.84.84:8484",
761 }
762
763 for i, n := range things {
764 h, p, err := net.SplitHostPort(n)
765 if err != nil {
766 continue
767 }
768 port, _ := strconv.ParseUint(p, 10, 16)
769
770 rr := &SRV{
771 Hdr: RR_Header{Name: "somename.",
772 Rrtype: TypeSRV,
773 Class: ClassINET,
774 Ttl: 5},
775 Priority: uint16(i),
776 Weight: 5,
777 Port: uint16(port),
778 Target: h + ".",
779 }
780
781 msg.Answer = append(msg.Answer, rr)
782 }
783
784 _, err := msg.Pack()
785 if err != nil {
786 t.Fatalf("couldn't pack %v: %v", msg, err)
787 }
788 }
789
790 func TestParseBackslash(t *testing.T) {
791 if _, err := NewRR("nul\\000gap.test.globnix.net. 600 IN A 192.0.2.10"); err != nil {
792 t.Errorf("could not create RR with \\000 in it")
793 }
794 if _, err := NewRR(`nul\000gap.test.globnix.net. 600 IN TXT "Hello\123"`); err != nil {
795 t.Errorf("could not create RR with \\000 in it")
796 }
797 if _, err := NewRR(`m\ @\ iek.nl. IN 3600 A 127.0.0.1`); err != nil {
798 t.Errorf("could not create RR with \\ and \\@ in it")
799 }
800 }
801
802 func TestILNP(t *testing.T) {
803 tests := []string{
804 "host1.example.com.\t3600\tIN\tNID\t10 0014:4fff:ff20:ee64",
805 "host1.example.com.\t3600\tIN\tNID\t20 0015:5fff:ff21:ee65",
806 "host2.example.com.\t3600\tIN\tNID\t10 0016:6fff:ff22:ee66",
807 "host1.example.com.\t3600\tIN\tL32\t10 10.1.2.0",
808 "host1.example.com.\t3600\tIN\tL32\t20 10.1.4.0",
809 "host2.example.com.\t3600\tIN\tL32\t10 10.1.8.0",
810 "host1.example.com.\t3600\tIN\tL64\t10 2001:0DB8:1140:1000",
811 "host1.example.com.\t3600\tIN\tL64\t20 2001:0DB8:2140:2000",
812 "host2.example.com.\t3600\tIN\tL64\t10 2001:0DB8:4140:4000",
813 "host1.example.com.\t3600\tIN\tLP\t10 l64-subnet1.example.com.",
814 "host1.example.com.\t3600\tIN\tLP\t10 l64-subnet2.example.com.",
815 "host1.example.com.\t3600\tIN\tLP\t20 l32-subnet1.example.com.",
816 }
817 for _, t1 := range tests {
818 r, err := NewRR(t1)
819 if err != nil {
820 t.Fatalf("an error occurred: %v", err)
821 } else {
822 if t1 != r.String() {
823 t.Fatalf("strings should be equal %s %s", t1, r.String())
824 }
825 }
826 }
827 }
828
829 func TestGposEidNimloc(t *testing.T) {
830 dt := map[string]string{
831 "444433332222111199990123000000ff. NSAP-PTR foo.bar.com.": "444433332222111199990123000000ff.\t3600\tIN\tNSAP-PTR\tfoo.bar.com.",
832 "lillee. IN GPOS -32.6882 116.8652 10.0": "lillee.\t3600\tIN\tGPOS\t-32.6882 116.8652 10.0",
833 "hinault. IN GPOS -22.6882 116.8652 250.0": "hinault.\t3600\tIN\tGPOS\t-22.6882 116.8652 250.0",
834 "VENERA. IN NIMLOC 75234159EAC457800920": "VENERA.\t3600\tIN\tNIMLOC\t75234159EAC457800920",
835 "VAXA. IN EID 3141592653589793": "VAXA.\t3600\tIN\tEID\t3141592653589793",
836 }
837 for i, o := range dt {
838 rr, err := NewRR(i)
839 if err != nil {
840 t.Error("failed to parse RR: ", err)
841 continue
842 }
843 if rr.String() != o {
844 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
845 }
846 }
847 }
848
849 func TestPX(t *testing.T) {
850 dt := map[string]string{
851 "*.net2.it. IN PX 10 net2.it. PRMD-net2.ADMD-p400.C-it.": "*.net2.it.\t3600\tIN\tPX\t10 net2.it. PRMD-net2.ADMD-p400.C-it.",
852 "ab.net2.it. IN PX 10 ab.net2.it. O-ab.PRMD-net2.ADMDb.C-it.": "ab.net2.it.\t3600\tIN\tPX\t10 ab.net2.it. O-ab.PRMD-net2.ADMDb.C-it.",
853 }
854 for i, o := range dt {
855 rr, err := NewRR(i)
856 if err != nil {
857 t.Error("failed to parse RR: ", err)
858 continue
859 }
860 if rr.String() != o {
861 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
862 }
863 }
864 }
865
866 func TestComment(t *testing.T) {
867 // Comments we must see
868 comments := map[string]bool{
869 "; this is comment 1": true,
870 "; this is comment 2": true,
871 "; this is comment 4": true,
872 "; this is comment 6": true,
873 "; this is comment 7": true,
874 "; this is comment 8": true,
875 }
876 zone := `
877 foo. IN A 10.0.0.1 ; this is comment 1
878 foo. IN A (
879 10.0.0.2 ; this is comment 2
880 )
881 ; this is comment 3
882 foo. IN A 10.0.0.3
883 foo. IN A ( 10.0.0.4 ); this is comment 4
884
885 foo. IN A 10.0.0.5
886 ; this is comment 5
887
888 foo. IN A 10.0.0.6
889
890 foo. IN DNSKEY 256 3 5 AwEAAb+8l ; this is comment 6
891 foo. IN NSEC miek.nl. TXT RRSIG NSEC; this is comment 7
892 foo. IN TXT "THIS IS TEXT MAN"; this is comment 8
893 `
894 z := NewZoneParser(strings.NewReader(zone), ".", "")
895 for _, ok := z.Next(); ok; _, ok = z.Next() {
896 if z.Comment() != "" {
897 if _, okC := comments[z.Comment()]; !okC {
898 t.Errorf("wrong comment %q", z.Comment())
899 }
900 }
901 }
902 if err := z.Err(); err != nil {
903 t.Error("got an error when it shouldn't")
904 }
905 }
906
907 func TestZoneParserComments(t *testing.T) {
908 for i, test := range []struct {
909 zone string
910 comments []string
911 }{
912 {
913 `name. IN SOA a6.nstld.com. hostmaster.nic.name. (
914 203362132 ; serial
915 5m ; refresh (5 minutes)
916 5m ; retry (5 minutes)
917 2w ; expire (2 weeks)
918 300 ; minimum (5 minutes)
919 ) ; y
920 . 3600000 IN NS ONE.MY-ROOTS.NET. ; x`,
921 []string{"; serial ; refresh (5 minutes) ; retry (5 minutes) ; expire (2 weeks) ; minimum (5 minutes) ; y", "; x"},
922 },
923 {
924 `name. IN SOA a6.nstld.com. hostmaster.nic.name. (
925 203362132 ; serial
926 5m ; refresh (5 minutes)
927 5m ; retry (5 minutes)
928 2w ; expire (2 weeks)
929 300 ; minimum (5 minutes)
930 ) ; y
931 . 3600000 IN NS ONE.MY-ROOTS.NET.`,
932 []string{"; serial ; refresh (5 minutes) ; retry (5 minutes) ; expire (2 weeks) ; minimum (5 minutes) ; y", ""},
933 },
934 {
935 `name. IN SOA a6.nstld.com. hostmaster.nic.name. (
936 203362132 ; serial
937 5m ; refresh (5 minutes)
938 5m ; retry (5 minutes)
939 2w ; expire (2 weeks)
940 300 ; minimum (5 minutes)
941 )
942 . 3600000 IN NS ONE.MY-ROOTS.NET.`,
943 []string{"; serial ; refresh (5 minutes) ; retry (5 minutes) ; expire (2 weeks) ; minimum (5 minutes)", ""},
944 },
945 {
946 `name. IN SOA a6.nstld.com. hostmaster.nic.name. (
947 203362132 ; serial
948 5m ; refresh (5 minutes)
949 5m ; retry (5 minutes)
950 2w ; expire (2 weeks)
951 300 ; minimum (5 minutes)
952 )
953 . 3600000 IN NS ONE.MY-ROOTS.NET. ; x`,
954 []string{"; serial ; refresh (5 minutes) ; retry (5 minutes) ; expire (2 weeks) ; minimum (5 minutes)", "; x"},
955 },
956 {
957 `name. IN SOA a6.nstld.com. hostmaster.nic.name. (
958 203362132 ; serial
959 5m ; refresh (5 minutes)
960 5m ; retry (5 minutes)
961 2w ; expire (2 weeks)
962 300 ; minimum (5 minutes)
963 )`,
964 []string{"; serial ; refresh (5 minutes) ; retry (5 minutes) ; expire (2 weeks) ; minimum (5 minutes)"},
965 },
966 {
967 `. 3600000 IN NS ONE.MY-ROOTS.NET. ; x`,
968 []string{"; x"},
969 },
970 {
971 `. 3600000 IN NS ONE.MY-ROOTS.NET.`,
972 []string{""},
973 },
974 {
975 `. 3600000 IN NS ONE.MY-ROOTS.NET. ;;x`,
976 []string{";;x"},
977 },
978 } {
979 r := strings.NewReader(test.zone)
980
981 var j int
982 z := NewZoneParser(r, "", "")
983 for rr, ok := z.Next(); ok; rr, ok = z.Next() {
984 if j >= len(test.comments) {
985 t.Fatalf("too many records for zone %d at %d record, expected %d", i, j+1, len(test.comments))
986 }
987
988 if z.Comment() != test.comments[j] {
989 t.Errorf("invalid comment for record %d:%d %v", i, j, rr)
990 t.Logf("expected %q", test.comments[j])
991 t.Logf("got %q", z.Comment())
992 }
993
994 j++
995 }
996
997 if err := z.Err(); err != nil {
998 t.Fatal(err)
999 }
1000
1001 if j != len(test.comments) {
1002 t.Errorf("too few records for zone %d, got %d, expected %d", i, j, len(test.comments))
1003 }
1004 }
1005 }
1006
1007 func TestEUIxx(t *testing.T) {
1008 tests := map[string]string{
1009 "host.example. IN EUI48 00-00-5e-90-01-2a": "host.example.\t3600\tIN\tEUI48\t00-00-5e-90-01-2a",
1010 "host.example. IN EUI64 00-00-5e-ef-00-00-00-2a": "host.example.\t3600\tIN\tEUI64\t00-00-5e-ef-00-00-00-2a",
1011 }
1012 for i, o := range tests {
1013 r, err := NewRR(i)
1014 if err != nil {
1015 t.Errorf("failed to parse %s: %v", i, err)
1016 }
1017 if r.String() != o {
1018 t.Errorf("want %s, got %s", o, r.String())
1019 }
1020 }
1021 }
1022
1023 func TestUserRR(t *testing.T) {
1024 tests := map[string]string{
1025 "host.example. IN UID 1234": "host.example.\t3600\tIN\tUID\t1234",
1026 "host.example. IN GID 1234556": "host.example.\t3600\tIN\tGID\t1234556",
1027 "host.example. IN UINFO \"Miek Gieben\"": "host.example.\t3600\tIN\tUINFO\t\"Miek Gieben\"",
1028 }
1029 for i, o := range tests {
1030 r, err := NewRR(i)
1031 if err != nil {
1032 t.Errorf("failed to parse %s: %v", i, err)
1033 }
1034 if r.String() != o {
1035 t.Errorf("want %s, got %s", o, r.String())
1036 }
1037 }
1038 }
1039
1040 func TestTXT(t *testing.T) {
1041 // Test single entry TXT record
1042 rr, err := NewRR(`_raop._tcp.local. 60 IN TXT "single value"`)
1043 if err != nil {
1044 t.Error("failed to parse single value TXT record", err)
1045 } else if rr, ok := rr.(*TXT); !ok {
1046 t.Error("wrong type, record should be of type TXT")
1047 } else {
1048 if len(rr.Txt) != 1 {
1049 t.Error("bad size of TXT value:", len(rr.Txt))
1050 } else if rr.Txt[0] != "single value" {
1051 t.Error("bad single value")
1052 }
1053 if rr.String() != `_raop._tcp.local. 60 IN TXT "single value"` {
1054 t.Error("bad representation of TXT record:", rr.String())
1055 }
1056 if Len(rr) != 28+1+12 {
1057 t.Error("bad size of serialized record:", Len(rr))
1058 }
1059 }
1060
1061 // Test multi entries TXT record
1062 rr, err = NewRR(`_raop._tcp.local. 60 IN TXT "a=1" "b=2" "c=3" "d=4"`)
1063 if err != nil {
1064 t.Error("failed to parse multi-values TXT record", err)
1065 } else if rr, ok := rr.(*TXT); !ok {
1066 t.Error("wrong type, record should be of type TXT")
1067 } else {
1068 if len(rr.Txt) != 4 {
1069 t.Error("bad size of TXT multi-value:", len(rr.Txt))
1070 } else if rr.Txt[0] != "a=1" || rr.Txt[1] != "b=2" || rr.Txt[2] != "c=3" || rr.Txt[3] != "d=4" {
1071 t.Error("bad values in TXT records")
1072 }
1073 if rr.String() != `_raop._tcp.local. 60 IN TXT "a=1" "b=2" "c=3" "d=4"` {
1074 t.Error("bad representation of TXT multi value record:", rr.String())
1075 }
1076 if Len(rr) != 28+1+3+1+3+1+3+1+3 {
1077 t.Error("bad size of serialized multi value record:", Len(rr))
1078 }
1079 }
1080
1081 // Test empty-string in TXT record
1082 rr, err = NewRR(`_raop._tcp.local. 60 IN TXT ""`)
1083 if err != nil {
1084 t.Error("failed to parse empty-string TXT record", err)
1085 } else if rr, ok := rr.(*TXT); !ok {
1086 t.Error("wrong type, record should be of type TXT")
1087 } else {
1088 if len(rr.Txt) != 1 {
1089 t.Error("bad size of TXT empty-string value:", len(rr.Txt))
1090 } else if rr.Txt[0] != "" {
1091 t.Error("bad value for empty-string TXT record")
1092 }
1093 if rr.String() != `_raop._tcp.local. 60 IN TXT ""` {
1094 t.Error("bad representation of empty-string TXT record:", rr.String())
1095 }
1096 if Len(rr) != 28+1 {
1097 t.Error("bad size of serialized record:", Len(rr))
1098 }
1099 }
1100
1101 // Test TXT record with string larger than 255 bytes that should be split
1102 // up by the parser. Add some escape sequences too to ensure their length
1103 // is counted correctly.
1104 s := `"\;\\\120` + strings.Repeat("a", 255) + `b"`
1105 rr, err = NewRR(`test.local. 60 IN TXT ` + s)
1106 if err != nil {
1107 t.Error("failed to parse empty-string TXT record", err)
1108 }
1109 if rr.(*TXT).Txt[1] != "aaab" {
1110 t.Errorf("Txt should have two strings, last one must be 'aaab', but is %s", rr.(*TXT).Txt[1])
1111 }
1112 rrContent := strings.Replace(rr.String(), rr.Header().String(), "", 1)
1113 expectedRRContent := `";\\x` + strings.Repeat("a", 252) + `" "aaab"`
1114 if expectedRRContent != rrContent {
1115 t.Errorf("Expected TXT RR content to be %#q but got %#q", expectedRRContent, rrContent)
1116 }
1117
1118 // Test TXT record that is already split up into strings of len <= 255.
1119 s = fmt.Sprintf(
1120 "%q %q %q %q %q %q",
1121 strings.Repeat(`a`, 255),
1122 strings.Repeat("b", 255),
1123 strings.Repeat("c", 255),
1124 strings.Repeat("d", 0),
1125 strings.Repeat("e", 1),
1126 strings.Repeat("f", 123),
1127 )
1128 rr, err = NewRR(`test.local. 60 IN TXT ` + s)
1129 if err != nil {
1130 t.Error("failed to parse empty-string TXT record", err)
1131 }
1132 rrContent = strings.Replace(rr.String(), rr.Header().String(), "", 1)
1133 expectedRRContent = s // same as input
1134 if expectedRRContent != rrContent {
1135 t.Errorf("Expected TXT RR content to be %#q but got %#q", expectedRRContent, rrContent)
1136 }
1137 }
1138
1139 func TestTypeXXXX(t *testing.T) {
1140 _, err := NewRR("example.com IN TYPE1234 \\# 4 aabbccdd")
1141 if err != nil {
1142 t.Errorf("failed to parse TYPE1234 RR: %v", err)
1143 }
1144 _, err = NewRR("example.com IN TYPE655341 \\# 8 aabbccddaabbccdd")
1145 if err == nil {
1146 t.Errorf("this should not work, for TYPE655341")
1147 }
1148 _, err = NewRR("example.com IN TYPE1 \\# 4 0a000001")
1149 if err != nil {
1150 t.Errorf("failed to parse TYPE1 RR: %v", err)
1151 }
1152 }
1153
1154 func TestPTR(t *testing.T) {
1155 _, err := NewRR("144.2.0.192.in-addr.arpa. 900 IN PTR ilouse03146p0\\(.example.com.")
1156 if err != nil {
1157 t.Error("failed to parse ", err)
1158 }
1159 }
1160
1161 func TestDigit(t *testing.T) {
1162 tests := map[string]byte{
1163 "miek\\000.nl. 100 IN TXT \"A\"": 0,
1164 "miek\\001.nl. 100 IN TXT \"A\"": 1,
1165 "miek\\254.nl. 100 IN TXT \"A\"": 254,
1166 "miek\\255.nl. 100 IN TXT \"A\"": 255,
1167 "miek\\256.nl. 100 IN TXT \"A\"": 0,
1168 "miek\\257.nl. 100 IN TXT \"A\"": 1,
1169 "miek\\004.nl. 100 IN TXT \"A\"": 4,
1170 }
1171 for s, i := range tests {
1172 r, err := NewRR(s)
1173 buf := make([]byte, 40)
1174 if err != nil {
1175 t.Fatalf("failed to parse %v", err)
1176 }
1177 PackRR(r, buf, 0, nil, false)
1178 if buf[5] != i {
1179 t.Fatalf("5 pos must be %d, is %d", i, buf[5])
1180 }
1181 r1, _, _ := UnpackRR(buf, 0)
1182 if r1.Header().Ttl != 100 {
1183 t.Fatalf("TTL should %d, is %d", 100, r1.Header().Ttl)
1184 }
1185 }
1186 }
1187
1188 func TestParseRRSIGTimestamp(t *testing.T) {
1189 tests := map[string]bool{
1190 `miek.nl. IN RRSIG SOA 8 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2BvuNiUJjSYlJAgzyAE6CF875BMvvZa+Sb0 RlSCL7WODQSQHhCx/fegHhVVF+Iz8N8kOLrmXD1+jO3Bm6Prl5UhcsPx WTBsg/kmxbp8sR1kvH4oZJtVfakG3iDerrxNaf0sQwhZzyfJQAqpC7pcBoc=`: true,
1191 `miek.nl. IN RRSIG SOA 8 2 43200 315565800 4102477800 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2BvuNiUJjSYlJAgzyAE6CF875BMvvZa+Sb0 RlSCL7WODQSQHhCx/fegHhVVF+Iz8N8kOLrmXD1+jO3Bm6Prl5UhcsPx WTBsg/kmxbp8sR1kvH4oZJtVfakG3iDerrxNaf0sQwhZzyfJQAqpC7pcBoc=`: true,
1192 }
1193 for r := range tests {
1194 _, err := NewRR(r)
1195 if err != nil {
1196 t.Error(err)
1197 }
1198 }
1199 }
1200
1201 func TestTxtEqual(t *testing.T) {
1202 rr1 := new(TXT)
1203 rr1.Hdr = RR_Header{Name: ".", Rrtype: TypeTXT, Class: ClassINET, Ttl: 0}
1204 rr1.Txt = []string{"a\"a", "\"", "b"}
1205 rr2, _ := NewRR(rr1.String())
1206 if rr1.String() != rr2.String() {
1207 // This is not an error, but keep this test.
1208 t.Errorf("these two TXT records should match:\n%s\n%s", rr1.String(), rr2.String())
1209 }
1210 }
1211
1212 func TestTxtLong(t *testing.T) {
1213 rr1 := new(TXT)
1214 rr1.Hdr = RR_Header{Name: ".", Rrtype: TypeTXT, Class: ClassINET, Ttl: 0}
1215 // Make a long txt record, this breaks when sending the packet,
1216 // but not earlier.
1217 rr1.Txt = []string{"start-"}
1218 for i := 0; i < 200; i++ {
1219 rr1.Txt[0] += "start-"
1220 }
1221 str := rr1.String()
1222 if len(str) < len(rr1.Txt[0]) {
1223 t.Error("string conversion should work")
1224 }
1225 }
1226
1227 // Basically, don't crash.
1228 func TestMalformedPackets(t *testing.T) {
1229 var packets = []string{
1230 "0021641c0000000100000000000078787878787878787878787303636f6d0000100001",
1231 }
1232
1233 // com = 63 6f 6d
1234 for _, packet := range packets {
1235 data, _ := hex.DecodeString(packet)
1236 var msg Msg
1237 msg.Unpack(data)
1238 }
1239 }
1240
1241 type algorithm struct {
1242 name uint8
1243 bits int
1244 }
1245
1246 func TestNewPrivateKey(t *testing.T) {
1247 if testing.Short() {
1248 t.Skip("skipping test in short mode.")
1249 }
1250 algorithms := []algorithm{
1251 {ECDSAP256SHA256, 256},
1252 {ECDSAP384SHA384, 384},
1253 {RSASHA1, 1024},
1254 {RSASHA256, 1024},
1255 {ED25519, 256},
1256 }
1257
1258 for _, algo := range algorithms {
1259 key := new(DNSKEY)
1260 key.Hdr.Rrtype = TypeDNSKEY
1261 key.Hdr.Name = "miek.nl."
1262 key.Hdr.Class = ClassINET
1263 key.Hdr.Ttl = 14400
1264 key.Flags = 256
1265 key.Protocol = 3
1266 key.Algorithm = algo.name
1267 privkey, err := key.Generate(algo.bits)
1268 if err != nil {
1269 t.Fatal(err)
1270 }
1271
1272 newPrivKey, err := key.NewPrivateKey(key.PrivateKeyString(privkey))
1273 if err != nil {
1274 t.Error(key.String())
1275 t.Error(key.PrivateKeyString(privkey))
1276 t.Fatal(err)
1277 }
1278
1279 switch newPrivKey := newPrivKey.(type) {
1280 case *rsa.PrivateKey:
1281 newPrivKey.Precompute()
1282 }
1283
1284 if !reflect.DeepEqual(privkey, newPrivKey) {
1285 t.Errorf("[%v] Private keys differ:\n%#v\n%#v", AlgorithmToString[algo.name], privkey, newPrivKey)
1286 }
1287 }
1288 }
1289
1290 // special input test
1291 func TestNewRRSpecial(t *testing.T) {
1292 var (
1293 rr RR
1294 err error
1295 expect string
1296 )
1297
1298 rr, err = NewRR("; comment")
1299 expect = ""
1300 if err != nil {
1301 t.Errorf("unexpected err: %v", err)
1302 }
1303 if rr != nil {
1304 t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
1305 }
1306
1307 rr, err = NewRR("")
1308 expect = ""
1309 if err != nil {
1310 t.Errorf("unexpected err: %v", err)
1311 }
1312 if rr != nil {
1313 t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
1314 }
1315
1316 rr, err = NewRR("$ORIGIN foo.")
1317 expect = ""
1318 if err != nil {
1319 t.Errorf("unexpected err: %v", err)
1320 }
1321 if rr != nil {
1322 t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
1323 }
1324
1325 rr, err = NewRR(" ")
1326 expect = ""
1327 if err != nil {
1328 t.Errorf("unexpected err: %v", err)
1329 }
1330 if rr != nil {
1331 t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
1332 }
1333
1334 rr, err = NewRR("\n")
1335 expect = ""
1336 if err != nil {
1337 t.Errorf("unexpected err: %v", err)
1338 }
1339 if rr != nil {
1340 t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
1341 }
1342
1343 rr, err = NewRR("foo. A 1.1.1.1\nbar. A 2.2.2.2")
1344 expect = "foo.\t3600\tIN\tA\t1.1.1.1"
1345 if err != nil {
1346 t.Errorf("unexpected err: %v", err)
1347 }
1348 if rr == nil || rr.String() != expect {
1349 t.Errorf("unexpected result: [%s] != [%s]", rr, expect)
1350 }
1351 }
1352
1353 func TestPrintfVerbsRdata(t *testing.T) {
1354 x, _ := NewRR("www.miek.nl. IN MX 20 mx.miek.nl.")
1355 if Field(x, 1) != "20" {
1356 t.Errorf("should be 20")
1357 }
1358 if Field(x, 2) != "mx.miek.nl." {
1359 t.Errorf("should be mx.miek.nl.")
1360 }
1361
1362 x, _ = NewRR("www.miek.nl. IN A 127.0.0.1")
1363 if Field(x, 1) != "127.0.0.1" {
1364 t.Errorf("should be 127.0.0.1")
1365 }
1366
1367 x, _ = NewRR("www.miek.nl. IN AAAA ::1")
1368 if Field(x, 1) != "::1" {
1369 t.Errorf("should be ::1")
1370 }
1371
1372 x, _ = NewRR("www.miek.nl. IN NSEC a.miek.nl. A NS SOA MX AAAA")
1373 if Field(x, 1) != "a.miek.nl." {
1374 t.Errorf("should be a.miek.nl.")
1375 }
1376 if Field(x, 2) != "A NS SOA MX AAAA" {
1377 t.Errorf("should be A NS SOA MX AAAA")
1378 }
1379
1380 x, _ = NewRR("www.miek.nl. IN TXT \"first\" \"second\"")
1381 if Field(x, 1) != "first second" {
1382 t.Errorf("should be first second")
1383 }
1384 if Field(x, 0) != "" {
1385 t.Errorf("should be empty")
1386 }
1387 }
1388
1389 func TestParseTokenOverflow(t *testing.T) {
1390 _, err := NewRR("_443._tcp.example.org. IN TLSA 0 0 0 308205e8308204d0a00302010202100411de8f53b462f6a5a861b712ec6b59300d06092a864886f70d01010b05003070310b300906035504061302555331153013060355040a130c446967694365727420496e6331193017060355040b13107777772e64696769636572742e636f6d312f302d06035504031326446967694365727420534841322048696768204173737572616e636520536572766572204341301e170d3134313130363030303030305a170d3135313131333132303030305a3081a5310b3009060355040613025553311330110603550408130a43616c69666f726e6961311430120603550407130b4c6f7320416e67656c6573313c303a060355040a1333496e7465726e657420436f72706f726174696f6e20666f722041737369676e6564204e616d657320616e64204e756d6265727331133011060355040b130a546563686e6f6c6f6779311830160603550403130f7777772e6578616d706c652e6f726730820122300d06092a864886f70d01010105000382010f003082010a02820101009e663f52a3d18cb67cdfed547408a4e47e4036538988da2798da3b6655f7240d693ed1cb3fe6d6ad3a9e657ff6efa86b83b0cad24e5d31ff2bf70ec3b78b213f1b4bf61bdc669cbbc07d67154128ca92a9b3cbb4213a836fb823ddd4d7cc04918314d25f06086fa9970ba17e357cca9b458c27eb71760ab95e3f9bc898ae89050ae4d09ba2f7e4259d9ff1e072a6971b18355a8b9e53670c3d5dbdbd283f93a764e71b3a4140ca0746090c08510e2e21078d7d07844bf9c03865b531a0bf2ee766bc401f6451c5a1e6f6fb5d5c1d6a97a0abe91ae8b02e89241e07353909ccd5b41c46de207c06801e08f20713603827f2ae3e68cf15ef881d7e0608f70742e30203010001a382024630820242301f0603551d230418301680145168ff90af0207753cccd9656462a212b859723b301d0603551d0e04160414b000a7f422e9b1ce216117c4c46e7164c8e60c553081810603551d11047a3078820f7777772e6578616d706c652e6f7267820b6578616d706c652e636f6d820b6578616d706c652e656475820b6578616d706c652e6e6574820b6578616d706c652e6f7267820f7777772e6578616d706c652e636f6d820f7777772e6578616d706c652e656475820f7777772e6578616d706c652e6e6574300e0603551d0f0101ff0404030205a0301d0603551d250416301406082b0601050507030106082b0601050507030230750603551d1f046e306c3034a032a030862e687474703a2f2f63726c332e64696769636572742e636f6d2f736861322d68612d7365727665722d67332e63726c3034a032a030862e687474703a2f2f63726c342e64696769636572742e636f6d2f736861322d68612d7365727665722d67332e63726c30420603551d20043b3039303706096086480186fd6c0101302a302806082b06010505070201161c68747470733a2f2f7777772e64696769636572742e636f6d2f43505330818306082b0601050507010104773075302406082b060105050730018618687474703a2f2f6f6373702e64696769636572742e636f6d304d06082b060105050730028641687474703a2f2f636163657274732e64696769636572742e636f6d2f446967694365727453484132486967684173737572616e636553657276657243412e637274300c0603551d130101ff04023000300d06092a864886f70d01010b050003820101005eac2124dedb3978a86ff3608406acb542d3cb54cb83facd63aec88144d6a1bf15dbf1f215c4a73e241e582365cba9ea50dd306541653b3513af1a0756c1b2720e8d112b34fb67181efad9c4609bdc670fb025fa6e6d42188161b026cf3089a08369c2f3609fc84bcc3479140c1922ede430ca8dbac2b2a3cdacb305ba15dc7361c4c3a5e6daa99cb446cb221b28078a7a944efba70d96f31ac143d959bccd2fd50e30c325ea2624fb6b6dbe9344dbcf133bfbd5b4e892d635dbf31596451672c6b65ba5ac9b3cddea92b35dab1065cae3c8cb6bb450a62ea2f72ea7c6bdc7b65fa09b012392543734083c7687d243f8d0375304d99ccd2e148966a8637a6797")
1391 if err != nil {
1392 t.Fatalf("long token should not return an error")
1393 }
1394 }
1395
1396 func TestParseTLSA(t *testing.T) {
1397 lt := []string{
1398 "_443._tcp.example.org.\t3600\tIN\tTLSA\t1 1 1 c22be239f483c08957bc106219cc2d3ac1a308dfbbdd0a365f17b9351234cf00",
1399 "_443._tcp.example.org.\t3600\tIN\tTLSA\t2 1 2 4e85f45179e9cd6e0e68e2eb5be2e85ec9b92d91c609caf3ef0315213e3f92ece92c38397a607214de95c7fadc0ad0f1c604a469a0387959745032c0d51492f3",
1400 "_443._tcp.example.org.\t3600\tIN\tTLSA\t3 0 2 69ec8d2277360b215d0cd956b0e2747108dff34b27d461a41c800629e38ee6c2d1230cc9e8e36711330adc6766e6ff7c5fbb37f106f248337c1a20ad682888d2",
1401 }
1402 for _, o := range lt {
1403 rr, err := NewRR(o)
1404 if err != nil {
1405 t.Error("failed to parse RR: ", err)
1406 continue
1407 }
1408 if rr.String() != o {
1409 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", o, o, rr.String())
1410 }
1411 }
1412 }
1413
1414 func TestParseSMIMEA(t *testing.T) {
1415 lt := map[string]string{
1416 "2e85e1db3e62be6ea._smimecert.example.com.\t3600\tIN\tSMIMEA\t1 1 2 bd80f334566928fc18f58df7e4928c1886f48f71ca3fd41cd9b1854aca7c2180aaacad2819612ed68e7bd3701cc39be7f2529b017c0bc6a53e8fb3f0c7d48070": "2e85e1db3e62be6ea._smimecert.example.com.\t3600\tIN\tSMIMEA\t1 1 2 bd80f334566928fc18f58df7e4928c1886f48f71ca3fd41cd9b1854aca7c2180aaacad2819612ed68e7bd3701cc39be7f2529b017c0bc6a53e8fb3f0c7d48070",
1417 "2e85e1db3e62be6ea._smimecert.example.com.\t3600\tIN\tSMIMEA\t0 0 1 cdcf0fc66b182928c5217ddd42c826983f5a4b94160ee6c1c9be62d38199f710": "2e85e1db3e62be6ea._smimecert.example.com.\t3600\tIN\tSMIMEA\t0 0 1 cdcf0fc66b182928c5217ddd42c826983f5a4b94160ee6c1c9be62d38199f710",
1418 "2e85e1db3e62be6ea._smimecert.example.com.\t3600\tIN\tSMIMEA\t3 0 2 499a1eda2af8828b552cdb9d80c3744a25872fddd73f3898d8e4afa3549595d2dd4340126e759566fe8c26b251fa0c887ba4869f011a65f7e79967c2eb729f5b": "2e85e1db3e62be6ea._smimecert.example.com.\t3600\tIN\tSMIMEA\t3 0 2 499a1eda2af8828b552cdb9d80c3744a25872fddd73f3898d8e4afa3549595d2dd4340126e759566fe8c26b251fa0c887ba4869f011a65f7e79967c2eb729f5b",
1419 "2e85e1db3e62be6eb._smimecert.example.com.\t3600\tIN\tSMIMEA\t3 0 2 499a1eda2af8828b552cdb9d80c3744a25872fddd73f3898d8e4afa3549595d2dd4340126e759566fe8 c26b251fa0c887ba4869f01 1a65f7e79967c2eb729f5b": "2e85e1db3e62be6eb._smimecert.example.com.\t3600\tIN\tSMIMEA\t3 0 2 499a1eda2af8828b552cdb9d80c3744a25872fddd73f3898d8e4afa3549595d2dd4340126e759566fe8c26b251fa0c887ba4869f011a65f7e79967c2eb729f5b",
1420 }
1421 for i, o := range lt {
1422 rr, err := NewRR(i)
1423 if err != nil {
1424 t.Error("failed to parse RR: ", err)
1425 continue
1426 }
1427 if rr.String() != o {
1428 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", o, o, rr.String())
1429 }
1430 }
1431 }
1432
1433 func TestParseSSHFP(t *testing.T) {
1434 lt := []string{
1435 "test.example.org.\t300\tSSHFP\t1 2 (\n" +
1436 "\t\t\t\t\tBC6533CDC95A79078A39A56EA7635984ED655318ADA9\n" +
1437 "\t\t\t\t\tB6159E30723665DA95BB )",
1438 "test.example.org.\t300\tSSHFP\t1 2 ( BC6533CDC 95A79078A39A56EA7635984ED655318AD A9B6159E3072366 5DA95BB )",
1439 }
1440 result := "test.example.org.\t300\tIN\tSSHFP\t1 2 BC6533CDC95A79078A39A56EA7635984ED655318ADA9B6159E30723665DA95BB"
1441 for _, o := range lt {
1442 rr, err := NewRR(o)
1443 if err != nil {
1444 t.Error("failed to parse RR: ", err)
1445 continue
1446 }
1447 if rr.String() != result {
1448 t.Errorf("`%s' should be equal to\n\n`%s', but is \n`%s'", o, result, rr.String())
1449 }
1450 }
1451 }
1452
1453 func TestParseHINFO(t *testing.T) {
1454 dt := map[string]string{
1455 "example.net. HINFO A B": "example.net. 3600 IN HINFO \"A\" \"B\"",
1456 "example.net. HINFO \"A\" \"B\"": "example.net. 3600 IN HINFO \"A\" \"B\"",
1457 "example.net. HINFO A B C D E F": "example.net. 3600 IN HINFO \"A\" \"B C D E F\"",
1458 "example.net. HINFO AB": "example.net. 3600 IN HINFO \"AB\" \"\"",
1459 // "example.net. HINFO PC-Intel-700mhz \"Redhat Linux 7.1\"": "example.net. 3600 IN HINFO \"PC-Intel-700mhz\" \"Redhat Linux 7.1\"",
1460 // This one is recommended in Pro Bind book http://www.zytrax.com/books/dns/ch8/hinfo.html
1461 // but effectively, even Bind would replace it to correctly formed text when you AXFR
1462 // TODO: remove this set of comments or figure support for quoted/unquoted combinations in endingToTxtSlice function
1463 }
1464 for i, o := range dt {
1465 rr, err := NewRR(i)
1466 if err != nil {
1467 t.Error("failed to parse RR: ", err)
1468 continue
1469 }
1470 if rr.String() != o {
1471 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
1472 }
1473 }
1474 }
1475
1476 func TestParseISDN(t *testing.T) {
1477 dt := map[string]string{
1478 "example.net. ISDN A B": "example.net. 3600 IN ISDN \"A\" \"B\"",
1479 "example.net. ISDN \"A\" \"B\"": "example.net. 3600 IN ISDN \"A\" \"B\"",
1480 }
1481 for i, o := range dt {
1482 rr, err := NewRR(i)
1483 if err != nil {
1484 t.Error("failed to parse RR: ", err)
1485 continue
1486 }
1487 if rr.String() != o {
1488 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
1489 }
1490 }
1491 }
1492
1493 func TestParseCAA(t *testing.T) {
1494 lt := map[string]string{
1495 "example.net. CAA 0 issue \"symantec.com\"": "example.net.\t3600\tIN\tCAA\t0 issue \"symantec.com\"",
1496 "example.net. CAA 0 issuewild \"symantec.com; stuff\"": "example.net.\t3600\tIN\tCAA\t0 issuewild \"symantec.com; stuff\"",
1497 "example.net. CAA 128 tbs \"critical\"": "example.net.\t3600\tIN\tCAA\t128 tbs \"critical\"",
1498 "example.net. CAA 2 auth \"0>09\\006\\010+\\006\\001\\004\\001\\214y\\002\\003\\001\\006\\009`\\134H\\001e\\003\\004\\002\\001\\004 y\\209\\012\\221r\\220\\156Q\\218\\150\\150{\\166\\245:\\231\\182%\\157:\\133\\179}\\1923r\\238\\151\\255\\128q\\145\\002\\001\\000\"": "example.net.\t3600\tIN\tCAA\t2 auth \"0>09\\006\\010+\\006\\001\\004\\001\\214y\\002\\003\\001\\006\\009`\\134H\\001e\\003\\004\\002\\001\\004 y\\209\\012\\221r\\220\\156Q\\218\\150\\150{\\166\\245:\\231\\182%\\157:\\133\\179}\\1923r\\238\\151\\255\\128q\\145\\002\\001\\000\"",
1499 "example.net. TYPE257 0 issue \"symantec.com\"": "example.net.\t3600\tIN\tCAA\t0 issue \"symantec.com\"",
1500 }
1501 for i, o := range lt {
1502 rr, err := NewRR(i)
1503 if err != nil {
1504 t.Error("failed to parse RR: ", err)
1505 continue
1506 }
1507 if rr.String() != o {
1508 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
1509 }
1510 }
1511 }
1512
1513 func TestPackCAA(t *testing.T) {
1514 m := new(Msg)
1515 record := new(CAA)
1516 record.Hdr = RR_Header{Name: "example.com.", Rrtype: TypeCAA, Class: ClassINET, Ttl: 0}
1517 record.Tag = "issue"
1518 record.Value = "symantec.com"
1519 record.Flag = 1
1520
1521 m.Answer = append(m.Answer, record)
1522 bytes, err := m.Pack()
1523 if err != nil {
1524 t.Fatalf("failed to pack msg: %v", err)
1525 }
1526 if err := m.Unpack(bytes); err != nil {
1527 t.Fatalf("failed to unpack msg: %v", err)
1528 }
1529 if len(m.Answer) != 1 {
1530 t.Fatalf("incorrect number of answers unpacked")
1531 }
1532 rr := m.Answer[0].(*CAA)
1533 if rr.Tag != "issue" {
1534 t.Fatalf("invalid tag for unpacked answer")
1535 } else if rr.Value != "symantec.com" {
1536 t.Fatalf("invalid value for unpacked answer")
1537 } else if rr.Flag != 1 {
1538 t.Fatalf("invalid flag for unpacked answer")
1539 }
1540 }
1541
1542 func TestParseURI(t *testing.T) {
1543 lt := map[string]string{
1544 "_http._tcp. IN URI 10 1 \"http://www.example.com/path\"": "_http._tcp.\t3600\tIN\tURI\t10 1 \"http://www.example.com/path\"",
1545 "_http._tcp. IN URI 10 1 \"\"": "_http._tcp.\t3600\tIN\tURI\t10 1 \"\"",
1546 }
1547 for i, o := range lt {
1548 rr, err := NewRR(i)
1549 if err != nil {
1550 t.Error("failed to parse RR: ", err)
1551 continue
1552 }
1553 if rr.String() != o {
1554 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
1555 }
1556 }
1557 }
1558
1559 func TestParseAVC(t *testing.T) {
1560 avcs := map[string]string{
1561 `example.org. IN AVC "app-name:WOLFGANG|app-class:OAM|business=yes"`: `example.org. 3600 IN AVC "app-name:WOLFGANG|app-class:OAM|business=yes"`,
1562 }
1563 for avc, o := range avcs {
1564 rr, err := NewRR(avc)
1565 if err != nil {
1566 t.Error("failed to parse RR: ", err)
1567 continue
1568 }
1569 if rr.String() != o {
1570 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", avc, o, rr.String())
1571 }
1572 }
1573 }
1574
1575 func TestParseCSYNC(t *testing.T) {
1576 syncs := map[string]string{
1577 `example.com. 3600 IN CSYNC 66 3 A NS AAAA`: `example.com. 3600 IN CSYNC 66 3 A NS AAAA`,
1578 }
1579 for s, o := range syncs {
1580 rr, err := NewRR(s)
1581 if err != nil {
1582 t.Error("failed to parse RR: ", err)
1583 continue
1584 }
1585 if rr.String() != o {
1586 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", s, o, rr.String())
1587 }
1588 }
1589 }
1590
1591 func TestParseSVCB(t *testing.T) {
1592 svcbs := map[string]string{
1593 `example.com. 3600 IN SVCB 0 cloudflare.com.`: `example.com. 3600 IN SVCB 0 cloudflare.com.`,
1594 `example.com. 3600 IN SVCB 65000 cloudflare.com. alpn=h2 ipv4hint=3.4.3.2`: `example.com. 3600 IN SVCB 65000 cloudflare.com. alpn="h2" ipv4hint="3.4.3.2"`,
1595 `example.com. 3600 IN SVCB 65000 cloudflare.com. key65000=4\ 3 key65001="\" " key65002 key65003= key65004="" key65005== key65006==\"\" key65007=\254 key65008=\032`: `example.com. 3600 IN SVCB 65000 cloudflare.com. key65000="4\ 3" key65001="\"\ " key65002="" key65003="" key65004="" key65005="=" key65006="=\"\"" key65007="\254" key65008="\ "`,
1596 // Explained in svcb.go "In AliasMode, records SHOULD NOT include any SvcParams,"
1597 `example.com. 3600 IN SVCB 0 no-default-alpn`: `example.com. 3600 IN SVCB 0 no-default-alpn.`,
1598 // From the specification
1599 `example.com. HTTPS 0 foo.example.com.`: `example.com. 3600 IN HTTPS 0 foo.example.com.`,
1600 `example.com. SVCB 1 .`: `example.com. 3600 IN SVCB 1 .`,
1601 `example.com. SVCB 16 foo.example.com. port=53`: `example.com. 3600 IN SVCB 16 foo.example.com. port="53"`,
1602 `example.com. SVCB 1 foo.example.com. key667=hello`: `example.com. 3600 IN SVCB 1 foo.example.com. key667="hello"`,
1603 `example.com. SVCB 1 foo.example.com. key667="hello\210qoo"`: `example.com. 3600 IN SVCB 1 foo.example.com. key667="hello\210qoo"`,
1604 `example.com. SVCB 1 foo.example.com. ipv6hint="2001:db8::1,2001:db8::53:1"`: `example.com. 3600 IN SVCB 1 foo.example.com. ipv6hint="2001:db8::1,2001:db8::53:1"`,
1605 `example.com. SVCB 1 example.com. ipv6hint="2001:db8::198.51.100.100"`: `example.com. 3600 IN SVCB 1 example.com. ipv6hint="2001:db8::c633:6464"`,
1606 `example.com. SVCB 16 foo.example.org. alpn=h2,h3-19 mandatory=ipv4hint,alpn ipv4hint=192.0.2.1`: `example.com. 3600 IN SVCB 16 foo.example.org. alpn="h2,h3-19" mandatory="ipv4hint,alpn" ipv4hint="192.0.2.1"`,
1607 `example.com. SVCB 16 foo.example.org. alpn="f\\\\oo\\,bar,h2"`: `example.com. 3600 IN SVCB 16 foo.example.org. alpn="f\\\092oo\\\044bar,h2"`,
1608 `example.com. SVCB 16 foo.example.org. alpn=f\\\092oo\092,bar,h2`: `example.com. 3600 IN SVCB 16 foo.example.org. alpn="f\\\092oo\\\044bar,h2"`,
1609 // From draft-ietf-add-ddr-06
1610 `_dns.example.net. SVCB 1 example.net. alpn=h2 dohpath=/dns-query{?dns}`: `_dns.example.net. 3600 IN SVCB 1 example.net. alpn="h2" dohpath="/dns-query{?dns}"`,
1611 `_dns.example.net. SVCB 1 example.net. alpn=h2 dohpath=/dns\045query{\?dns}`: `_dns.example.net. 3600 IN SVCB 1 example.net. alpn="h2" dohpath="/dns-query{?dns}"`,
1612 // From RFC9461 Section 7 (https://datatracker.ietf.org/doc/html/rfc9461#section-7)
1613 `_dns.simple.example. 7200 IN SVCB 1 simple.example. alpn=dot`: `_dns.simple.example. 7200 IN SVCB 1 simple.example. alpn="dot"`,
1614 `_dns.doh.example. 7200 IN SVCB 1 doh.example. alpn=h2 dohpath=/dns-query{?dns}`: `_dns.doh.example. 7200 IN SVCB 1 doh.example. alpn="h2" dohpath="/dns-query{?dns}"`,
1615 `_dns.resolver.example. 7200 IN SVCB 1 resolver.example. alpn=dot,doq,h2,h3 dohpath=/q{?dns}`: `_dns.resolver.example. 7200 IN SVCB 1 resolver.example. alpn="dot,doq,h2,h3" dohpath="/q{?dns}"`,
1616 `_dns.resolver.example. 7200 IN SVCB 2 resolver.example. alpn=dot port=8530`: `_dns.resolver.example. 7200 IN SVCB 2 resolver.example. alpn="dot" port="8530"`,
1617 // From RFC 9540 Section 4.2.1 (https://www.rfc-editor.org/rfc/rfc9540.html#name-the-ohttp-svcparamkey)
1618 `_dns.resolver.arpa 7200 IN SVCB 1 doh.example.net alpn=h2 dohpath=/dns-query{?dns} ohttp`: `_dns.resolver.arpa. 7200 IN SVCB 1 doh.example.net. alpn="h2" dohpath="/dns-query{?dns}" ohttp=""`,
1619 // From RFC 9540 Section 4.1 (HTTPS RR) (https://www.rfc-editor.org/rfc/rfc9540.html#name-use-in-https-service-rrs)
1620 `svc.example.com. 7200 IN HTTPS 1 . alpn=h2 ohttp`: `svc.example.com. 7200 IN HTTPS 1 . alpn="h2" ohttp=""`,
1621 `svc.example.com. 7200 IN HTTPS 1 . mandatory=ohttp ohttp`: `svc.example.com. 7200 IN HTTPS 1 . mandatory="ohttp" ohttp=""`,
1622 }
1623
1624 for s, o := range svcbs {
1625 rr, err := NewRR(s)
1626 if err != nil {
1627 t.Error("failed to parse RR: ", err)
1628 continue
1629 }
1630 if rr.String() != o {
1631 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", s, o, rr.String())
1632 }
1633 }
1634 }
1635
1636 func TestParseBadSVCB(t *testing.T) {
1637 header := `example.com. 3600 IN HTTPS `
1638 evils := []string{
1639 `65536 . no-default-alpn`, // bad priority
1640 `1 ..`, // bad domain
1641 `1 . no-default-alpn=1`, // value illegal
1642 `1 . key`, // invalid key
1643 `1 . key=`, // invalid key
1644 `1 . =`, // invalid key
1645 `1 . ==`, // invalid key
1646 `1 . =a`, // invalid key
1647 `1 . ""`, // invalid key
1648 `1 . ""=`, // invalid key
1649 `1 . "a"`, // invalid key
1650 `1 . "a"=`, // invalid key
1651 `1 . key1=`, // we know that key
1652 `1 . key65535`, // key reserved
1653 `1 . key065534`, // key can't be padded
1654 `1 . key65534="f`, // unterminated value
1655 `1 . key65534="`, // unterminated value
1656 `1 . key65534=\2`, // invalid numeric escape
1657 `1 . key65534=\24`, // invalid numeric escape
1658 `1 . key65534=\256`, // invalid numeric escape
1659 `1 . key65534=\`, // invalid numeric escape
1660 `1 . key65534=""alpn`, // zQuote ending needs whitespace
1661 `1 . key65534="a"alpn`, // zQuote ending needs whitespace
1662 `1 . ipv6hint=1.1.1.1`, // not ipv6
1663 `1 . ipv6hint=1:1:1:1`, // not ipv6
1664 `1 . ipv6hint=a`, // not ipv6
1665 `1 . ipv6hint=`, // empty ipv6
1666 `1 . ipv4hint=1.1.1.1.1`, // not ipv4
1667 `1 . ipv4hint=::fc`, // not ipv4
1668 `1 . ipv4hint=..11`, // not ipv4
1669 `1 . ipv4hint=a`, // not ipv4
1670 `1 . ipv4hint=`, // empty ipv4
1671 `1 . port=`, // empty port
1672 `1 . echconfig=YUd`, // bad base64
1673 `1 . alpn=h\`, // unterminated escape
1674 `1 . alpn=h2\\.h3`, // comma-separated list with bad character
1675 `1 . alpn=h2,,h3`, // empty protocol identifier
1676 `1 . alpn=h3,`, // final protocol identifier empty
1677 }
1678 for _, o := range evils {
1679 _, err := NewRR(header + o)
1680 if err == nil {
1681 t.Error("failed to reject invalid RR: ", header+o)
1682 continue
1683 }
1684 }
1685 }
1686
1687 func TestParseBadNAPTR(t *testing.T) {
1688 // Should look like: mplus.ims.vodafone.com. 3600 IN NAPTR 10 100 "S" "SIP+D2U" "" _sip._udp.mplus.ims.vodafone.com.
1689 naptr := `mplus.ims.vodafone.com. 3600 IN NAPTR 10 100 S SIP+D2U _sip._udp.mplus.ims.vodafone.com.`
1690 _, err := NewRR(naptr) // parse fails, we should not have leaked a goroutine.
1691 if err == nil {
1692 t.Fatalf("parsing NAPTR should have failed: %s", naptr)
1693 }
1694 if err := goroutineLeaked(); err != nil {
1695 t.Errorf("leaked goroutines: %s", err)
1696 }
1697 }
1698
1699 func TestUnbalancedParens(t *testing.T) {
1700 sig := `example.com. 3600 IN RRSIG MX 15 2 3600 (
1701 1440021600 1438207200 3613 example.com. (
1702 oL9krJun7xfBOIWcGHi7mag5/hdZrKWw15jPGrHpjQeRAvTdszaPD+QLs3f
1703 x8A4M3e23mRZ9VrbpMngwcrqNAg== )`
1704 _, err := NewRR(sig)
1705 if err == nil {
1706 t.Fatalf("failed to detect extra opening brace")
1707 }
1708 }
1709
1710 func TestBad(t *testing.T) {
1711 tests := []string{
1712 `" TYPE257 9 1E12\x00\x105"`,
1713 `" TYPE256 9 5"`,
1714 `" TYPE257 0\"00000000000000400000000000000000000\x00\x10000000000000000000000000000000000 9 l\x16\x01\x005266"`,
1715 }
1716 for i := range tests {
1717 s, err := strconv.Unquote(tests[i])
1718 if err != nil {
1719 t.Fatalf("failed to unquote: %q: %s", tests[i], err)
1720 }
1721 if _, err = NewRR(s); err == nil {
1722 t.Errorf("correctly parsed %q", s)
1723 }
1724 }
1725 }
1726
1727 func TestNULLRecord(t *testing.T) {
1728 // packet captured from iodine
1729 packet := `8116840000010001000000000569627a6c700474657374046d69656b026e6c00000a0001c00c000a0001000000000005497f000001`
1730 data, _ := hex.DecodeString(packet)
1731 msg := new(Msg)
1732 err := msg.Unpack(data)
1733 if err != nil {
1734 t.Fatalf("Failed to unpack NULL record")
1735 }
1736 if _, ok := msg.Answer[0].(*NULL); !ok {
1737 t.Fatalf("Expected packet to contain NULL record")
1738 }
1739 }
1740 func TestAAAAParsing(t *testing.T) {
1741 tests := []string{
1742 "2001:db8::1",
1743 "1::1",
1744 "2001:db81:d2b4:b6ba:50db:49cc:a8d1:5bb1",
1745 "::ffff:192.0.2.0",
1746 }
1747
1748 rrPrefix := ".\t1\tIN\tAAAA\t"
1749
1750 for num, tc := range tests {
1751 t.Run(fmt.Sprintf("Test %d", num), func(t *testing.T) {
1752 rr, err := NewRR(rrPrefix + tc)
1753 if err != nil {
1754 t.Fatalf("failed to parse RR: %s", err)
1755 }
1756 // Output presentation format and try to parse again
1757 reparseRR, err := NewRR(rr.String())
1758 if err != nil {
1759 t.Fatalf("failed to reparse RR: %s", err)
1760 }
1761 if reparseRR.String() != rrPrefix+tc {
1762 t.Errorf("expected %s,got %s", rrPrefix+tc, reparseRR.String())
1763 }
1764 })
1765 }
1766 }
1767
1768 func TestParseAPL(t *testing.T) {
1769 tests := []struct {
1770 name string
1771 in string
1772 expect string
1773 }{
1774 {
1775 "v4",
1776 ". APL 1:192.0.2.0/24",
1777 ".\t3600\tIN\tAPL\t1:192.0.2.0/24",
1778 },
1779 {
1780 "v6",
1781 ". APL 2:2001:db8::/32",
1782 ".\t3600\tIN\tAPL\t2:2001:db8::/32",
1783 },
1784 {
1785 "null v6",
1786 ". APL 2:::/0",
1787 ".\t3600\tIN\tAPL\t2:::/0",
1788 },
1789 {
1790 "null v4",
1791 ". APL 1:0.0.0.0/0",
1792 ".\t3600\tIN\tAPL\t1:0.0.0.0/0",
1793 },
1794 {
1795 "full v6",
1796 ". APL 2:::/0",
1797 ".\t3600\tIN\tAPL\t2:::/0",
1798 },
1799 {
1800 "full v4",
1801 ". APL 1:192.0.2.1/32",
1802 ".\t3600\tIN\tAPL\t1:192.0.2.1/32",
1803 },
1804 {
1805 "full v6",
1806 ". APL 2:2001:0db8:d2b4:b6ba:50db:49cc:a8d1:5bb1/128",
1807 ".\t3600\tIN\tAPL\t2:2001:db8:d2b4:b6ba:50db:49cc:a8d1:5bb1/128",
1808 },
1809 {
1810 "v4in6",
1811 ". APL 2:::ffff:192.0.2.0/120",
1812 ".\t3600\tIN\tAPL\t2:::ffff:192.0.2.0/120",
1813 },
1814 {
1815 "v4in6 v6 syntax",
1816 ". APL 2:::ffff:c000:0200/120",
1817 ".\t3600\tIN\tAPL\t2:::ffff:192.0.2.0/120",
1818 },
1819 {
1820 "negate",
1821 ". APL !1:192.0.2.0/24",
1822 ".\t3600\tIN\tAPL\t!1:192.0.2.0/24",
1823 },
1824 {
1825 "multiple",
1826 ". APL 1:192.0.2.0/24 !1:192.0.2.1/32 2:2001:db8::/32 !2:2001:db8:1::0/48",
1827 ".\t3600\tIN\tAPL\t1:192.0.2.0/24 !1:192.0.2.1/32 2:2001:db8::/32 !2:2001:db8:1::/48",
1828 },
1829 {
1830 "no address",
1831 ". APL",
1832 ".\t3600\tIN\tAPL\t",
1833 },
1834 }
1835 for _, tc := range tests {
1836 t.Run(tc.name, func(t *testing.T) {
1837 rr, err := NewRR(tc.in)
1838 if err != nil {
1839 t.Fatalf("failed to parse RR: %s", err)
1840 }
1841
1842 got := rr.String()
1843 if got != tc.expect {
1844 t.Errorf("expected %q, got %q", tc.expect, got)
1845 }
1846 })
1847 }
1848 }
1849
1850 func TestParseAPLErrors(t *testing.T) {
1851 tests := []struct {
1852 name string
1853 in string
1854 }{
1855 {
1856 "unexpected",
1857 `. APL ""`,
1858 },
1859 {
1860 "unrecognized family",
1861 ". APL 3:0.0.0.0/0",
1862 },
1863 {
1864 "malformed family",
1865 ". APL foo:0.0.0.0/0",
1866 },
1867 {
1868 "malformed address",
1869 ". APL 1:192.0.2/16",
1870 },
1871 {
1872 "extra bits",
1873 ". APL 2:2001:db8::/0",
1874 },
1875 {
1876 "address mismatch v2",
1877 ". APL 1:2001:db8::/64",
1878 },
1879 {
1880 "address mismatch v6",
1881 ". APL 2:192.0.2.1/32",
1882 },
1883 {
1884 "no prefix",
1885 ". APL 1:192.0.2.1",
1886 },
1887 {
1888 "no family",
1889 ". APL 0.0.0.0/0",
1890 },
1891 }
1892 for _, tc := range tests {
1893 t.Run(tc.name, func(t *testing.T) {
1894 _, err := NewRR(tc.in)
1895 if err == nil {
1896 t.Fatal("expected error, got none")
1897 }
1898 })
1899 }
1900 }
1901
1902 func TestUnpackRRWithHeaderInvalidLengths(t *testing.T) {
1903 rr, err := NewRR("test.example.org. 300 IN SSHFP 1 2 BC6533CDC95A79078A39A56EA7635984ED655318ADA9B6159E30723665DA95BB")
1904 if err != nil {
1905 t.Fatalf("failed to parse SSHFP record: %v", err)
1906 }
1907
1908 buf := make([]byte, Len(rr))
1909 headerEnd, end, err := packRR(rr, buf, 0, compressionMap{}, false)
1910 if err != nil {
1911 t.Fatalf("failed to pack A record: %v", err)
1912 }
1913
1914 rr.Header().Rdlength = uint16(end - headerEnd)
1915 for _, off := range []int{
1916 -1,
1917 end + 1,
1918 1<<16 - 1,
1919 } {
1920 _, _, err := UnpackRRWithHeader(*rr.Header(), buf, off)
1921 if de, ok := err.(*Error); !ok || de.err != "bad off" {
1922 t.Errorf("UnpackRRWithHeader with bad offset (%d) returned wrong or no error: %v", off, err)
1923 }
1924 }
1925
1926 for _, rdlength := range []uint16{
1927 uint16(end - headerEnd + 1),
1928 uint16(end),
1929 1<<16 - 1,
1930 } {
1931 rr.Header().Rdlength = rdlength
1932
1933 _, _, err := UnpackRRWithHeader(*rr.Header(), buf, headerEnd)
1934 if de, ok := err.(*Error); !ok || de.err != "bad rdlength" {
1935 t.Errorf("UnpackRRWithHeader with bad rdlength (%d) returned wrong or no error: %v", rdlength, err)
1936 }
1937 }
1938 }
1939
1940 func TestParseZONEMD(t *testing.T) {
1941 // Uses examples from https://tools.ietf.org/html/rfc8976
1942 dt := map[string]string{
1943 // Simple Zone
1944 `example. 86400 IN ZONEMD 2018031900 1 1 (
1945 c68090d90a7aed71
1946 6bc459f9340e3d7c
1947 1370d4d24b7e2fc3
1948 a1ddc0b9a87153b9
1949 a9713b3c9ae5cc27
1950 777f98b8e730044c )
1951 `: "example.\t86400\tIN\tZONEMD\t2018031900 1 1 c68090d90a7aed716bc459f9340e3d7c1370d4d24b7e2fc3a1ddc0b9a87153b9a9713b3c9ae5cc27777f98b8e730044c",
1952 // Complex Zone
1953 `example. 86400 IN ZONEMD 2018031900 1 1 (
1954 a3b69bad980a3504
1955 e1cffcb0fd6397f9
1956 3848071c93151f55
1957 2ae2f6b1711d4bd2
1958 d8b39808226d7b9d
1959 b71e34b72077f8fe )
1960 `: "example.\t86400\tIN\tZONEMD\t2018031900 1 1 a3b69bad980a3504e1cffcb0fd6397f93848071c93151f552ae2f6b1711d4bd2d8b39808226d7b9db71e34b72077f8fe",
1961 // Multiple Digests Zone
1962 `example. 86400 IN ZONEMD 2018031900 1 1 (
1963 62e6cf51b02e54b9
1964 b5f967d547ce4313
1965 6792901f9f88e637
1966 493daaf401c92c27
1967 9dd10f0edb1c56f8
1968 080211f8480ee306 )
1969 `: "example.\t86400\tIN\tZONEMD\t2018031900 1 1 62e6cf51b02e54b9b5f967d547ce43136792901f9f88e637493daaf401c92c279dd10f0edb1c56f8080211f8480ee306",
1970 `example. 86400 IN ZONEMD 2018031900 1 2 (
1971 08cfa1115c7b948c
1972 4163a901270395ea
1973 226a930cd2cbcf2f
1974 a9a5e6eb85f37c8a
1975 4e114d884e66f176
1976 eab121cb02db7d65
1977 2e0cc4827e7a3204
1978 f166b47e5613fd27 )
1979 `: "example.\t86400\tIN\tZONEMD\t2018031900 1 2 08cfa1115c7b948c4163a901270395ea226a930cd2cbcf2fa9a5e6eb85f37c8a4e114d884e66f176eab121cb02db7d652e0cc4827e7a3204f166b47e5613fd27",
1980 `example. 86400 IN ZONEMD 2018031900 1 240 (
1981 e2d523f654b9422a
1982 96c5a8f44607bbee )
1983 `: "example. 86400 IN ZONEMD 2018031900 1 240 e2d523f654b9422a96c5a8f44607bbee",
1984 `example. 86400 IN ZONEMD 2018031900 241 1 (
1985 e1846540e33a9e41
1986 89792d18d5d131f6
1987 05fc283e )
1988 `: "example. 86400 IN ZONEMD 2018031900 241 1 e1846540e33a9e4189792d18d5d131f605fc283e",
1989 // URI.ARPA zone
1990 `uri.arpa. 3600 IN ZONEMD 2018100702 1 1 (
1991 0dbc3c4dbfd75777c12ca19c337854b1577799901307c482e9d91d5d15
1992 cd934d16319d98e30c4201cf25a1d5a0254960 )`: "uri.arpa.\t3600\tIN\tZONEMD\t2018100702 1 1 0dbc3c4dbfd75777c12ca19c337854b1577799901307c482e9d91d5d15cd934d16319d98e30c4201cf25a1d5a0254960",
1993 // ROOT-SERVERS.NET Zone
1994 `root-servers.net. 3600000 IN ZONEMD 2018091100 1 1 (
1995 f1ca0ccd91bd5573d9f431c00ee0101b2545c97602be0a97
1996 8a3b11dbfc1c776d5b3e86ae3d973d6b5349ba7f04340f79 )
1997 `: "root-servers.net.\t3600000\tIN\tZONEMD\t2018091100 1 1 f1ca0ccd91bd5573d9f431c00ee0101b2545c97602be0a978a3b11dbfc1c776d5b3e86ae3d973d6b5349ba7f04340f79",
1998 }
1999 for i, o := range dt {
2000 rr, err := NewRR(i)
2001 if err != nil {
2002 t.Error("failed to parse RR: ", err)
2003 continue
2004 }
2005 if rr.String() != o {
2006 t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
2007 }
2008 }
2009 }
2010
2011 func TestParseIPSECKEY(t *testing.T) {
2012 dt := map[string]string{
2013 "ipseckey. 3600 IN IPSECKEY 10 0 2 . AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==": "ipseckey.\t3600\tIN\tIPSECKEY\t10 0 2 . AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==",
2014 "ipseckey. 3600 IN IPSECKEY 10 1 2 1.2.3.4 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==": "ipseckey.\t3600\tIN\tIPSECKEY\t10 1 2 1.2.3.4 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==",
2015 "ipseckey. 3600 IN IPSECKEY 10 2 2 2001:470:30:84:e276:63ff:fe72:3900 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==": "ipseckey.\t3600\tIN\tIPSECKEY\t10 2 2 2001:470:30:84:e276:63ff:fe72:3900 AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==",
2016 "ipseckey. 3600 IN IPSECKEY 10 3 2 ipseckey2. AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==": "ipseckey.\t3600\tIN\tIPSECKEY\t10 3 2 ipseckey2. AQNRU3mG7TVTO2BkR47usntb102uFJtugbo6BSGvgqt4AQ==",
2017 }
2018
2019 for i, o := range dt {
2020 rr := testRR(i).(*IPSECKEY)
2021 if s := rr.String(); s != o {
2022 t.Errorf("input %#v does not match expected output %#v", s, o)
2023 }
2024 }
2025 }
2026
2027 func TestParseAMTRELAY(t *testing.T) {
2028 dt := map[string]string{
2029 "amtrelay. 3600 IN AMTRELAY 10 0 0 .": "amtrelay.\t3600\tIN\tAMTRELAY\t10 0 0 .",
2030 "amtrelay. 3600 IN AMTRELAY 10 0 1 1.2.3.4": "amtrelay.\t3600\tIN\tAMTRELAY\t10 0 1 1.2.3.4",
2031 "amtrelay. 3600 IN AMTRELAY 10 1 2 2001:470:30:84:e276:63ff:fe72:3900": "amtrelay.\t3600\tIN\tAMTRELAY\t10 1 2 2001:470:30:84:e276:63ff:fe72:3900",
2032 "amtrelay. 3600 IN AMTRELAY 10 1 3 amtrelay2.": "amtrelay.\t3600\tIN\tAMTRELAY\t10 1 3 amtrelay2.",
2033 }
2034
2035 for i, o := range dt {
2036 rr := testRR(i).(*AMTRELAY)
2037 if s := rr.String(); s != o {
2038 t.Errorf("input %#v does not match expected output %#v", s, o)
2039 }
2040 }
2041 }
2042
2043 func TestParseOPENPGPKEY(t *testing.T) {
2044 dt := map[string]string{
2045 "2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db._openpgpkey 3600 IN OPENPGPKEY mDMEZCMu8xYJKwYBBAHaRw8BAQdAH4FTbN/H5SoMBl9Ez2cFQ1NuzymK894fq2ffsYDvRkG0EWFsaWNlQGV4YW1wbGUuY29tiJYEExYKAD4CGwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AWIQRjw8oAQytQxDz5Q/Io7xpohfeBngUCZCMv5gUJAAk7ZgAKCRAo7xpohfeBnlmVAP9k0slIpLwddCD1bZ9qVjqzNcS743OIDny7XuH6x02L2wEAwxqAotO7/oUm0L4wyYR6hvGlhuGMSZXc9xMwZ1wVcA8=": "2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db._openpg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1rymjHNgl2FM7hRxkm10+huPQksdONIApfUAEQEAAYkCPAQYAQoAJhYhBGbbSw1G5F+SEI6J1Xs8dQS9cFHbBQJkI3C3AhsMBQkACTpSAAoJEHs8dQS9cFHbycgQAKq6DjwaZZP1XA2yhoMM8yVUpGTtPaBx5/fDiT7pzTy8GU3MCfYXT9kExPvBqTr2faI3gBJ+bMNkPYpmSUHq+kW1i8Q8Ibr7d3PFc83q0ZyEwPr57nlaF08Hiw7ZkTr1py55fwKF4eEZUoF0SX9AFP75FdXpAVT8/w6/gYsGwyPz4Hn08bi/7UUI0xnxtEUu8K0fheL0fLyu6Qhm7NNOnzXOwZAYV6AWrXvitsspglQE9di17sI5tu3plR/ZvnQ3tVllJQubH1x6P2+/MeXaSILOJ7LcJEAj5hYAVH6YPb0GuRx+bm5d4lNKEeII+HYhsaqGCkdwDVTiM25soe9hN7z8f+pxxhmPlCh1DlDLdr/zp9etshne4mgY9KrJD9Yjm53VCi0zhlUpEigeIiXhsh1wlG1+63C594hihXRWpA+KMjecHZzMfS4LQRs3lthN5QTdOHkKeX4ClulZV1FS+eq5kSpt/p4r9KaR1qLiZyaV43Z1ZgNfD6gbD5iC1oxYjy2tj0/hV1OWPcW0Fj+xSwmMVvGCI0dqrjO9tLnF4w4+ddaHtryBbtlAyV4HOtKoNxiBVf/Up6EOOPS6J7LOH6EYkOZwoPwBXaEdkASoAo6vTDgqBA2lIcwPg7jKX+o07McITk9BACAfxUV3oPR2nFmTGbxgY4MStUPo55P6VCt3",
2048 }
2049 for i, o := range dt {
2050 rr := testRR(i).(*OPENPGPKEY)
2051 if s := rr.String(); s != o {
2052 t.Errorf("input %#v does not match expected output %#v", s, o)
2053 }
2054 }
2055 }
2056
2057 func TestParseRRSIGAlgNames(t *testing.T) {
2058 tests := map[string]uint8{
2059 `miek.nl. IN RRSIG SOA RSASHA1 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: RSASHA1,
2060 `miek.nl. IN RRSIG SOA RSAMD5 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: RSAMD5,
2061 `miek.nl. IN RRSIG SOA ECC-GOST 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECCGOST,
2062 `miek.nl. IN RRSIG SOA ED448 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ED448,
2063 `miek.nl. IN RRSIG SOA ECDSAP256SHA256 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECDSAP256SHA256,
2064 `miek.nl. IN RRSIG SOA INDIRECT 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: INDIRECT,
2065 `miek.nl. IN RRSIG SOA BLA 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: 0,
2066 `miek.nl. IN RRSIG SOA - 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: 0,
2067 }
2068 for r, alg := range tests {
2069 rr, err := NewRR(r)
2070 if alg != 0 && err != nil {
2071 t.Error(err)
2072 continue
2073 }
2074 if alg != 0 && rr.(*RRSIG).Algorithm != alg {
2075 t.Errorf("expecting alg %d, got %d", alg, rr.(*RRSIG).Algorithm)
2076 }
2077 }
2078 }