mirror of
https://github.com/miekg/dns.git
synced 2025-08-10 11:36:58 +02:00
* Support generic net.PacketConn's for the Server
This commit adds support for listening on generic net.PacketConn's for
UDP DNS requests, previously *net.UDPConn was the only supported type.
In the event of a future v2 of this module, this should be streamlined.
* Eliminate wrapper functions around RunLocalXServerWithFinChan
* Eliminate RunLocalTCPServerWithTsig function
* Replace RunLocalTLSServer with a wrapper around RunLocalTCPServer
This reduces code duplication.
* Add net.PacketConn server tests
This provides coverage over nearly all of the newly added code (with
the unfortunate exception of (*response).RemoteAddr).
* Fix broken client_test.go tests
a433fbede4
was merged into master between this PR being opened and
being merged. This broke the CI tests in rather strange ways as the
code was being merged into master in a way that wasn't at all clear.
This commit fixes the two broken lines.
36 lines
859 B
Go
36 lines
859 B
Go
package dns
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestAcceptNotify(t *testing.T) {
|
|
HandleFunc("example.org.", handleNotify)
|
|
s, addrstr, _, err := RunLocalUDPServer(":0")
|
|
if err != nil {
|
|
t.Fatalf("unable to run test server: %v", err)
|
|
}
|
|
defer s.Shutdown()
|
|
|
|
m := new(Msg)
|
|
m.SetNotify("example.org.")
|
|
// Set a SOA hint in the answer section, this is allowed according to RFC 1996.
|
|
soa, _ := NewRR("example.org. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2018112827 7200 3600 1209600 3600")
|
|
m.Answer = []RR{soa}
|
|
|
|
c := new(Client)
|
|
resp, _, err := c.Exchange(m, addrstr)
|
|
if err != nil {
|
|
t.Errorf("failed to exchange: %v", err)
|
|
}
|
|
if resp.Rcode != RcodeSuccess {
|
|
t.Errorf("expected %s, got %s", RcodeToString[RcodeSuccess], RcodeToString[resp.Rcode])
|
|
}
|
|
}
|
|
|
|
func handleNotify(w ResponseWriter, req *Msg) {
|
|
m := new(Msg)
|
|
m.SetReply(req)
|
|
w.WriteMsg(m)
|
|
}
|