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)
|
2011-07-06 04:01:17 +10:00
|
|
|
m.SetQuestion("miek.nl", TypeSOA)
|
2011-07-05 04:18:51 +10:00
|
|
|
|
2011-07-06 04:01:17 +10:00
|
|
|
c := NewClient()
|
2011-08-08 21:21:18 +10:00
|
|
|
r, _ := c.Exchange(m, "85.223.71.124: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-05 06:27:23 +10:00
|
|
|
func helloMiek(w RequestWriter, r *Msg) {
|
2011-07-06 04:01:17 +10:00
|
|
|
w.Send(r)
|
|
|
|
reply, _ := w.Receive()
|
|
|
|
w.Write(reply)
|
2011-07-05 06:27:23 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientASync(t *testing.T) {
|
2011-07-06 04:01:17 +10: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-05 06:27:23 +10:00
|
|
|
|
|
|
|
m := new(Msg)
|
2011-07-06 04:01:17 +10:00
|
|
|
m.SetQuestion("miek.nl", TypeSOA)
|
2011-07-05 06:27:23 +10:00
|
|
|
|
2011-07-06 04:01:17 +10:00
|
|
|
c := NewClient()
|
|
|
|
c.Do(m, "85.223.71.124:53")
|
2011-07-05 06:27:23 +10:00
|
|
|
|
|
|
|
forever:
|
2011-07-06 04:01:17 +10:00
|
|
|
for {
|
|
|
|
select {
|
2011-09-11 08:31:03 +10:00
|
|
|
case n := <-c.ReplyChan:
|
2011-09-11 05:22:42 +10:00
|
|
|
if n.Reply != nil && n.Reply.Rcode != RcodeSuccess {
|
2011-07-06 04:01:17 +10:00
|
|
|
t.Log("Failed to get an valid answer")
|
|
|
|
t.Fail()
|
2011-09-11 05:22:42 +10:00
|
|
|
t.Logf("%v\n", n.Reply)
|
2011-07-06 04:01:17 +10:00
|
|
|
}
|
|
|
|
break forever
|
|
|
|
}
|
|
|
|
}
|
2011-07-05 06:27:23 +10:00
|
|
|
}
|
|
|
|
|
2011-07-06 16:51:51 +10:00
|
|
|
func TestClientEDNS0(t *testing.T) {
|
|
|
|
m := new(Msg)
|
|
|
|
m.SetQuestion("miek.nl", TypeDNSKEY)
|
2011-07-05 04:18:51 +10:00
|
|
|
|
2011-09-11 21:01:18 +10:00
|
|
|
m.SetEdns0(2048, true)
|
|
|
|
//edns.Option = make([]Option, 1)
|
|
|
|
//edns.SetNsid("") // Empty to request it
|
2011-07-05 04:18:51 +10:00
|
|
|
|
2011-07-06 16:51:51 +10:00
|
|
|
c := NewClient()
|
2011-08-08 21:21:18 +10:00
|
|
|
r, _ := c.Exchange(m, "85.223.71.124: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.")
|
2011-07-06 04:52:35 +10:00
|
|
|
|
2011-09-11 09:37:06 +10:00
|
|
|
m.SetTsig("axfr.", HmacMD5, 300, uint64(time.Seconds()))
|
2011-09-11 09:10:47 +10:00
|
|
|
TsigGenerate(m, "so6ZGir4GPAqINNh9U5c3A==", "", false)
|
2011-07-24 07:43:43 +10:00
|
|
|
secrets := make(map[string]string)
|
2011-09-11 09:37:06 +10:00
|
|
|
secrets["axfr."] = "so6ZGir4GPAqINNh9U5c3A=="
|
2011-07-24 07:43:43 +10:00
|
|
|
|
2011-09-11 09:10:47 +10:00
|
|
|
println(m.String())
|
2011-07-24 07:43:43 +10:00
|
|
|
c := NewClient()
|
|
|
|
c.Net = "tcp"
|
|
|
|
c.TsigSecret = secrets
|
|
|
|
|
2011-09-11 08:31:03 +10:00
|
|
|
if err := c.XfrReceive(m, "85.223.71.124:53"); err != nil {
|
|
|
|
t.Log("Failed to setup axfr" + err.String())
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
ex := <-c.ReplyChan
|
|
|
|
println(ex.Reply.String())
|
2011-09-11 08:33:13 +10:00
|
|
|
println(ex.Error.String())
|
|
|
|
if ex.Error != nil {
|
|
|
|
break
|
|
|
|
}
|
2011-09-11 08:31:03 +10:00
|
|
|
}
|
2011-07-05 04:18:51 +10:00
|
|
|
}
|