|
|
@ -1768,33 +1768,38 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestAgent_ServiceTokens(t *testing.T) {
|
|
|
|
func TestState_ServiceTokens(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokens := new(token.Store)
|
|
|
|
tokens := new(token.Store)
|
|
|
|
tokens.UpdateUserToken("default", token.TokenSourceConfig)
|
|
|
|
|
|
|
|
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
|
|
|
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
|
|
|
l := local.NewState(agent.LocalConfig(cfg), nil, tokens)
|
|
|
|
l := local.NewState(agent.LocalConfig(cfg), nil, tokens)
|
|
|
|
l.TriggerSyncChanges = func() {}
|
|
|
|
l.TriggerSyncChanges = func() {}
|
|
|
|
|
|
|
|
|
|
|
|
l.AddService(&structs.NodeService{ID: "redis"}, "")
|
|
|
|
id := structs.NewServiceID("redis", nil)
|
|
|
|
|
|
|
|
|
|
|
|
// Returns default when no token is set
|
|
|
|
t.Run("defaults to empty string", func(t *testing.T) {
|
|
|
|
if token := l.ServiceToken(structs.NewServiceID("redis", nil)); token != "default" {
|
|
|
|
require.Equal(t, "", l.ServiceToken(id))
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns configured token
|
|
|
|
t.Run("empty string when there is no token", func(t *testing.T) {
|
|
|
|
l.AddService(&structs.NodeService{ID: "redis"}, "abc123")
|
|
|
|
err := l.AddService(&structs.NodeService{ID: "redis"}, "")
|
|
|
|
if token := l.ServiceToken(structs.NewServiceID("redis", nil)); token != "abc123" {
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Keeps token around for the delete
|
|
|
|
require.Equal(t, "", l.ServiceToken(id))
|
|
|
|
l.RemoveService(structs.NewServiceID("redis", nil))
|
|
|
|
})
|
|
|
|
if token := l.ServiceToken(structs.NewServiceID("redis", nil)); token != "abc123" {
|
|
|
|
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
t.Run("returns configured token", func(t *testing.T) {
|
|
|
|
}
|
|
|
|
err := l.AddService(&structs.NodeService{ID: "redis"}, "abc123")
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, "abc123", l.ServiceToken(id))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("RemoveCheck keeps token around for the delete", func(t *testing.T) {
|
|
|
|
|
|
|
|
err := l.RemoveService(structs.NewServiceID("redis", nil))
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, "abc123", l.ServiceToken(id))
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func loadRuntimeConfig(t *testing.T, hcl string) *config.RuntimeConfig {
|
|
|
|
func loadRuntimeConfig(t *testing.T, hcl string) *config.RuntimeConfig {
|
|
|
@ -1805,32 +1810,38 @@ func loadRuntimeConfig(t *testing.T, hcl string) *config.RuntimeConfig {
|
|
|
|
return result.RuntimeConfig
|
|
|
|
return result.RuntimeConfig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestAgent_CheckTokens(t *testing.T) {
|
|
|
|
func TestState_CheckTokens(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokens := new(token.Store)
|
|
|
|
tokens := new(token.Store)
|
|
|
|
tokens.UpdateUserToken("default", token.TokenSourceConfig)
|
|
|
|
|
|
|
|
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
|
|
|
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
|
|
|
l := local.NewState(agent.LocalConfig(cfg), nil, tokens)
|
|
|
|
l := local.NewState(agent.LocalConfig(cfg), nil, tokens)
|
|
|
|
l.TriggerSyncChanges = func() {}
|
|
|
|
l.TriggerSyncChanges = func() {}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns default when no token is set
|
|
|
|
id := structs.NewCheckID("mem", nil)
|
|
|
|
l.AddCheck(&structs.HealthCheck{CheckID: types.CheckID("mem")}, "")
|
|
|
|
|
|
|
|
if token := l.CheckToken(structs.NewCheckID("mem", nil)); token != "default" {
|
|
|
|
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns configured token
|
|
|
|
t.Run("defaults to empty string", func(t *testing.T) {
|
|
|
|
l.AddCheck(&structs.HealthCheck{CheckID: types.CheckID("mem")}, "abc123")
|
|
|
|
require.Equal(t, "", l.CheckToken(id))
|
|
|
|
if token := l.CheckToken(structs.NewCheckID("mem", nil)); token != "abc123" {
|
|
|
|
})
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Keeps token around for the delete
|
|
|
|
t.Run("empty string when there is no token", func(t *testing.T) {
|
|
|
|
l.RemoveCheck(structs.NewCheckID("mem", nil))
|
|
|
|
err := l.AddCheck(&structs.HealthCheck{CheckID: "mem"}, "")
|
|
|
|
if token := l.CheckToken(structs.NewCheckID("mem", nil)); token != "abc123" {
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Fatalf("bad: %s", token)
|
|
|
|
|
|
|
|
}
|
|
|
|
require.Equal(t, "", l.CheckToken(id))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("returns configured token", func(t *testing.T) {
|
|
|
|
|
|
|
|
err := l.AddCheck(&structs.HealthCheck{CheckID: "mem"}, "abc123")
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, "abc123", l.CheckToken(id))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("RemoveCheck keeps token around for the delete", func(t *testing.T) {
|
|
|
|
|
|
|
|
err := l.RemoveCheck(structs.NewCheckID("mem", nil))
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, "abc123", l.CheckToken(id))
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestAgent_CheckCriticalTime(t *testing.T) {
|
|
|
|
func TestAgent_CheckCriticalTime(t *testing.T) {
|
|
|
|