|
|
@ -2567,30 +2567,6 @@ func TestAgent_reloadWatchesHTTPS(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Parallel()
|
|
|
|
a := NewTestAgent(t.Name(), `
|
|
|
|
|
|
|
|
node_name = "node1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect {
|
|
|
|
|
|
|
|
proxy_defaults {
|
|
|
|
|
|
|
|
exec_mode = "script"
|
|
|
|
|
|
|
|
daemon_command = ["foo", "bar"]
|
|
|
|
|
|
|
|
script_command = ["bar", "foo"]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ports {
|
|
|
|
|
|
|
|
proxy_min_port = 20000
|
|
|
|
|
|
|
|
proxy_max_port = 20000
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
defer a.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register a target service we can use
|
|
|
|
|
|
|
|
reg := &structs.NodeService{
|
|
|
|
|
|
|
|
Service: "web",
|
|
|
|
|
|
|
|
Port: 8080,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, a.AddService(reg, nil, false, ""))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
desc string
|
|
|
@ -2621,7 +2597,10 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TargetServiceID: "web",
|
|
|
|
TargetServiceID: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
// Proxy will inherit agent's 0.0.0.0 bind address but we can't check that
|
|
|
|
|
|
|
|
// so we should default to localhost in that case.
|
|
|
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc: "default global exec mode",
|
|
|
|
desc: "default global exec mode",
|
|
|
@ -2634,7 +2613,8 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
TargetServiceID: "web",
|
|
|
|
TargetServiceID: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc: "default daemon command",
|
|
|
|
desc: "default daemon command",
|
|
|
@ -2647,7 +2627,8 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
Command: []string{"foo", "bar"},
|
|
|
|
Command: []string{"foo", "bar"},
|
|
|
|
TargetServiceID: "web",
|
|
|
|
TargetServiceID: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc: "default script command",
|
|
|
|
desc: "default script command",
|
|
|
@ -2660,7 +2641,8 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
Command: []string{"bar", "foo"},
|
|
|
|
Command: []string{"bar", "foo"},
|
|
|
|
TargetServiceID: "web",
|
|
|
|
TargetServiceID: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc: "managed proxy with custom bind port",
|
|
|
|
desc: "managed proxy with custom bind port",
|
|
|
@ -2677,7 +2659,6 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
wantTCPCheck: "127.10.10.10:1234",
|
|
|
|
wantTCPCheck: "127.10.10.10:1234",
|
|
|
|
wantErr: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// This test is necessary since JSON and HCL both will parse
|
|
|
|
// This test is necessary since JSON and HCL both will parse
|
|
|
|
// numbers as a float64.
|
|
|
|
// numbers as a float64.
|
|
|
@ -2695,12 +2676,83 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
wantTCPCheck: "127.10.10.10:1234",
|
|
|
|
wantTCPCheck: "127.10.10.10:1234",
|
|
|
|
wantErr: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
desc: "managed proxy with overridden but unspecified ipv6 bind address",
|
|
|
|
|
|
|
|
proxy: &structs.ConnectManagedProxy{
|
|
|
|
|
|
|
|
ExecMode: structs.ProxyExecModeDaemon,
|
|
|
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
|
|
|
"bind_address": "[::]",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
desc: "managed proxy with overridden check address",
|
|
|
|
|
|
|
|
proxy: &structs.ConnectManagedProxy{
|
|
|
|
|
|
|
|
ExecMode: structs.ProxyExecModeDaemon,
|
|
|
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
|
|
|
"tcp_check_address": "127.20.20.20",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantTCPCheck: "127.20.20.20:20000",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
desc: "managed proxy with disabled check",
|
|
|
|
|
|
|
|
proxy: &structs.ConnectManagedProxy{
|
|
|
|
|
|
|
|
ExecMode: structs.ProxyExecModeDaemon,
|
|
|
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
|
|
|
"disable_tcp_check": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantTCPCheck: "",
|
|
|
|
|
|
|
|
wantErr: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.desc, func(t *testing.T) {
|
|
|
|
t.Run(tt.desc, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a := NewTestAgent(t.Name(), `
|
|
|
|
|
|
|
|
node_name = "node1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Explicit test because proxies inheriting this value must have a health
|
|
|
|
|
|
|
|
# check on a different IP.
|
|
|
|
|
|
|
|
bind_addr = "0.0.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect {
|
|
|
|
|
|
|
|
proxy_defaults {
|
|
|
|
|
|
|
|
exec_mode = "script"
|
|
|
|
|
|
|
|
daemon_command = ["foo", "bar"]
|
|
|
|
|
|
|
|
script_command = ["bar", "foo"]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ports {
|
|
|
|
|
|
|
|
proxy_min_port = 20000
|
|
|
|
|
|
|
|
proxy_max_port = 20000
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
defer a.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register a target service we can use
|
|
|
|
|
|
|
|
reg := &structs.NodeService{
|
|
|
|
|
|
|
|
Service: "web",
|
|
|
|
|
|
|
|
Port: 8080,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(a.AddService(reg, nil, false, ""))
|
|
|
|
|
|
|
|
|
|
|
|
err := a.AddProxy(tt.proxy, false, "")
|
|
|
|
err := a.AddProxy(tt.proxy, false, "")
|
|
|
|
if tt.wantErr {
|
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(err)
|
|
|
|
require.Error(err)
|
|
|
@ -2719,23 +2771,23 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure a TCP check was created for the service.
|
|
|
|
// Ensure a TCP check was created for the service.
|
|
|
|
gotCheck := a.State.Check("service:web-proxy")
|
|
|
|
gotCheck := a.State.Check("service:web-proxy")
|
|
|
|
require.NotNil(gotCheck)
|
|
|
|
if tt.wantTCPCheck == "" {
|
|
|
|
require.Equal("Connect Proxy Listening", gotCheck.Name)
|
|
|
|
require.Nil(gotCheck)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Confusingly, a.State.Check("service:web-proxy") will return the state
|
|
|
|
require.NotNil(gotCheck)
|
|
|
|
// but it's Definition field will be empty. This appears to be expected
|
|
|
|
require.Equal("Connect Proxy Listening", gotCheck.Name)
|
|
|
|
// when adding Checks as part of `AddService`. Notice how `AddService`
|
|
|
|
|
|
|
|
// tests in this file don't assert on that state but instead look at the
|
|
|
|
// Confusingly, a.State.Check("service:web-proxy") will return the state
|
|
|
|
// agent's check state directly to ensure the right thing was registered.
|
|
|
|
// but it's Definition field will be empty. This appears to be expected
|
|
|
|
// We'll do the same for now.
|
|
|
|
// when adding Checks as part of `AddService`. Notice how `AddService`
|
|
|
|
gotTCP, ok := a.checkTCPs["service:web-proxy"]
|
|
|
|
// tests in this file don't assert on that state but instead look at the
|
|
|
|
require.True(ok)
|
|
|
|
// agent's check state directly to ensure the right thing was registered.
|
|
|
|
wantTCPCheck := tt.wantTCPCheck
|
|
|
|
// We'll do the same for now.
|
|
|
|
if wantTCPCheck == "" {
|
|
|
|
gotTCP, ok := a.checkTCPs["service:web-proxy"]
|
|
|
|
wantTCPCheck = "127.0.0.1:20000"
|
|
|
|
require.True(ok)
|
|
|
|
|
|
|
|
require.Equal(tt.wantTCPCheck, gotTCP.TCP)
|
|
|
|
|
|
|
|
require.Equal(10*time.Second, gotTCP.Interval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.Equal(wantTCPCheck, gotTCP.TCP)
|
|
|
|
|
|
|
|
require.Equal(10*time.Second, gotTCP.Interval)
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|