Allow catalog-only zones without file= in --bind-conf mode
Zones without a file= property (e.g. ddns zones) are included in catalog zone output for secondaries but skipped in domains.conf. Previously --bind-conf required every zone to have file= set.
This commit is contained in:
@@ -73,23 +73,30 @@ func TestValidateBindConf(t *testing.T) {
|
||||
{Zone: "a.example.com.", ZoneFile: "data/a", ZonesFile: "zones.txt", Line: 1},
|
||||
{Zone: "b.example.com.", ZoneFile: "data/b", ZonesFile: "zones.txt", Line: 2},
|
||||
}
|
||||
if err := validateBindConf(entries); err != nil {
|
||||
if err := writeBindConf(filepath.Join(t.TempDir(), "domains.conf"), entries); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing file", func(t *testing.T) {
|
||||
t.Run("zones without file are skipped", func(t *testing.T) {
|
||||
entries := []ZoneEntry{
|
||||
{Zone: "a.example.com.", ZoneFile: "data/a", ZonesFile: "zones.txt", Line: 1},
|
||||
{Zone: "b.example.com.", ZoneFile: "", ZonesFile: "zones.txt", Line: 3},
|
||||
{Zone: "dyn.example.com.", ZoneFile: "", ZonesFile: "zones.txt", Line: 3},
|
||||
}
|
||||
err := validateBindConf(entries)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for missing file")
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "domains.conf")
|
||||
if err := writeBindConf(path, entries); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := string(data)
|
||||
assertContains(t, got, `zone "a.example.com"`)
|
||||
if strings.Contains(got, "dyn.example.com") {
|
||||
t.Error("catalog-only zone without file= should not appear in BIND config")
|
||||
}
|
||||
assertContains(t, err.Error(), "zones.txt:3:")
|
||||
assertContains(t, err.Error(), "b.example.com.")
|
||||
assertContains(t, err.Error(), "missing file=")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,7 +124,7 @@ func TestWriteBindConf(t *testing.T) {
|
||||
assertContains(t, got, "dnssec-policy standard")
|
||||
}
|
||||
|
||||
func TestWriteBindConfValidationError(t *testing.T) {
|
||||
func TestWriteBindConfSkipsCatalogOnlyZones(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "domains.conf")
|
||||
|
||||
@@ -125,14 +132,19 @@ func TestWriteBindConfValidationError(t *testing.T) {
|
||||
{Zone: "example.com.", ZoneFile: "", ZonesFile: "zones.txt", Line: 5},
|
||||
}
|
||||
|
||||
err := writeBindConf(path, entries)
|
||||
if err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
if err := writeBindConf(path, entries); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
assertContains(t, err.Error(), "zones.txt:5:")
|
||||
|
||||
// File should not have been written
|
||||
if _, statErr := os.Stat(path); statErr == nil {
|
||||
t.Error("file should not be written when validation fails")
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := string(data)
|
||||
|
||||
// Should have header but no zone blocks
|
||||
assertContains(t, got, "# THIS FILE IS GENERATED BY catalog-zone-gen")
|
||||
if strings.Contains(got, "example.com") {
|
||||
t.Error("zone without file= should not appear in BIND config")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user