Enforce a valid port for the Serf WAN since it can't be disabled.

Fixes #3817
This commit is contained in:
Kyle Havlovitz 2018-01-19 13:48:31 -08:00
parent dac4367fb2
commit f191eb2df3
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
2 changed files with 20 additions and 0 deletions

View File

@ -369,6 +369,9 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
if ipaddr.IsAny(b.stringVal(c.AdvertiseAddrWAN)) {
return RuntimeConfig{}, fmt.Errorf("Advertise WAN address cannot be 0.0.0.0, :: or [::]")
}
if serfPortWAN < 0 {
return RuntimeConfig{}, fmt.Errorf("ports.serf_wan must be a valid port from 1 to 65535")
}
bindAddr := bindAddrs[0].(*net.IPAddr)
advertiseAddr := b.makeIPAddr(b.expandFirstIP("advertise_addr", c.AdvertiseAddrLAN), bindAddr)

View File

@ -1064,6 +1064,23 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
rt.DataDir = dataDir
},
},
{
desc: "serf wan port > 0",
args: []string{`-data-dir=` + dataDir},
json: []string{`{
"ports": {
"serf_wan": -1
},
"advertise_addr_wan": "1.2.3.4"
}`},
hcl: []string{`
ports {
serf_wan = -1
}
advertise_addr_wan = "1.2.3.4"
`},
err: "ports.serf_wan must be a valid port from 1 to 65535",
},
{
desc: "serf bind address lan template",
args: []string{`-data-dir=` + dataDir},