2011-07-04 18:18:51 +00:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2011-07-23 21:43:43 +00:00
|
|
|
"time"
|
2011-07-04 18:18:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientSync(t *testing.T) {
|
|
|
|
m := new(Msg)
|
2012-01-08 14:34:42 +00:00
|
|
|
m.SetQuestion("miek.nl.", TypeSOA)
|
2011-07-04 18:18:51 +00:00
|
|
|
|
2012-05-26 08:28:32 +00:00
|
|
|
c := new(Client)
|
2012-05-20 10:44:49 +00:00
|
|
|
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) {
|
2012-01-08 14:34:42 +00:00
|
|
|
HandleQueryFunc("miek.nl.", helloMiek) // All queries for miek.nl will be handled by HelloMiek
|
2012-05-21 18:58:41 +00:00
|
|
|
ListenAndQuery(nil) // Detect if this isn't running
|
2011-07-04 20:27:23 +00:00
|
|
|
|
|
|
|
m := new(Msg)
|
2012-01-08 14:34:42 +00:00
|
|
|
m.SetQuestion("miek.nl.", TypeSOA)
|
2011-07-04 20:27:23 +00:00
|
|
|
|
2012-05-26 08:28:32 +00:00
|
|
|
c := new(Client)
|
2011-07-05 18:01:17 +00:00
|
|
|
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 {
|
2012-05-21 20:07:46 +00:00
|
|
|
case n := <-c.Reply:
|
2011-09-10 19:22:42 +00:00
|
|
|
if n.Reply != nil && n.Reply.Rcode != RcodeSuccess {
|
2011-07-05 18:01:17 +00:00
|
|
|
t.Log("Failed to get an valid answer")
|
|
|
|
t.Fail()
|
2011-09-10 19:22:42 +00:00
|
|
|
t.Logf("%v\n", n.Reply)
|
2011-07-05 18:01:17 +00:00
|
|
|
}
|
|
|
|
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)
|
2012-01-08 14:34:42 +00:00
|
|
|
m.SetQuestion("miek.nl.", TypeDNSKEY)
|
2011-07-04 18:18:51 +00:00
|
|
|
|
2011-11-28 05:03:21 +00:00
|
|
|
m.SetEdns0(2048, true)
|
2011-09-11 11:01:18 +00:00
|
|
|
//edns.Option = make([]Option, 1)
|
|
|
|
//edns.SetNsid("") // Empty to request it
|
2011-07-04 18:18:51 +00:00
|
|
|
|
2012-05-26 08:28:32 +00:00
|
|
|
c := new(Client)
|
2012-05-07 13:54:14 +00:00
|
|
|
r, _ := c.Exchange(m, "85.223.71.124:53")
|
2011-07-06 06:51: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 18:18:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-05 18:52:35 +00:00
|
|
|
func TestClientTsigAXFR(t *testing.T) {
|
2011-07-04 18:18:51 +00:00
|
|
|
m := new(Msg)
|
2011-09-10 23:37:06 +00:00
|
|
|
m.SetAxfr("miek.nl.")
|
2012-05-20 10:44:49 +00:00
|
|
|
m.SetTsig("axfr.", HmacMD5, 300, time.Now().Unix())
|
2011-07-23 21:43:43 +00:00
|
|
|
|
2012-05-26 08:28:32 +00:00
|
|
|
c := new(Client)
|
2012-03-02 20:19:37 +00:00
|
|
|
c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
2011-07-23 21:43:43 +00:00
|
|
|
c.Net = "tcp"
|
|
|
|
|
2012-05-20 10:44:49 +00:00
|
|
|
if a, err := c.XfrReceive(m, "85.223.71.124:53"); err != nil {
|
2011-12-10 19:54:26 +00:00
|
|
|
t.Log("Failed to setup axfr" + err.Error())
|
2011-09-10 22:31:03 +00:00
|
|
|
t.Fail()
|
2012-01-12 22:17:34 +00:00
|
|
|
return
|
2012-05-20 10:44:49 +00:00
|
|
|
} else {
|
|
|
|
for ex := range a {
|
|
|
|
t.Log(ex.Reply.String())
|
|
|
|
if ex.Error != nil {
|
|
|
|
t.Logf("Error %s\n", ex.Error.Error())
|
|
|
|
t.Fail()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if ex.Reply.Rcode != RcodeSuccess {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
t.Logf("%s\n", ex.Reply.String())
|
2012-01-12 22:17:34 +00:00
|
|
|
}
|
2011-09-11 15:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientAXFRMultipleMessages(t *testing.T) {
|
|
|
|
m := new(Msg)
|
|
|
|
m.SetAxfr("dnsex.nl.")
|
|
|
|
|
2012-05-26 08:28:32 +00:00
|
|
|
c := new(Client)
|
2011-09-11 15:01:55 +00:00
|
|
|
c.Net = "tcp"
|
2012-03-02 19:41:51 +00:00
|
|
|
// timeout?
|
2011-09-11 15:01:55 +00:00
|
|
|
|
2012-05-20 10:44:49 +00:00
|
|
|
if a, err := c.XfrReceive(m, "85.223.71.124:53"); err != nil {
|
2011-12-10 19:54:26 +00:00
|
|
|
t.Log("Failed to setup axfr" + err.Error())
|
2011-09-11 15:01:55 +00:00
|
|
|
t.Fail()
|
2012-01-12 22:17:34 +00:00
|
|
|
return
|
2012-05-20 10:44:49 +00:00
|
|
|
} else {
|
|
|
|
for ex := range a {
|
|
|
|
t.Log(ex.Reply.String())
|
|
|
|
if ex.Error != nil {
|
|
|
|
t.Logf("Error %s\n", ex.Error.Error())
|
|
|
|
t.Fail()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if ex.Reply.Rcode != RcodeSuccess {
|
|
|
|
break
|
|
|
|
}
|
2012-01-12 22:17:34 +00:00
|
|
|
}
|
2011-09-10 22:31:03 +00:00
|
|
|
}
|
2011-07-04 18:18:51 +00:00
|
|
|
}
|