2011-07-05 04:18:51 +10:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2011-07-24 07:43:43 +10:00
|
|
|
"time"
|
2011-07-05 04:18:51 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientSync(t *testing.T) {
|
|
|
|
m := new(Msg)
|
2012-01-09 01:34:42 +11:00
|
|
|
m.SetQuestion("miek.nl.", TypeSOA)
|
2011-07-05 04:18:51 +10:00
|
|
|
|
2012-05-26 18:28:32 +10:00
|
|
|
c := new(Client)
|
2012-11-20 02:19:17 +11:00
|
|
|
r, _, _ := c.Exchange(m, "37.251.95.53:53")
|
2011-07-05 04:18:51 +10:00
|
|
|
|
|
|
|
if r != nil && r.Rcode != RcodeSuccess {
|
|
|
|
t.Log("Failed to get an valid answer")
|
|
|
|
t.Fail()
|
|
|
|
t.Logf("%v\n", r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-06 16:51:51 +10:00
|
|
|
func TestClientEDNS0(t *testing.T) {
|
|
|
|
m := new(Msg)
|
2012-01-09 01:34:42 +11:00
|
|
|
m.SetQuestion("miek.nl.", TypeDNSKEY)
|
2011-07-05 04:18:51 +10:00
|
|
|
|
2011-11-28 16:03:21 +11:00
|
|
|
m.SetEdns0(2048, true)
|
2011-09-11 21:01:18 +10:00
|
|
|
//edns.Option = make([]Option, 1)
|
|
|
|
//edns.SetNsid("") // Empty to request it
|
2011-07-05 04:18:51 +10:00
|
|
|
|
2012-05-26 18:28:40 +10:00
|
|
|
c := new(Client)
|
2012-11-20 02:19:17 +11:00
|
|
|
r, _, _ := c.Exchange(m, "37.251.95.53:53")
|
2011-07-06 16:51:51 +10:00
|
|
|
|
|
|
|
if r != nil && r.Rcode != RcodeSuccess {
|
|
|
|
t.Log("Failed to get an valid answer")
|
|
|
|
t.Fail()
|
|
|
|
t.Logf("%v\n", r)
|
2011-07-05 04:18:51 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-06 04:52:35 +10:00
|
|
|
func TestClientTsigAXFR(t *testing.T) {
|
2011-07-05 04:18:51 +10:00
|
|
|
m := new(Msg)
|
2011-09-11 09:37:06 +10:00
|
|
|
m.SetAxfr("miek.nl.")
|
2012-05-20 20:44:49 +10:00
|
|
|
m.SetTsig("axfr.", HmacMD5, 300, time.Now().Unix())
|
2011-07-24 07:43:43 +10:00
|
|
|
|
2012-05-26 18:28:32 +10:00
|
|
|
c := new(Client)
|
2012-03-03 07:19:37 +11:00
|
|
|
c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
2011-07-24 07:43:43 +10:00
|
|
|
c.Net = "tcp"
|
|
|
|
|
2012-11-20 02:19:17 +11:00
|
|
|
if a, err := c.XfrReceive(m, "37.251.95.53:53"); err != nil {
|
2012-10-10 07:45:19 +11:00
|
|
|
t.Log("Failed to setup axfr: " + err.Error())
|
2011-09-11 08:31:03 +10:00
|
|
|
t.Fail()
|
2012-01-13 09:17:34 +11:00
|
|
|
return
|
2012-05-20 20:44:49 +10:00
|
|
|
} else {
|
|
|
|
for ex := range a {
|
|
|
|
if ex.Error != nil {
|
|
|
|
t.Logf("Error %s\n", ex.Error.Error())
|
|
|
|
t.Fail()
|
|
|
|
break
|
|
|
|
}
|
2012-08-31 22:59:56 +10:00
|
|
|
for _, rr := range ex.RR {
|
|
|
|
t.Logf("%s\n", rr.String())
|
2012-05-20 20:44:49 +10:00
|
|
|
}
|
2012-01-13 09:17:34 +11:00
|
|
|
}
|
2011-09-12 01:01:55 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientAXFRMultipleMessages(t *testing.T) {
|
|
|
|
m := new(Msg)
|
|
|
|
m.SetAxfr("dnsex.nl.")
|
|
|
|
|
2012-05-26 18:28:32 +10:00
|
|
|
c := new(Client)
|
2011-09-12 01:01:55 +10:00
|
|
|
c.Net = "tcp"
|
|
|
|
|
2012-11-20 02:19:17 +11:00
|
|
|
if a, err := c.XfrReceive(m, "37.251.95.53:53"); err != nil {
|
2011-12-11 06:54:26 +11:00
|
|
|
t.Log("Failed to setup axfr" + err.Error())
|
2011-09-12 01:01:55 +10:00
|
|
|
t.Fail()
|
2012-01-13 09:17:34 +11:00
|
|
|
return
|
2012-05-20 20:44:49 +10:00
|
|
|
} else {
|
|
|
|
for ex := range a {
|
|
|
|
if ex.Error != nil {
|
|
|
|
t.Logf("Error %s\n", ex.Error.Error())
|
|
|
|
t.Fail()
|
|
|
|
break
|
|
|
|
}
|
2012-01-13 09:17:34 +11:00
|
|
|
}
|
2011-09-11 08:31:03 +10:00
|
|
|
}
|
2011-07-05 04:18:51 +10:00
|
|
|
}
|
2012-10-16 04:37:19 +11:00
|
|
|
|
|
|
|
// not really a test, but shows how to use update leases
|
|
|
|
func TestUpdateLeaseTSIG(t *testing.T) {
|
|
|
|
m := new(Msg)
|
|
|
|
m.SetUpdate("t.local.ip6.io.")
|
|
|
|
rr, _ := NewRR("t.local.ip6.io. 30 A 127.0.0.1")
|
|
|
|
rrs := make([]RR, 1)
|
|
|
|
rrs[0] = rr
|
2012-10-16 19:41:20 +11:00
|
|
|
m.Insert(rrs)
|
2012-10-16 04:37:19 +11:00
|
|
|
|
|
|
|
lease_rr := new(RR_OPT)
|
|
|
|
lease_rr.Hdr.Name = "."
|
|
|
|
lease_rr.Hdr.Rrtype = TypeOPT
|
|
|
|
e := new(EDNS0_UPDATE_LEASE)
|
|
|
|
e.Code = EDNS0UPDATELEASE
|
|
|
|
e.Lease = 120
|
|
|
|
lease_rr.Option = append(lease_rr.Option, e)
|
|
|
|
m.Extra = append(m.Extra, lease_rr)
|
|
|
|
|
|
|
|
c := new(Client)
|
|
|
|
m.SetTsig("polvi.", HmacMD5, 300, time.Now().Unix())
|
|
|
|
c.TsigSecret = map[string]string{"polvi.": "pRZgBrBvI4NAHZYhxmhs/Q=="}
|
|
|
|
|
|
|
|
w := new(reply)
|
|
|
|
w.client = c
|
|
|
|
w.addr = "127.0.0.1:53"
|
|
|
|
w.req = m
|
|
|
|
|
|
|
|
if err := w.dial(); err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
if err := w.send(m); err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|