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:
Miek Gieben 2011-12-09 21:12:03 +01:00
parent 92736e2a8a
commit 05eb569938
5 changed files with 62 additions and 3 deletions

58
dyn_test.go Normal file
View 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())
}

View File

@ -77,7 +77,7 @@ Activate: 20110302104537`
func TestDotInName(t *testing.T) {
buf := make([]byte, 20)
packDomainName("aa\\.bb.nl.", buf, 0)
PackDomainName("aa\\.bb.nl.", buf, 0)
// index 3 must be a real dot
if buf[3] != '.' {
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.Fail()
}
dom, _, _ := unpackDomainName(buf, 0)
dom, _, _ := UnpackDomainName(buf, 0)
// printing it should yield the backspace again
if dom != "aa\\.bb.nl." {
t.Log("Dot should have been escaped: " + dom)

View File

@ -50,9 +50,10 @@ func (u *Msg) Additional() []RR {
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 {
u := new(Msg)
u.MsgHdr.Response = false
u.MsgHdr.Opcode = OpcodeUpdate
u.Question = make([]Question, 1)
u.Question[0] = Question{zone, TypeSOA, class}