fix(plugin/secondary): make transfer property mandatory (#7249)

* fix(plugin/secondary): make transfer property mandatory

Signed-off-by: wafuwafu13 <jaruwafu@gmail.com>
This commit is contained in:
Hirotaka Tagawa / wafuwafu13 2025-04-25 18:40:15 +01:00 committed by GitHub
parent 427b406300
commit 328165de1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View File

@ -72,6 +72,7 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
names = append(names, origins[i]) names = append(names, origins[i])
} }
hasTransfer := false
for c.NextBlock() { for c.NextBlock() {
var f []string var f []string
@ -82,6 +83,7 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
if err != nil { if err != nil {
return file.Zones{}, err return file.Zones{}, err
} }
hasTransfer = true
default: default:
return file.Zones{}, c.Errf("unknown property '%s'", c.Val()) return file.Zones{}, c.Errf("unknown property '%s'", c.Val())
} }
@ -93,6 +95,9 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
z[origin].Upstream = upstream.New() z[origin].Upstream = upstream.New()
} }
} }
if !hasTransfer {
return file.Zones{}, c.Err("secondary zones require a transfer from property")
}
} }
} }
return file.Zones{Z: z, Names: names}, nil return file.Zones{Z: z, Names: names}, nil

View File

@ -13,12 +13,6 @@ func TestSecondaryParse(t *testing.T) {
transferFrom string transferFrom string
zones []string zones []string
}{ }{
{
`secondary`,
false, // TODO(miek): should actually be true, because without transfer lines this does not make sense
"",
nil,
},
{ {
`secondary { `secondary {
transfer from 127.0.0.1 transfer from 127.0.0.1
@ -35,6 +29,20 @@ func TestSecondaryParse(t *testing.T) {
"127.0.0.1:53", "127.0.0.1:53",
[]string{"example.org."}, []string{"example.org."},
}, },
{
`secondary`,
true,
"",
nil,
},
{
`secondary example.org {
transferr from 127.0.0.1
}`,
true,
"",
nil,
},
} }
for i, test := range tests { for i, test := range tests {