Skip to content

Commit

Permalink
Stronger assertions that RefreshAiSummaries does nothing if AirgapEna…
Browse files Browse the repository at this point in the history
…bled

Removed all unnecessary parameters and added assertions around the log statement to provide better evidence that having `AirgapEnabled = true` will not try to clone, pull, or otherwise update the AI summaries repo.

Discovered that we were importing github.com/tj/assert, which is a fork of github.com/stretchr/testify/assert with a few minor changes. Updating all references to use stretchr's original library for consistency. All tests passing.
  • Loading branch information
coreyogburn committed Sep 24, 2024
1 parent 903aea7 commit 9bc8efc
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 15 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/pierrec/lz4/v4 v4.1.21
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.47.0
github.com/tj/assert v0.0.3
go.uber.org/mock v0.4.0
golang.org/x/mod v0.20.0
)
Expand Down
2 changes: 1 addition & 1 deletion model/custom_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package model
import (
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestGetCustomRulesetsDefault(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion model/detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"testing"

"github.com/security-onion-solutions/securityonion-soc/util"
"github.com/tj/assert"

"github.com/stretchr/testify/assert"
)

func TestDetectionOverrideValidate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion model/rulerepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/security-onion-solutions/securityonion-soc/util"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestGetRepos(t *testing.T) {
Expand Down
18 changes: 14 additions & 4 deletions server/modules/detections/ai_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"testing"
"time"

"github.com/apex/log"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/server/modules/detections/mock"

"github.com/tj/assert"
"github.com/apex/log"
"github.com/apex/log/handlers/memory"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand All @@ -25,13 +26,22 @@ func TestRefreshAiSummaries(t *testing.T) {

iom := mock.NewMockIOManager(ctrl)
loader := mock.NewMockAiLoader(ctrl)
logger := log.WithField("test", true)

h := memory.New()
lg := &log.Logger{Handler: h, Level: log.DebugLevel}
logger := lg.WithField("test", true)

loader.EXPECT().IsAirgapped().Return(true)

err := RefreshAiSummaries(loader, model.SigLangSigma, &isRunning, "baseRepoFolder", repo, branch, logger, iom)
err := RefreshAiSummaries(loader, model.SigLanguage(""), nil, "", "", "", logger, nil)
assert.NoError(t, err)

assert.Equal(t, len(h.Entries), 1)

msg := h.Entries[0]
assert.Equal(t, msg.Message, "skipping AI summary update because airgap is enabled")
assert.Equal(t, msg.Level, log.DebugLevel)

loader.EXPECT().IsAirgapped().Return(false)
iom.EXPECT().ReadDir("baseRepoFolder").Return([]fs.DirEntry{}, nil)
iom.EXPECT().CloneRepo(gomock.Any(), "baseRepoFolder/repo1", repo, &branch).Return(nil)
Expand Down
2 changes: 1 addition & 1 deletion server/modules/detections/detengine_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/security-onion-solutions/securityonion-soc/util"

"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/tj/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand Down
2 changes: 1 addition & 1 deletion server/modules/detections/errortracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestErrorTracker(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/modules/detections/integrity_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sort"
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestDiffLists(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion server/modules/detections/io_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"testing"

"github.com/security-onion-solutions/securityonion-soc/config"
"github.com/tj/assert"

"github.com/stretchr/testify/assert"
)

func TestBuildHttpClient(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/modules/strelka/strelka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/apex/log"
"github.com/elastic/go-elasticsearch/v8/esutil"
"github.com/samber/lo"
"github.com/tj/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand Down
2 changes: 1 addition & 1 deletion server/modules/suricata/migration-2.4.70_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/security-onion-solutions/securityonion-soc/server/modules/detections/mock"
"github.com/security-onion-solutions/securityonion-soc/util"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand Down
2 changes: 1 addition & 1 deletion util/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package util
import (
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestUnquote(t *testing.T) {
Expand Down

0 comments on commit 9bc8efc

Please sign in to comment.