Skip to content

Commit

Permalink
Merge branch 'main' into cleanup/fleet_gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksmaus authored Jul 19, 2024
2 parents 7d59aae + 482eecb commit ac34927
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ func TestPolicyChange(t *testing.T) {
change := <-ch
require.Equal(t, config.MustNewConfigFrom(conf), change.Config())
})
t.Run("Received config with $$ in inputs", func(t *testing.T) {
ch := make(chan coordinator.ConfigChange, 1)

conf := map[string]interface{}{
"inputs": []interface{}{map[string]interface{}{
"type": "key",
"key": "$$$$",
}}}
action := &fleetapi.ActionPolicyChange{
ActionID: "abc123",
ActionType: "POLICY_CHANGE",
Data: fleetapi.ActionPolicyChangeData{
Policy: conf,
},
}

cfg := configuration.DefaultConfiguration()
handler := NewPolicyChangeHandler(log, agentInfo, cfg, nullStore, ch, nilLogLevelSet(t), &coordinator.Coordinator{})

err := handler.Handle(context.Background(), action, ack)
require.NoError(t, err)

change := <-ch
m, err := change.Config().ToMapStr()
require.NoError(t, err)

require.Equal(t, conf, m)
})
}

func TestPolicyAcked(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions internal/pkg/agent/transpiler/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ func TestAST(t *testing.T) {
},
},
},
"special characters in strings": {
hashmap: map[string]interface{}{
"key": "$1$$2$$$3$$$$4",
"$1$$2$$$3$$$$4": "value",
},
ast: &AST{
root: &Dict{
value: []Node{
&Key{name: "key", value: &StrVal{value: "$1$$2$$$3$$$$4"}},
&Key{name: "$1$$2$$$3$$$$4", value: &StrVal{value: "value"}},
},
},
},
},
"integer as key": {
hashmap: map[string]interface{}{
"1": []string{"/var/log/log1", "/var/log/log2"},
Expand Down
44 changes: 44 additions & 0 deletions internal/pkg/agent/transpiler/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func TestVars_Replace(t *testing.T) {
"other": map[string]interface{}{
"data": "info",
},
"special": map[string]interface{}{
"key1": "$1$$2",
"key2": "1$2$$",
"key3": "${abcd}",
"key4": "$${abcd}",
"key5": "${",
"key6": "$${",
},
})
tests := []struct {
Input string
Expand Down Expand Up @@ -209,6 +217,42 @@ func TestVars_Replace(t *testing.T) {
false,
false,
},
{
`${special.key1}`,
NewStrVal("$1$$2"),
false,
false,
},
{
`${special.key2}`,
NewStrVal("1$2$$"),
false,
false,
},
{
`${special.key3}`,
NewStrVal("${abcd}"),
false,
false,
},
{
`${special.key4}`,
NewStrVal("$${abcd}"),
false,
false,
},
{
`${special.key5}`,
NewStrVal("${"),
false,
false,
},
{
`${special.key6}`,
NewStrVal("$${"),
false,
false,
},
}
for _, test := range tests {
t.Run(test.Input, func(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions internal/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,18 @@ func dumpToYAML(t *testing.T, out string, in interface{}) {
err = os.WriteFile(out, b, 0600)
require.NoError(t, err)
}

func TestDollarSignsInInputs(t *testing.T) {
in := map[string]interface{}{
"inputs": []interface{}{
map[string]interface{}{
"type": "logfile",
"what": "$$$$",
},
},
}
c := MustNewConfigFrom(in)
out, err := c.ToMapStr()
assert.NoError(t, err)
assert.Equal(t, in, out)
}

0 comments on commit ac34927

Please sign in to comment.