aboutsummaryrefslogtreecommitdiff
path: root/plugin/transfer/select_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/transfer/select_test.go')
-rw-r--r--plugin/transfer/select_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/plugin/transfer/select_test.go b/plugin/transfer/select_test.go
new file mode 100644
index 000000000..6cb0d7681
--- /dev/null
+++ b/plugin/transfer/select_test.go
@@ -0,0 +1,58 @@
+package transfer
+
+import (
+ "context"
+ "fmt"
+ "testing"
+
+ "github.com/coredns/coredns/plugin/pkg/dnstest"
+ "github.com/coredns/coredns/plugin/test"
+
+ "github.com/miekg/dns"
+)
+
+type (
+ t1 struct{}
+ t2 struct{}
+)
+
+func (t t1) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
+ const z = "example.org."
+ if zone != z {
+ return nil, ErrNotAuthoritative
+ }
+ return nil, fmt.Errorf(z)
+}
+func (t t2) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
+ const z = "sub.example.org."
+ if zone != z {
+ return nil, ErrNotAuthoritative
+ }
+ return nil, fmt.Errorf(z)
+}
+
+func TestZoneSelection(t *testing.T) {
+ tr := &Transfer{
+ Transferers: []Transferer{t1{}, t2{}},
+ xfrs: []*xfr{
+ {
+ Zones: []string{"example.org."},
+ to: []string{"192.0.2.1"}, // RFC 5737 IP, no interface should have this address.
+ },
+ {
+ Zones: []string{"sub.example.org."},
+ to: []string{"*"},
+ },
+ },
+ }
+ r := new(dns.Msg)
+ r.SetAxfr("sub.example.org.")
+ w := dnstest.NewRecorder(&test.ResponseWriter{})
+ _, err := tr.ServeDNS(context.TODO(), w, r)
+ if err == nil {
+ t.Fatal("Expected error, got nil")
+ }
+ if x := err.Error(); x != "sub.example.org." {
+ t.Errorf("Expected transfer for zone %s, got %s", "sub.example.org", x)
+ }
+}