diff options
author | 2018-06-15 16:12:56 +0100 | |
---|---|---|
committer | 2018-06-15 08:12:56 -0700 | |
commit | 177e32b62e1bd937317ec3fd7c7f3a8114c52d77 (patch) | |
tree | 30be44ecbeb89ad8c196e9178824ef029609f536 /plugin/proxy/proxy_test.go | |
parent | 70c957d885a6c6b33a0828c680e451a9e3a3994a (diff) | |
download | coredns-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/proxy/proxy_test.go')
-rw-r--r-- | plugin/proxy/proxy_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
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) + } +} |