mirror of
https://github.com/miekg/dns.git
synced 2025-12-16 17:21:17 +01:00
Test and fix dynamic updates
* Update to the new Go version * Fix lot of things that need fixes Need a why to communicate half RRs (i.e. A record without rdata)
This commit is contained in:
parent
92736e2a8a
commit
05eb569938
58
dyn_test.go
Normal file
58
dyn_test.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func sendit(u *Msg) (r *Msg, e error) {
|
||||||
|
c := NewClient()
|
||||||
|
r, e = c.Exchange(u, "127.0.0.1:53")
|
||||||
|
return r, e
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateAdd(t *testing.T) {
|
||||||
|
u := NewUpdate("dyn.atoom.net.", ClassINET)
|
||||||
|
a := new(RR_A)
|
||||||
|
a.Hdr = RR_Header{"miek2.dyn.atoom.net.", TypeA, ClassINET, 1000, 0}
|
||||||
|
a.A = net.IPv4(127, 0, 0, 1)
|
||||||
|
rr := make([]RR, 1)
|
||||||
|
rr[0] = a
|
||||||
|
u.RRsetAddRdata(rr)
|
||||||
|
t.Log(u.String())
|
||||||
|
|
||||||
|
r, e := sendit(u)
|
||||||
|
if e != nil {
|
||||||
|
t.Log("Failed: " + e.Error())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if r != nil && r.Rcode != RcodeSuccess {
|
||||||
|
t.Log("Failed: " + r.String())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
t.Log(r.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateDelete(t *testing.T) {
|
||||||
|
u := NewUpdate("dyn.atoom.net.", ClassINET)
|
||||||
|
a := new(RR_A)
|
||||||
|
a.Hdr = RR_Header{"miek2.dyn.atoom.net.", TypeA, ClassINET, 1000, 0}
|
||||||
|
a.A = nil
|
||||||
|
rr := make([]RR, 1)
|
||||||
|
rr[0] = a
|
||||||
|
u.RRsetDelete(rr)
|
||||||
|
t.Log(u.String())
|
||||||
|
|
||||||
|
r, e := sendit(u)
|
||||||
|
if e != nil {
|
||||||
|
t.Log("Failed: " + e.Error())
|
||||||
|
t.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r != nil && r.Rcode != RcodeSuccess {
|
||||||
|
t.Log("Failed: " + r.String())
|
||||||
|
t.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Log(r.String())
|
||||||
|
}
|
||||||
@ -77,7 +77,7 @@ Activate: 20110302104537`
|
|||||||
|
|
||||||
func TestDotInName(t *testing.T) {
|
func TestDotInName(t *testing.T) {
|
||||||
buf := make([]byte, 20)
|
buf := make([]byte, 20)
|
||||||
packDomainName("aa\\.bb.nl.", buf, 0)
|
PackDomainName("aa\\.bb.nl.", buf, 0)
|
||||||
// index 3 must be a real dot
|
// index 3 must be a real dot
|
||||||
if buf[3] != '.' {
|
if buf[3] != '.' {
|
||||||
t.Log("Dot should be a real dot")
|
t.Log("Dot should be a real dot")
|
||||||
@ -88,7 +88,7 @@ func TestDotInName(t *testing.T) {
|
|||||||
t.Log("This must have the value 2")
|
t.Log("This must have the value 2")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
dom, _, _ := unpackDomainName(buf, 0)
|
dom, _, _ := UnpackDomainName(buf, 0)
|
||||||
// printing it should yield the backspace again
|
// printing it should yield the backspace again
|
||||||
if dom != "aa\\.bb.nl." {
|
if dom != "aa\\.bb.nl." {
|
||||||
t.Log("Dot should have been escaped: " + dom)
|
t.Log("Dot should have been escaped: " + dom)
|
||||||
|
|||||||
@ -50,9 +50,10 @@ func (u *Msg) Additional() []RR {
|
|||||||
return u.Extra
|
return u.Extra
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUpdate creats a new DNS update packet.
|
// NewUpdate creates a new DNS update packet, which is a normal DNS message.
|
||||||
func NewUpdate(zone string, class uint16) *Msg {
|
func NewUpdate(zone string, class uint16) *Msg {
|
||||||
u := new(Msg)
|
u := new(Msg)
|
||||||
|
u.MsgHdr.Response = false
|
||||||
u.MsgHdr.Opcode = OpcodeUpdate
|
u.MsgHdr.Opcode = OpcodeUpdate
|
||||||
u.Question = make([]Question, 1)
|
u.Question = make([]Question, 1)
|
||||||
u.Question[0] = Question{zone, TypeSOA, class}
|
u.Question[0] = Question{zone, TypeSOA, class}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user