mirror of https://github.com/status-im/consul.git
agent: Disallow 0.0.0.0 as advertise or advertise-wan address
Fixes #2961
This commit is contained in:
parent
73a31b9bfe
commit
e365ef12cf
|
@ -361,6 +361,16 @@ func (c *Command) readConfig() *Config {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.AdvertiseAddr == "0.0.0.0" {
|
||||||
|
c.UI.Error("Advertise address cannot be 0.0.0.0")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.AdvertiseAddrWan == "0.0.0.0" {
|
||||||
|
c.UI.Error("Advertise WAN address cannot be 0.0.0.0")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Compile all the watches
|
// Compile all the watches
|
||||||
for _, params := range config.Watches {
|
for _, params := range config.Watches {
|
||||||
// Parse the watches, excluding the handler
|
// Parse the watches, excluding the handler
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -50,6 +51,36 @@ func TestValidDatacenter(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestConfigFail should test command line flags that lead to an immediate error.
|
||||||
|
func TestConfigFail(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
args []string
|
||||||
|
out string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
args: []string{"agent", "-server", "-data-dir", "foo", "-advertise", "0.0.0.0"},
|
||||||
|
out: "==> Advertise address cannot be 0.0.0.0\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"agent", "-server", "-data-dir", "foo", "-advertise-wan", "0.0.0.0"},
|
||||||
|
out: "==> Advertise WAN address cannot be 0.0.0.0\n",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(strings.Join(tt.args, " "), func(t *testing.T) {
|
||||||
|
cmd := exec.Command("consul", tt.args...)
|
||||||
|
b, err := cmd.CombinedOutput()
|
||||||
|
if got, want := err, "exit status 1"; got == nil || got.Error() != want {
|
||||||
|
t.Fatalf("got err %q want %q", got, want)
|
||||||
|
}
|
||||||
|
if got, want := string(b), tt.out; got != want {
|
||||||
|
t.Fatalf("got %q want %q", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRetryJoin(t *testing.T) {
|
func TestRetryJoin(t *testing.T) {
|
||||||
dir, agent := makeAgent(t, nextConfig())
|
dir, agent := makeAgent(t, nextConfig())
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
Loading…
Reference in New Issue