dns/client_test.go

99 lines
2.0 KiB
Go
Raw Normal View History

2011-07-04 18:18:51 +00:00
package dns
import (
"testing"
"time"
2011-07-04 18:18:51 +00:00
)
func TestClientSync(t *testing.T) {
m := new(Msg)
2011-07-05 18:01:17 +00:00
m.SetQuestion("miek.nl", TypeSOA)
2011-07-04 18:18:51 +00:00
2011-07-05 18:01:17 +00:00
c := NewClient()
r := c.Exchange(m, "85.223.71.124:53")
2011-07-04 18:18:51 +00:00
if r != nil && r.Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer")
t.Fail()
t.Logf("%v\n", r)
}
}
2011-07-04 20:27:23 +00:00
func helloMiek(w RequestWriter, r *Msg) {
2011-07-05 18:01:17 +00:00
w.Send(r)
reply, _ := w.Receive()
w.Write(reply)
2011-07-04 20:27:23 +00:00
}
func TestClientASync(t *testing.T) {
2011-07-05 18:01:17 +00:00
HandleQueryFunc("miek.nl", helloMiek) // All queries for miek.nl will be handled by HelloMiek
ListenAndQuery(nil, nil) // Detect if this isn't running
2011-07-04 20:27:23 +00:00
m := new(Msg)
2011-07-05 18:01:17 +00:00
m.SetQuestion("miek.nl", TypeSOA)
2011-07-04 20:27:23 +00:00
2011-07-05 18:01:17 +00:00
c := NewClient()
c.Do(m, "85.223.71.124:53")
2011-07-04 20:27:23 +00:00
forever:
2011-07-05 18:01:17 +00:00
for {
select {
case n := <-DefaultReplyChan:
if n[1] != nil && n[1].Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer")
t.Fail()
t.Logf("%v\n", n[1])
}
break forever
}
}
2011-07-04 20:27:23 +00:00
}
2011-07-06 06:51:51 +00:00
func TestClientEDNS0(t *testing.T) {
m := new(Msg)
m.SetQuestion("miek.nl", TypeDNSKEY)
2011-07-04 18:18:51 +00:00
edns := new(RR_OPT)
edns.Hdr.Name = "." // must . be for edns
edns.Hdr.Rrtype = TypeOPT
// You can handle an OTP RR as any other, but there
// are some convience functions
edns.SetUDPSize(2048)
edns.SetDo()
edns.Option = make([]Option, 1)
edns.SetNsid("") // Empty to request it
m.Extra = make([]RR, 1)
m.Extra[0] = edns
2011-07-06 06:51:51 +00:00
c := NewClient()
r := c.Exchange(m, "85.223.71.124:53")
if r != nil && r.Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer")
t.Fail()
t.Logf("%v\n", r)
2011-07-04 18:18:51 +00:00
}
}
func TestClientTsigAXFR(t *testing.T) {
2011-07-04 18:18:51 +00:00
m := new(Msg)
m.SetAxfr("miek.nl")
m.SetTsig("axfr", HmacMD5, 300, uint64(time.Seconds()))
secrets := make(map[string]string)
secrets["axfr"] = "so6ZGir4GPAqINNh9U5c3A=="
c := NewClient()
c.Net = "tcp"
c.TsigSecret = secrets
2011-07-05 19:09:48 +00:00
c.XfrReceive(m, "85.223.71.124:53")
/*
if err != nil {
t.Log("%s\n", err.String())
t.Fail()
}
*/
2011-07-04 18:18:51 +00:00
}