fix(auto/file): return REFUSED when no next plugin is available (#7381)

This commit is contained in:
Cameron Steel
2025-07-04 19:39:19 +10:00
committed by GitHub
parent 1449cb660e
commit 0aee758833
4 changed files with 50 additions and 33 deletions

View File

@@ -104,39 +104,44 @@ func TestAutoServeDNSZoneMatching(t *testing.T) {
t.Parallel()
tests := []struct {
name string
origins []string
names []string
qname string
hasZone bool
name string
origins []string
names []string
qname string
hasZone bool
shouldRefuse bool
}{
{
name: "exact zone match",
origins: []string{"example.org."},
names: []string{"example.org."},
qname: "test.example.org.",
hasZone: true,
name: "exact zone match",
origins: []string{"example.org."},
names: []string{"example.org."},
qname: "test.example.org.",
hasZone: true,
shouldRefuse: false,
},
{
name: "subdomain zone match",
origins: []string{"example.org."},
names: []string{"example.org."},
qname: "sub.test.example.org.",
hasZone: true,
name: "subdomain zone match",
origins: []string{"example.org."},
names: []string{"example.org."},
qname: "sub.test.example.org.",
hasZone: true,
shouldRefuse: false,
},
{
name: "no origin match",
origins: []string{"other.org."},
names: []string{"example.org."},
qname: "test.example.org.",
hasZone: false,
name: "no origin match",
origins: []string{"other.org."},
names: []string{"example.org."},
qname: "test.example.org.",
hasZone: false,
shouldRefuse: false,
},
{
name: "origin match but no name match",
origins: []string{"example.org."},
names: []string{"other.org."},
qname: "test.example.org.",
hasZone: false,
name: "origin match but no name match",
origins: []string{"example.org."},
names: []string{"other.org."},
qname: "test.example.org.",
hasZone: false,
shouldRefuse: true,
},
}
@@ -163,14 +168,18 @@ func TestAutoServeDNSZoneMatching(t *testing.T) {
rec := dnstest.NewRecorder(&test.ResponseWriter{})
ctx := context.Background()
_, err := a.ServeDNS(ctx, rec, m)
code, err := a.ServeDNS(ctx, rec, m)
if tt.hasZone {
if err != nil {
t.Errorf("Expected no error for zone match, got: %v", err)
}
} else {
if err == nil {
if tt.shouldRefuse {
if code != dns.RcodeRefused {
t.Errorf("Expected code %d, got %d", dns.RcodeRefused, code)
}
} else if err == nil {
t.Errorf("Expected error for no zone match, got nil")
}
}