mw/federation: correct parse (#1027)
Fix parse error and add testcase when a ZONE is specified. Fixes #1024
This commit is contained in:
parent
9452a0a3bc
commit
c514197d6b
2 changed files with 19 additions and 6 deletions
|
@ -49,17 +49,25 @@ func federationParse(c *caddy.Controller) (*Federation, error) {
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
// federation [zones..]
|
// federation [zones..]
|
||||||
origins := make([]string, len(c.ServerBlockKeys))
|
zones := c.RemainingArgs()
|
||||||
copy(origins, c.ServerBlockKeys)
|
origins := []string{}
|
||||||
|
if len(zones) > 0 {
|
||||||
|
origins = make([]string, len(zones))
|
||||||
|
copy(origins, zones)
|
||||||
|
} else {
|
||||||
|
origins = make([]string, len(c.ServerBlockKeys))
|
||||||
|
copy(origins, c.ServerBlockKeys)
|
||||||
|
}
|
||||||
|
|
||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
x := c.Val()
|
x := c.Val()
|
||||||
switch c.Val() {
|
switch x {
|
||||||
default:
|
default:
|
||||||
args := c.RemainingArgs()
|
args := c.RemainingArgs()
|
||||||
if len(args) != 1 {
|
if x := len(args); x != 1 {
|
||||||
return fed, fmt.Errorf("need two arguments for federation: %q", args)
|
return fed, fmt.Errorf("need two arguments for federation, got %d", x)
|
||||||
}
|
}
|
||||||
|
|
||||||
fed.f[x] = dns.Fqdn(args[0])
|
fed.f[x] = dns.Fqdn(args[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ func TestSetup(t *testing.T) {
|
||||||
expectedLen int
|
expectedLen int
|
||||||
expectedNameZone []string // contains only entry for now
|
expectedNameZone []string // contains only entry for now
|
||||||
}{
|
}{
|
||||||
|
// ok
|
||||||
{`federation {
|
{`federation {
|
||||||
prod prod.example.org
|
prod prod.example.org
|
||||||
}`, false, 1, []string{"prod", "prod.example.org."}},
|
}`, false, 1, []string{"prod", "prod.example.org."}},
|
||||||
|
@ -25,6 +26,10 @@ func TestSetup(t *testing.T) {
|
||||||
staging staging.example.org
|
staging staging.example.org
|
||||||
prod prod.example.org
|
prod prod.example.org
|
||||||
}`, false, 2, []string{"staging", "staging.example.org."}},
|
}`, false, 2, []string{"staging", "staging.example.org."}},
|
||||||
|
{`federation example.com {
|
||||||
|
staging staging.example.org
|
||||||
|
prod prod.example.org
|
||||||
|
}`, false, 2, []string{"staging", "staging.example.org."}},
|
||||||
// errors
|
// errors
|
||||||
{`federation {
|
{`federation {
|
||||||
}`, true, 0, []string{}},
|
}`, true, 0, []string{}},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue