aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-06-15 16:12:56 +0100
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2018-06-15 08:12:56 -0700
commit177e32b62e1bd937317ec3fd7c7f3a8114c52d77 (patch)
tree30be44ecbeb89ad8c196e9178824ef029609f536 /plugin
parent70c957d885a6c6b33a0828c680e451a9e3a3994a (diff)
downloadcoredns-177e32b62e1bd937317ec3fd7c7f3a8114c52d77.tar.gz
coredns-177e32b62e1bd937317ec3fd7c7f3a8114c52d77.tar.zst
coredns-177e32b62e1bd937317ec3fd7c7f3a8114c52d77.zip
plugin/forward: add REFUSED test (#1878)
add a test to see if we copy the rcode correctly. Some minor cleanup in import ordering and renaming NewUpstream to New as we already are in the upstream package.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/auto/setup.go2
-rw-r--r--plugin/etcd/setup.go2
-rw-r--r--plugin/file/cname_test.go2
-rw-r--r--plugin/file/setup.go2
-rw-r--r--plugin/forward/forward_test.go25
-rw-r--r--plugin/kubernetes/setup.go2
-rw-r--r--plugin/pkg/upstream/upstream.go6
-rw-r--r--plugin/proxy/proxy_test.go27
-rw-r--r--plugin/secondary/setup.go2
-rw-r--r--plugin/template/setup.go2
10 files changed, 62 insertions, 10 deletions
diff --git a/plugin/auto/setup.go b/plugin/auto/setup.go
index 8f087e899..8791b0738 100644
--- a/plugin/auto/setup.go
+++ b/plugin/auto/setup.go
@@ -153,7 +153,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
return a, c.ArgErr()
}
var err error
- a.loader.upstream, err = upstream.NewUpstream(args)
+ a.loader.upstream, err = upstream.New(args)
if err != nil {
return a, err
}
diff --git a/plugin/etcd/setup.go b/plugin/etcd/setup.go
index e8d91a605..0cc8b0553 100644
--- a/plugin/etcd/setup.go
+++ b/plugin/etcd/setup.go
@@ -95,7 +95,7 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
if len(args) == 0 {
return nil, false, c.ArgErr()
}
- u, err := upstream.NewUpstream(args)
+ u, err := upstream.New(args)
if err != nil {
return nil, false, err
}
diff --git a/plugin/file/cname_test.go b/plugin/file/cname_test.go
index 0bc907b1f..10eb7d934 100644
--- a/plugin/file/cname_test.go
+++ b/plugin/file/cname_test.go
@@ -74,7 +74,7 @@ func TestLookupCNAMEExternal(t *testing.T) {
if err != nil {
t.Fatalf("Expected no error when reading zone, got %q", err)
}
- zone.Upstream, _ = upstream.NewUpstream([]string{"8.8.8.8:53"}) // TODO(miek): point to local instance
+ zone.Upstream, _ = upstream.New([]string{"8.8.8.8:53"}) // TODO(miek): point to local instance
fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{name: zone}, Names: []string{name}}}
ctx := context.TODO()
diff --git a/plugin/file/setup.go b/plugin/file/setup.go
index 6f83ea9f3..3f8d1969b 100644
--- a/plugin/file/setup.go
+++ b/plugin/file/setup.go
@@ -110,7 +110,7 @@ func fileParse(c *caddy.Controller) (Zones, error) {
case "upstream":
args := c.RemainingArgs()
- upstr, err = upstream.NewUpstream(args)
+ upstr, err = upstream.New(args)
if err != nil {
return Zones{}, err
}
diff --git a/plugin/forward/forward_test.go b/plugin/forward/forward_test.go
index 26167c25d..96f5fa0ce 100644
--- a/plugin/forward/forward_test.go
+++ b/plugin/forward/forward_test.go
@@ -41,3 +41,28 @@ func TestForward(t *testing.T) {
t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String())
}
}
+
+func TestForwardRefused(t *testing.T) {
+ s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
+ ret := new(dns.Msg)
+ ret.SetReply(r)
+ ret.Rcode = dns.RcodeRefused
+ w.WriteMsg(ret)
+ })
+ defer s.Close()
+
+ p := NewProxy(s.Addr, nil)
+ f := New()
+ f.SetProxy(p)
+ defer f.Close()
+
+ state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
+ state.Req.SetQuestion("example.org.", dns.TypeA)
+ resp, err := f.Forward(state)
+ if err != nil {
+ t.Fatal("Expected to receive reply, but didn't")
+ }
+ if resp.Rcode != dns.RcodeRefused {
+ t.Errorf("Expected rcode to be %d, got %d", dns.RcodeRefused, resp.Rcode)
+ }
+}
diff --git a/plugin/kubernetes/setup.go b/plugin/kubernetes/setup.go
index 2f6eab01d..9e2129f6a 100644
--- a/plugin/kubernetes/setup.go
+++ b/plugin/kubernetes/setup.go
@@ -218,7 +218,7 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
k8s.Fall.SetZonesFromArgs(c.RemainingArgs())
case "upstream":
args := c.RemainingArgs()
- u, err := upstream.NewUpstream(args)
+ u, err := upstream.New(args)
if err != nil {
return nil, err
}
diff --git a/plugin/pkg/upstream/upstream.go b/plugin/pkg/upstream/upstream.go
index 6ef131755..466da8990 100644
--- a/plugin/pkg/upstream/upstream.go
+++ b/plugin/pkg/upstream/upstream.go
@@ -18,9 +18,9 @@ type Upstream struct {
Forward *proxy.Proxy
}
-// NewUpstream creates a new Upstream for given destination(s). If dests is empty
-// it default to upstreaming to Self.
-func NewUpstream(dests []string) (Upstream, error) {
+// New creates a new Upstream for given destination(s). If dests is empty it default to upstreaming to
+// the coredns process.
+func New(dests []string) (Upstream, error) {
u := Upstream{}
if len(dests) == 0 {
u.self = true
diff --git a/plugin/proxy/proxy_test.go b/plugin/proxy/proxy_test.go
index 0d29c2329..3057715a4 100644
--- a/plugin/proxy/proxy_test.go
+++ b/plugin/proxy/proxy_test.go
@@ -9,7 +9,12 @@ import (
"testing"
"time"
+ "github.com/coredns/coredns/plugin/pkg/dnstest"
+ "github.com/coredns/coredns/plugin/test"
+ "github.com/coredns/coredns/request"
+
"github.com/mholt/caddy/caddyfile"
+ "github.com/miekg/dns"
)
func TestStop(t *testing.T) {
@@ -70,3 +75,25 @@ func TestStop(t *testing.T) {
})
}
}
+
+func TestProxyRefused(t *testing.T) {
+ s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
+ ret := new(dns.Msg)
+ ret.SetReply(r)
+ ret.Rcode = dns.RcodeRefused
+ w.WriteMsg(ret)
+ })
+ defer s.Close()
+
+ p := NewLookup([]string{s.Addr})
+
+ state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
+ state.Req.SetQuestion("example.org.", dns.TypeA)
+ resp, err := p.Forward(state)
+ if err != nil {
+ t.Fatal("Expected to receive reply, but didn't")
+ }
+ if resp.Rcode != dns.RcodeRefused {
+ t.Errorf("Expected rcode to be %d, got %d", dns.RcodeRefused, resp.Rcode)
+ }
+}
diff --git a/plugin/secondary/setup.go b/plugin/secondary/setup.go
index 90c3a3dc5..1a4115831 100644
--- a/plugin/secondary/setup.go
+++ b/plugin/secondary/setup.go
@@ -81,7 +81,7 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
case "upstream":
args := c.RemainingArgs()
var err error
- upstr, err = upstream.NewUpstream(args)
+ upstr, err = upstream.New(args)
if err != nil {
return file.Zones{}, err
}
diff --git a/plugin/template/setup.go b/plugin/template/setup.go
index 8c55f4115..cd4cc1b90 100644
--- a/plugin/template/setup.go
+++ b/plugin/template/setup.go
@@ -145,7 +145,7 @@ func templateParse(c *caddy.Controller) (handler Handler, err error) {
case "upstream":
args := c.RemainingArgs()
- u, err := upstream.NewUpstream(args)
+ u, err := upstream.New(args)
if err != nil {
return handler, err
}