Debian Codegraph @

scan_test.go

raw symbols SCIP
1 package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/"
5 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
6 "io/fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/"
7 "netscip-go gomod github.com/golang/go/src go1.25.0 net/"
8 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
9 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
10 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
11 "testing/fstestscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/"
12 )
13
14 func TestZoneParserGeneratescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserGenerate().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
15 zone := "$ORIGIN example.org.\n$GENERATE 10-12 foo${2,3,d} IN A 127.0.0.$"
16
17 wantRRs := []RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{
18 &Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: "foo012.example.org."}, Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.ParseIPscip-go gomod github.com/golang/go/src go1.25.0 net/ParseIP().("127.0.0.10")},
19 &Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: "foo013.example.org."}, Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.ParseIPscip-go gomod github.com/golang/go/src go1.25.0 net/ParseIP().("127.0.0.11")},
20 &Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: "foo014.example.org."}, Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.ParseIPscip-go gomod github.com/golang/go/src go1.25.0 net/ParseIP().("127.0.0.12")},
21 }
22
23 wantIdx := 0
24
25 z := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "", "")
26
27 for rr, ok := z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; rr, ok = z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
28 if wantIdx >= len(wantRRs) {
29 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected %d RRs, but got more", len(wantRRs))
30 }
31 if got, want := rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name., wantRRs[wantIdx].Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.; got != want {
32 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected name %s, but got %s", want, got)
33 }
34 a, okA := rr.(*Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#)
35 if !okA {
36 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected *A RR, but got %T", rr)
37 }
38 if got, want := a.Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A., wantRRs[wantIdx].(*Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#).Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.; !got.Equalscip-go gomod github.com/golang/go/src go1.25.0 net/IP#Equal().(want) {
39 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected A with IP %v, but got %v", got, want)
40 }
41 wantIdx++
42 }
43
44 if err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
45 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error, but got %s", err)
46 }
47
48 if wantIdx != len(wantRRs) {
49 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("too few records, expected %d, got %d", len(wantRRs), wantIdx)
50 }
51 }
52
53 func TestZoneParserIncludescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserInclude().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
54 tmpfile, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.CreateTempscip-go gomod github.com/golang/go/src go1.25.0 os/CreateTemp().("", "dns")
55 if err != nil {
56 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not create tmpfile for test: %s", err)
57 }
58 defer osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().())
59
60 if _, err := tmpfile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().("foo\tIN\tA\t127.0.0.1"); err != nil {
61 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to write content to tmpfile %q: %s", tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), err)
62 }
63 if err := tmpfile.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().(); err != nil {
64 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not close tmpfile %q: %s", tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), err)
65 }
66
67 zone := "$ORIGIN example.org.\n$INCLUDE " + tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().() + "\nbar\tIN\tA\t127.0.0.2"
68
69 var got int
70 z := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "", "")
71 z.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
72 for rr, ok := z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
73 switch rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name. {
74 case "foo.example.org.", "bar.example.org.":
75 default:
76 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected foo.example.org. or bar.example.org., but got %s", rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.)
77 }
78 got++
79 }
80 if err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
81 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error, but got %s", err)
82 }
83
84 if expected := 2; got != expected {
85 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to parse zone after include, expected %d records, got %d", expected, got)
86 }
87
88 osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().())
89
90 z = NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "", "")
91 z.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
92 z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().()
93 if err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil ||
94 !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), "failed to open") ||
95 !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().()) ||
96 !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), "no such file or directory") {
97 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().(`expected error to contain: "failed to open", %q and "no such file or directory" but got: %s`,
98 tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), err)
99 }
100 }
101
102 func TestZoneParserIncludeFSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserIncludeFS().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
103 fsys := fstestscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/.MapFSscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFS#{
104 "db.foo": &fstestscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/.MapFilescip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFile#{
105 Datascip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFile#Data.: []byte("foo\tIN\tA\t127.0.0.1"),
106 },
107 }
108 zone := "$ORIGIN example.org.\n$INCLUDE db.foo\nbar\tIN\tA\t127.0.0.2"
109
110 var got int
111 z := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "", "")
112 z.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
113 z.SetIncludeFSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeFS().(fsys)
114 for rr, ok := z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
115 switch rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name. {
116 case "foo.example.org.", "bar.example.org.":
117 default:
118 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected foo.example.org. or bar.example.org., but got %s", rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.)
119 }
120 got++
121 }
122 if err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
123 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error, but got %s", err)
124 }
125
126 if expected := 2; got != expected {
127 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to parse zone after include, expected %d records, got %d", expected, got)
128 }
129
130 fsys = fstestscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/.MapFSscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFS#{}
131
132 z = NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "", "")
133 z.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
134 z.SetIncludeFSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeFS().(fsys)
135 z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().()
136 if err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); !errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.ErrNotExistscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/ErrNotExist.) {
137 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().(`expected fs.ErrNotExist but got: %T %v`, err, err)
138 }
139 }
140
141 func TestZoneParserIncludeFSPathsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserIncludeFSPaths().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
142 fsys := fstestscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/.MapFSscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFS#{
143 "baz/bat/db.foo": &fstestscip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/.MapFilescip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFile#{
144 Datascip-go gomod github.com/golang/go/src go1.25.0 `testing/fstest`/MapFile#Data.: []byte("foo\tIN\tA\t127.0.0.1"),
145 },
146 }
147
148 for _, p := range []string{
149 "../bat/db.foo",
150 "/baz/bat/db.foo",
151 } {
152 zone := "$ORIGIN example.org.\n$INCLUDE " + p + "\nbar\tIN\tA\t127.0.0.2"
153 var got int
154 z := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "", "baz/quux/db.bar")
155 z.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
156 z.SetIncludeFSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeFS().(fsys)
157 for rr, ok := z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
158 switch rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name. {
159 case "foo.example.org.", "bar.example.org.":
160 default:
161 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("$INCLUDE %q: expected foo.example.org. or bar.example.org., but got %s", p, rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.)
162 }
163 got++
164 }
165 if err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
166 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("$INCLUDE %q: expected no error, but got %s", p, err)
167 }
168 if expected := 2; got != expected {
169 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("$INCLUDE %q: failed to parse zone after include, expected %d records, got %d", p, expected, got)
170 }
171 }
172 }
173
174 func TestZoneParserIncludeDisallowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserIncludeDisallowed().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
175 tmpfile, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.CreateTempscip-go gomod github.com/golang/go/src go1.25.0 os/CreateTemp().("", "dns")
176 if err != nil {
177 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not create tmpfile for test: %s", err)
178 }
179 defer osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().())
180
181 if _, err := tmpfile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().("foo\tIN\tA\t127.0.0.1"); err != nil {
182 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("unable to write content to tmpfile %q: %s", tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), err)
183 }
184 if err := tmpfile.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().(); err != nil {
185 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not close tmpfile %q: %s", tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), err)
186 }
187
188 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().("$INCLUDE "+tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().()), "example.org.", "")
189
190 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
191 }
192
193 const expect = "$INCLUDE directive not allowed"
194 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil || !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), expect) {
195 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error to contain %q, got %v", expect, err)
196 }
197 }
198
199 func TestZoneParserAddressAAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserAddressAAAA().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
200 tests := []struct {
201 record string
202 want *AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#
203 }{
204 {
205 record: "1.example.org. 600 IN AAAA ::1",
206 want: &AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: "1.example.org."}, AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#AAAA.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.IPv6loopbackscip-go gomod github.com/golang/go/src go1.25.0 net/IPv6loopback.},
207 },
208 {
209 record: "2.example.org. 600 IN AAAA ::FFFF:127.0.0.1",
210 want: &AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#{Hdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#Hdr.: RR_Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#{Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Name.: "2.example.org."}, AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#AAAA.: netscip-go gomod github.com/golang/go/src go1.25.0 net/.ParseIPscip-go gomod github.com/golang/go/src go1.25.0 net/ParseIP().("::FFFF:127.0.0.1")},
211 },
212 }
213
214 for _, tc := range tests {
215 got, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(tc.record)
216 if err != nil {
217 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error, but got %s", err)
218 }
219 aaaa, ok := got.(*AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#)
220 if !ok {
221 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected *AAAA RR, but got %T", got)
222 }
223 if !aaaa.AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#AAAA..Equalscip-go gomod github.com/golang/go/src go1.25.0 net/IP#Equal().(tc.want.AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#AAAA.) {
224 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected AAAA with IP %v, but got %v", tc.want.AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#AAAA., aaaa.AAAAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AAAA#AAAA.)
225 }
226 }
227 }
228
229 func TestZoneParserTargetBadscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserTargetBad().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
230 records := []string{
231 "bad.example.org. CNAME ; bad cname",
232 "bad.example.org. HTTPS 10 ; bad https",
233 "bad.example.org. MX 10 ; bad mx",
234 "bad.example.org. SRV 1 0 80 ; bad srv",
235 }
236
237 for _, record := range records {
238 const expect = "bad "
239 if got, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(record); err == nil || !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), expect) {
240 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("NewRR(%v) = %v, want err to contain %q", record, got, expect)
241 }
242 }
243 }
244
245 func TestZoneParserAddressBadscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestZoneParserAddressBad().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
246 records := []string{
247 "1.bad.example.org. 600 IN A ::1",
248 "2.bad.example.org. 600 IN A ::FFFF:127.0.0.1",
249 "3.bad.example.org. 600 IN AAAA 127.0.0.1",
250 }
251
252 for _, record := range records {
253 const expect = "bad A"
254 if got, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(record); err == nil || !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), expect) {
255 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("NewRR(%v) = %v, want err to contain %q", record, got, expect)
256 }
257 }
258 }
259
260 func TestParseTAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestParseTA().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
261 rr, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(` Ta 0 0 0`)
262 if err != nil {
263 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error, but got %s", err)
264 }
265 if rr == nil {
266 t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(`expected a normal RR, but got nil`)
267 }
268 }
269
270 var errTestReadErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errTestReadError. = &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{"test error"}
271
272 type errReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errReader# struct{}
273
274 func (errReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errReader#) Readscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errReader#Read().(p []byte) (int, error) { return 0, errTestReadErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errTestReadError. }
275
276 func TestParseZoneReadErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestParseZoneReadError().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
277 rr, err := ReadRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ReadRR().(errReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errReader#{}, "")
278 if err == nil || !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), errTestReadErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errTestReadError..Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#Error().()) {
279 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error to contain %q, but got %v", errTestReadErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/errTestReadError., err)
280 }
281 if rr != nil {
282 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected a nil RR, but got %v", rr)
283 }
284 }
285
286 func TestUnexpectedNewlinescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestUnexpectedNewline().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
287 zone := `
288 example.com. 60 PX
289 1000 TXT 1K
290 `
291 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "example.com.", "")
292 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
293 }
294
295 const expect = `dns: unexpected newline: "\n" at line: 2:18`
296 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil || err.Error() != expect {
297 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error to contain %q, got %v", expect, err)
298 }
299
300 // Test that newlines inside braces still work.
301 zone = `
302 example.com. 60 PX (
303 1000 TXT 1K )
304 `
305 zp = NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), "example.com.", "")
306
307 var count int
308 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
309 count++
310 }
311
312 if count != 1 {
313 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected 1 record, got %d", count)
314 }
315
316 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
317 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("unexpected error: %v", err)
318 }
319 }
320
321 func TestParseRFC3597InvalidLengthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestParseRFC3597InvalidLength().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
322 // We need to space separate the 00s otherwise it will exceed the maximum token size
323 // of the zone lexer.
324 _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().("example. 3600 CLASS1 TYPE1 \\# 65536 " + stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("00 ", 65536))
325 if err == nil {
326 t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("should not have parsed excessively long RFC3579 record")
327 }
328 }
329
330 func TestParseKnownRRAsRFC3597scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestParseKnownRRAsRFC3597().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
331 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("with RDATA", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
332 // This was found by oss-fuzz.
333 _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().("example. 3600 tYpe44 \\# 03 75 0100")
334 if err != nil {
335 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to parse RFC3579 format: %v", err)
336 }
337
338 rr, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().("example. 3600 CLASS1 TYPE1 \\# 4 7f000001")
339 if err != nil {
340 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to parse RFC3579 format: %v", err)
341 }
342
343 if rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype. != TypeAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeA. {
344 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected TypeA (1) Rrtype, but got %v", rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.)
345 }
346
347 a, ok := rr.(*Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#)
348 if !ok {
349 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected *A RR, but got %T", rr)
350 }
351
352 localhost := netscip-go gomod github.com/golang/go/src go1.25.0 net/.IPv4scip-go gomod github.com/golang/go/src go1.25.0 net/IPv4().(127, 0, 0, 1)
353 if !a.Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A..Equalscip-go gomod github.com/golang/go/src go1.25.0 net/IP#Equal().(localhost) {
354 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected A with IP %v, but got %v", localhost, a.Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.)
355 }
356 })
357 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().("without RDATA", func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
358 rr, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().("example. 3600 CLASS1 TYPE1 \\# 0")
359 if err != nil {
360 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("failed to parse RFC3579 format: %v", err)
361 }
362
363 if rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype. != TypeAscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeA. {
364 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected TypeA (1) Rrtype, but got %v", rr.Headerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#Header.().Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.)
365 }
366
367 a, ok := rr.(*Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#)
368 if !ok {
369 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected *A RR, but got %T", rr)
370 }
371
372 if len(a.Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.) != 0 {
373 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected A with empty IP, but got %v", a.Ascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/A#A.)
374 }
375 })
376 }
377
378 func TestParseOpenEscapescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestParseOpenEscape().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
379 if _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().("example.net IN CNAME example.net."); err != nil {
380 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected no error, but got: %s", err)
381 }
382 if _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().("example.net IN CNAME example.org\\"); err == nil {
383 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("expected an error, but got none")
384 }
385 }
386
387 func BenchmarkNewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkNewRR().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
388 const name1 = "12345678901234567890123456789012345.12345678.123."
389 const s = name1 + " 3600 IN MX 10 " + name1
390
391 for n := 0; n < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; n++ {
392 _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(s)
393 if err != nil {
394 b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
395 }
396 }
397 }
398
399 func BenchmarkReadRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkReadRR().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
400 const name1 = "12345678901234567890123456789012345.12345678.123."
401 const s = name1 + " 3600 IN MX 10 " + name1 + "\n"
402
403 for n := 0; n < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; n++ {
404 r := struct{ ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader# }{stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(s)}
405 // r is now only an io.Reader and won't benefit from the
406 // io.ByteReader special-case in zlexer.Next.
407
408 _, err := ReadRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ReadRR().(r, "")
409 if err != nil {
410 b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
411 }
412 }
413 }
414
415 const benchZonescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/benchZone. = `
416 foo. IN A 10.0.0.1 ; this is comment 1
417 foo. IN A (
418 10.0.0.2 ; this is comment 2
419 )
420 ; this is comment 3
421 foo. IN A 10.0.0.3
422 foo. IN A ( 10.0.0.4 ); this is comment 4
423
424 foo. IN A 10.0.0.5
425 ; this is comment 5
426
427 foo. IN A 10.0.0.6
428
429 foo. IN DNSKEY 256 3 5 AwEAAb+8l ; this is comment 6
430 foo. IN NSEC miek.nl. TXT RRSIG NSEC; this is comment 7
431 foo. IN TXT "THIS IS TEXT MAN"; this is comment 8
432 `
433
434 func BenchmarkZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkZoneParser().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
435 for n := 0; n < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; n++ {
436 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(benchZonescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/benchZone.), "example.org.", "")
437
438 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
439 }
440
441 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
442 b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
443 }
444 }
445 }
446
447 func TestEscapedStringOffsetscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestEscapedStringOffset().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
448 var cases = []struct {
449 input string
450 inputOffset int
451 expectedOffset int
452 expectedOK bool
453 }{
454 {"simple string with no escape sequences", 20, 20, true},
455 {"simple string with no escape sequences", 500, -1, true},
456 {`\;\088\\\;\120\\`, 0, 0, true},
457 {`\;\088\\\;\120\\`, 1, 2, true},
458 {`\;\088\\\;\120\\`, 2, 6, true},
459 {`\;\088\\\;\120\\`, 3, 8, true},
460 {`\;\088\\\;\120\\`, 4, 10, true},
461 {`\;\088\\\;\120\\`, 5, 14, true},
462 {`\;\088\\\;\120\\`, 6, 16, true},
463 {`\;\088\\\;\120\\`, 7, -1, true},
464 {`\`, 3, 0, false},
465 {`a\`, 3, 0, false},
466 {`aa\`, 3, 0, false},
467 {`aaa\`, 3, 3, true},
468 {`aaaa\`, 3, 3, true},
469 }
470 for i, test := range cases {
471 outputOffset, outputOK := escapedStringOffsetscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/escapedStringOffset().(test.input, test.inputOffset)
472 if outputOffset != test.expectedOffset {
473 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(
474 "Test %d (input %#q offset %d) returned offset %d but expected %d",
475 i, test.input, test.inputOffset, outputOffset, test.expectedOffset,
476 )
477 }
478 if outputOK != test.expectedOK {
479 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(
480 "Test %d (input %#q offset %d) returned ok=%t but expected %t",
481 i, test.input, test.inputOffset, outputOK, test.expectedOK,
482 )
483 }
484 }
485 }