| 1 | |
| 2 | package dns |
| 3 | |
| 4 | import ( |
| 5 | "context" |
| 6 | "errors" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/miekg/dns" |
| 10 | ) |
| 11 | |
| 12 | func TestCageDNSFailureDoesNotUseStaticOrHostResolver(t *testing.T) { |
| 13 | previous := Exchange |
| 14 | t.Cleanup(func() { Exchange = previous }) |
| 15 | Exchange = func(context.Context, *dns.Msg) (*dns.Msg, error) { return nil, errors.New("proxy down") } |
| 16 | h, err := NewHandler(HandlerOptions{StaticHosts: map[string]string{"example.com": "1.1.1.1"}}) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | q := new(dns.Msg) |
| 21 | q.SetQuestion("example.com.", dns.TypeA) |
| 22 | h.ServeDNS(TestResponseWriter{}, q) |
| 23 | if dnsResult.Rcode != dns.RcodeServerFailure || len(dnsResult.Answer) != 0 { |
| 24 | t.Fatal("expected SERVFAIL without static/host fallback") |
| 25 | } |
| 26 | } |