mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -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) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user