Debian Codegraph @

update_test.go

raw symbols SCIP
1 package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
5 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
6 )
7
8 func TestDynamicUpdateParsingscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestDynamicUpdateParsing().(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#) {
9 const prefix = "example.com. IN "
10
11 for typ, name := range TypeToStringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeToString. {
12 switch typ {
13 case TypeNonescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeNone., TypeReservedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeReserved.:
14 continue
15 case TypeANYscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeANY.:
16 // ANY is ambiguous here and ends up parsed as a CLASS.
17 //
18 // TODO(tmthrgd): Using TYPE255 here doesn't seem to work and also
19 // seems to fail for some other record types. Investigate.
20 continue
21 }
22
23 s := prefix + name
24 if _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(s); err != nil {
25 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failure to parse: %s: %v", s, err)
26 }
27
28 s += " \\# 0"
29 if _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(s); err != nil {
30 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failure to parse: %s: %v", s, err)
31 }
32 }
33 }
34
35 func TestDynamicUpdateUnpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestDynamicUpdateUnpack().(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#) {
36 // From https://github.com/miekg/dns/issues/150#issuecomment-62296803
37 // It should be an update message for the zone "example.",
38 // deleting the A RRset "example." and then adding an A record at "example.".
39 // class ANY, TYPE A
40 buf := []byte{171, 68, 40, 0, 0, 1, 0, 0, 0, 2, 0, 0, 7, 101, 120, 97, 109, 112, 108, 101, 0, 0, 6, 0, 1, 192, 12, 0, 1, 0, 255, 0, 0, 0, 0, 0, 0, 192, 12, 0, 1, 0, 1, 0, 0, 0, 0, 0, 4, 127, 0, 0, 1}
41 msg := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)
42 err := msg.Unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Unpack().(buf)
43 if err != nil {
44 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to unpack: %v\n%s", err, msg.Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#String().())
45 }
46 }
47
48 func TestDynamicUpdateZeroRdataUnpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestDynamicUpdateZeroRdataUnpack().(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#) {
49 m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)
50 rr := &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.: ".", Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype.: 0, Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: 1, Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: ^uint32(0), Rdlengthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rdlength.: 0}
51 m.Answerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Answer. = []RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rr, rr, rr, rr, rr}
52 m.Nsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Ns. = m.Answerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Answer.
53 for n, s := range TypeToStringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeToString. {
54 rr.Rrtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rrtype. = n
55 bytes, err := m.Packscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Pack().()
56 if err != nil {
57 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to pack %s: %v", s, err)
58 continue
59 }
60 if err := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#).Unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Unpack().(bytes); err != nil {
61 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("failed to unpack %s: %v", s, err)
62 }
63 }
64 }
65
66 func TestRemoveRRsetscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestRemoveRRset().(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#) {
67 // Should add a zero data RR in Class ANY with a TTL of 0
68 // for each set mentioned in the RRs provided to it.
69 rr := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().(". 100 IN A 127.0.0.1")
70 m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)
71 m.Nsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Ns. = []RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{&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.: ".", 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., Classscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Class.: ClassANYscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ClassANY., Ttlscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Ttl.: 0, Rdlengthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR_Header#Rdlength.: 0}}
72 expectstr := m.Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#String().()
73 expect, err := m.Packscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Pack().()
74 if err != nil {
75 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error packing expected msg: %v", err)
76 }
77
78 m.Nsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Ns. = nil
79 m.RemoveRRsetscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#RemoveRRset().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rr})
80 actual, err := m.Packscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Pack().()
81 if err != nil {
82 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error packing actual msg: %v", err)
83 }
84 if !bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25.0 bytes/Equal().(actual, expect) {
85 tmp := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)
86 if err := tmp.Unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Unpack().(actual); err != nil {
87 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("error unpacking actual msg: %v\nexpected: %v\ngot: %v\n", err, expect, actual)
88 }
89 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected msg:\n%s", expectstr)
90 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("actual msg:\n%v", tmp)
91 }
92 }
93
94 func TestPreReqAndRemovalsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestPreReqAndRemovals().(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#) {
95 // Build a list of multiple prereqs and then some removes followed by an insert.
96 // We should be able to add multiple prereqs and updates.
97 m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)
98 m.SetUpdatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetUpdate().("example.org.")
99 m.Idscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Id. = 1234
100
101 // Use a full set of RRs each time, so we are sure the rdata is stripped.
102 rrName1 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("name_used. 3600 IN A 127.0.0.1")
103 rrName2 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("name_not_used. 3600 IN A 127.0.0.1")
104 rrRemove1 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("remove1. 3600 IN A 127.0.0.1")
105 rrRemove2 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("remove2. 3600 IN A 127.0.0.1")
106 rrRemove3 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("remove3. 3600 IN A 127.0.0.1")
107 rrInsert := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("insert. 3600 IN A 127.0.0.1")
108 rrRrset1 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("rrset_used1. 3600 IN A 127.0.0.1")
109 rrRrset2 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("rrset_used2. 3600 IN A 127.0.0.1")
110 rrRrset3 := testRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testRR().("rrset_not_used. 3600 IN A 127.0.0.1")
111
112 // Handle the prereqs.
113 m.NameUsedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#NameUsed().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrName1})
114 m.NameNotUsedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#NameNotUsed().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrName2})
115 m.RRsetUsedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#RRsetUsed().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrRrset1})
116 m.Usedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Used().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrRrset2})
117 m.RRsetNotUsedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#RRsetNotUsed().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrRrset3})
118
119 // and now the updates.
120 m.RemoveNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#RemoveName().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrRemove1})
121 m.RemoveRRsetscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#RemoveRRset().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrRemove2})
122 m.Removescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Remove().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrRemove3})
123 m.Insertscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Insert().([]RRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RR#{rrInsert})
124
125 // This test function isn't a Example function because we print these RR with tabs at the
126 // end and the Example function trim these, thus they never match.
127 // TODO(miek): don't print these tabs and make this into an Example function.
128 expect := `;; opcode: UPDATE, status: NOERROR, id: 1234
129 ;; flags:; ZONE: 1, PREREQ: 5, UPDATE: 4, ADDITIONAL: 0
130
131 ;; ZONE SECTION:
132 ;example.org. IN SOA
133
134 ;; PREREQUISITE SECTION:
135 name_used. 0 CLASS255 ANY
136 name_not_used. 0 NONE ANY
137 rrset_used1. 0 CLASS255 A
138 rrset_used2. 0 IN A 127.0.0.1
139 rrset_not_used. 0 NONE A
140
141 ;; UPDATE SECTION:
142 remove1. 0 CLASS255 ANY
143 remove2. 0 CLASS255 A
144 remove3. 0 NONE A 127.0.0.1
145 insert. 3600 IN A 127.0.0.1
146 `
147
148 if m.Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#String().() != expect {
149 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected msg:\n%s", expect)
150 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("actual msg:\n%v", m.Stringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#String().())
151 }
152 }