Skip to content

Commit

Permalink
Update IsEmpty to check for pre-1.2.4 fields (#11930)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekStrickland authored and tgross committed Jan 28, 2022
1 parent 2f9accb commit 143fb90
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/11902.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
template: Fixed a bug where client template configuration that did not include any
of the new 1.2.4 configuration options could result in none of the configuration getting set.
```
5 changes: 4 additions & 1 deletion client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ func (c *ClientTemplateConfig) IsEmpty() bool {
return true
}

return c.BlockQueryWaitTime == nil &&
return !c.DisableSandbox &&
len(c.FunctionDenylist) == 0 &&
len(c.FunctionBlacklist) == 0 &&
c.BlockQueryWaitTime == nil &&
c.BlockQueryWaitTimeHCL == "" &&
c.MaxStale == nil &&
c.MaxStaleHCL == "" &&
Expand Down
35 changes: 35 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,41 @@ func TestConfig_LoadConsulTemplateConfig(t *testing.T) {
require.Equal(t, 20*time.Second, *templateConfig.VaultRetry.MaxBackoff)
}

func TestConfig_LoadConsulTemplateBasic(t *testing.T) {
defaultConfig := DefaultConfig()

// hcl
agentConfig, err := LoadConfig("test-resources/client_with_basic_template.hcl")
require.NoError(t, err)
require.NotNil(t, agentConfig.Client.TemplateConfig)

agentConfig = defaultConfig.Merge(agentConfig)

clientAgent := Agent{config: agentConfig}
clientConfig, err := clientAgent.clientConfig()
require.NoError(t, err)

templateConfig := clientConfig.TemplateConfig
require.NotNil(t, templateConfig)
require.True(t, templateConfig.DisableSandbox)
require.Len(t, templateConfig.FunctionDenylist, 1)

// json
agentConfig, err = LoadConfig("test-resources/client_with_basic_template.json")
require.NoError(t, err)

agentConfig = defaultConfig.Merge(agentConfig)

clientAgent = Agent{config: agentConfig}
clientConfig, err = clientAgent.clientConfig()
require.NoError(t, err)

templateConfig = clientConfig.TemplateConfig
require.NotNil(t, templateConfig)
require.True(t, templateConfig.DisableSandbox)
require.Len(t, templateConfig.FunctionDenylist, 1)
}

func TestParseMultipleIPTemplates(t *testing.T) {
testCases := []struct {
name string
Expand Down
9 changes: 9 additions & 0 deletions command/agent/test-resources/client_with_basic_template.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

client {
enabled = true

template {
disable_file_sandbox = true
function_denylist = []
}
}
9 changes: 9 additions & 0 deletions command/agent/test-resources/client_with_basic_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"client": {
"enabled": true,
"template": {
"disable_file_sandbox": true,
"function_denylist": []
}
}
}

0 comments on commit 143fb90

Please sign in to comment.