Skip to content

Commit

Permalink
resolve minion override issue in config screen
Browse files Browse the repository at this point in the history
  • Loading branch information
jertel committed Sep 18, 2024
1 parent eaff8f6 commit 02ad722
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/modules/salt/saltstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (store *Saltstore) recursivelyParseSettings(
merged := false
if minion == "" {
for _, existing := range settings {
if existing.Id == newId {
if existing.Id == newId && existing.NodeId == "" {
existing.Value = newValue
if existing.Multiline != multiline {
log.WithFields(log.Fields{
Expand Down
24 changes: 21 additions & 3 deletions server/modules/salt/saltstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
package salt

import (
"cmp"
"context"
"errors"
"os"
"os/exec"
"path/filepath"
"slices"
"testing"

"github.com/security-onion-solutions/securityonion-soc/model"
Expand All @@ -23,7 +25,7 @@ import (
const TMP_SALTSTACK_PATH = "/tmp/gotest-soc-saltstore"
const TMP_QUEUE_DIR = "/tmp/gotest-soc-salt-relay-queue"
const TMP_REQUEST_FILE = "req"
const TEST_SETTINGS_COUNT = 24
const TEST_SETTINGS_COUNT = 26

func Cleanup() {
exec.Command("rm", "-fr", TMP_SALTSTACK_PATH).Run()
Expand Down Expand Up @@ -200,9 +202,19 @@ func TestGetSettings(tester *testing.T) {

salt := NewTestSalt()
settings, err := salt.GetSettings(ctx(), true)
slices.SortFunc(settings,
func(a, b *model.Setting) int {
return cmp.Compare(a.Id, b.Id)
})
assert.NoError(tester, err)

count := 0

assert.Equal(tester, "myapp.advanced", settings[count].Id)
assert.Equal(tester, "myapp:\n global: advanced\n", settings[count].Value)
assert.Equal(tester, "", settings[count].NodeId)
count++

assert.Equal(tester, "myapp.bar", settings[count].Id)
assert.Equal(tester, "minion-override", settings[count].Value)
assert.Equal(tester, "normal_import", settings[count].NodeId)
Expand Down Expand Up @@ -329,8 +341,14 @@ func TestGetSettings(tester *testing.T) {
assert.Equal(tester, "", settings[count].NodeId)
count++

assert.Equal(tester, "myapp.advanced", settings[count].Id)
assert.Equal(tester, "myapp:\n global: advanced\n", settings[count].Value)
assert.Equal(tester, "myapp.zdef", settings[count].Id)
assert.Equal(tester, "strawberry", settings[count].Value)
assert.Equal(tester, "normal_import", settings[count].NodeId)
count++

assert.Equal(tester, "myapp.zdef", settings[count].Id)
assert.Equal(tester, "chocolate", settings[count].Value)
assert.Equal(tester, "vanilla", settings[count].Default)
assert.Equal(tester, "", settings[count].NodeId)
count++

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
myapp:
my_def:
- item1
- item2
- item2
zdef: vanilla
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
myapp:
foo: minion-born
bar: minion-override
bar: minion-override
zdef: strawberry
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ myapp:
float: 3.5
str: my_str
bool: true
zdef: chocolate

0 comments on commit 02ad722

Please sign in to comment.