From cc486fb900c20fce761993c102763449d14a1188 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 2 Oct 2016 19:41:00 +0100 Subject: [PATCH] middleware/file: transfer from does not make sense (#314) Make it return an error when you use `transfer from` when you're not a secondary. Add tests as well. Fixes #310 --- middleware/file/setup.go | 10 +++++++--- middleware/file/setup_test.go | 7 +++++++ middleware/secondary/setup.go | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/middleware/file/setup.go b/middleware/file/setup.go index 114b370f5..dd1f17d9a 100644 --- a/middleware/file/setup.go +++ b/middleware/file/setup.go @@ -83,7 +83,7 @@ func fileParse(c *caddy.Controller) (Zones, error) { noReload := false for c.NextBlock() { - t, _, e := TransferParse(c) + t, _, e := TransferParse(c, false) if e != nil { return Zones{}, e } @@ -105,8 +105,9 @@ func fileParse(c *caddy.Controller) (Zones, error) { } // TransferParse parses transfer statements: 'transfer to [address...]'. -// Exported so secondary can use this as well. -func TransferParse(c *caddy.Controller) (tos, froms []string, err error) { +// Exported so secondary can use this as well. For the `file` middleware transfer from does +// not make sense; make this an error. +func TransferParse(c *caddy.Controller, secondary bool) (tos, froms []string, err error) { what := c.Val() if !c.NextArg() { return nil, nil, c.ArgErr() @@ -126,6 +127,9 @@ func TransferParse(c *caddy.Controller) (tos, froms []string, err error) { } } if value == "from" { + if !secondary { + return nil, nil, fmt.Errorf("can't use `transfer from` when not being a seconary") + } froms = c.RemainingArgs() for i := range froms { if froms[i] != "*" { diff --git a/middleware/file/setup_test.go b/middleware/file/setup_test.go index d2cb1cc60..9f37fd688 100644 --- a/middleware/file/setup_test.go +++ b/middleware/file/setup_test.go @@ -26,6 +26,13 @@ func TestFileParse(t *testing.T) { shouldErr bool expectedZones Zones }{ + { + `file ` + zoneFileName1 + ` miek.nl { + transfer from 127.0.0.1 + }`, + true, + Zones{}, + }, { `file`, true, diff --git a/middleware/secondary/setup.go b/middleware/secondary/setup.go index eb112faf9..d239053ff 100644 --- a/middleware/secondary/setup.go +++ b/middleware/secondary/setup.go @@ -63,7 +63,7 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) { } for c.NextBlock() { - t, f, e := file.TransferParse(c) + t, f, e := file.TransferParse(c, true) if e != nil { return file.Zones{}, e }