diff --git a/server/modules/detections/ai_summary.go b/server/modules/detections/ai_summary.go index 0ab52d4e..a9e24737 100644 --- a/server/modules/detections/ai_summary.go +++ b/server/modules/detections/ai_summary.go @@ -35,6 +35,8 @@ func RefreshAiSummaries(eng AiLoader, lang model.SigLanguage, isRunning *bool, a "aiRepoUrl": aiRepoUrl, "aiRepoPath": aiRepoPath, }).Error("unable to update AI repo") + + return err } parser, err := url.Parse(aiRepoUrl) diff --git a/server/modules/detections/detengine_helpers.go b/server/modules/detections/detengine_helpers.go index a69ef2ad..17a833a5 100644 --- a/server/modules/detections/detengine_helpers.go +++ b/server/modules/detections/detengine_helpers.go @@ -195,8 +195,8 @@ func UpdateRepos(isRunning *bool, baseRepoFolder string, rulesRepos []*model.Rul err = iom.CloneRepo(ctx, repoPath, repo.Repo, repo.Branch) if err != nil { - log.WithError(err).WithField("repoPath", repoPath).Error("failed to clone repo, doing nothing with it") - continue + log.WithError(err).WithField("repoPath", repoPath).Error("failed to clone repo") + return nil, false, err } anythingNew = true diff --git a/server/modules/detections/detengine_helpers_test.go b/server/modules/detections/detengine_helpers_test.go index 30641f6d..5241a88a 100644 --- a/server/modules/detections/detengine_helpers_test.go +++ b/server/modules/detections/detengine_helpers_test.go @@ -450,3 +450,40 @@ func TestUpdateRepos(t *testing.T) { }, allRepos[1]) assert.True(t, anythingNew) } + +func TestUpdateReposFailToClone(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + branch := "branch" + + iom := mock.NewMockIOManager(ctrl) + iom.EXPECT().ReadDir("baseRepoFolder").Return([]fs.DirEntry{ + &handmock.MockDirEntry{ + Filename: "repo1", + Dir: true, + }, + &handmock.MockDirEntry{ + Filename: "repo3", + Dir: true, + }, + }, nil) + iom.EXPECT().CloneRepo(gomock.Any(), "baseRepoFolder/repo2", "http://github.com/user/repo2", &branch).Return(errors.New("unexpected error")) + + isRunning := true + + repos := []*model.RuleRepo{ + { + Repo: "http://github.com/user/repo2", + Branch: &branch, + }, + { + Repo: "http://github.com/user/repo1", + }, + } + + allRepos, anythingNew, err := UpdateRepos(&isRunning, "baseRepoFolder", repos, iom) + assert.Error(t, err) + assert.Nil(t, allRepos) + assert.False(t, anythingNew) +} diff --git a/server/modules/elastalert/elastalert_test.go b/server/modules/elastalert/elastalert_test.go index 29ca3fd6..62dceadd 100644 --- a/server/modules/elastalert/elastalert_test.go +++ b/server/modules/elastalert/elastalert_test.go @@ -1209,10 +1209,7 @@ func TestSyncChanges(t *testing.T) { IsRunning: true, }, IOManager: iom, - showAiSummaries: true, - aiRepoUrl: "aiRepoUrl", - aiRepoBranch: "aiRepoBranch", - aiRepoPath: "aiRepoPath", + showAiSummaries: false, } logger := log.WithField("detectionEngine", "test-elastalert") @@ -1220,10 +1217,6 @@ func TestSyncChanges(t *testing.T) { workItems := []esutil.BulkIndexerItem{} auditItems := []esutil.BulkIndexerItem{} - // RefreshAiSummaries - iom.EXPECT().ReadDir("aiRepoPath").Return([]fs.DirEntry{}, nil) - iom.EXPECT().CloneRepo(gomock.Any(), "aiRepoPath/aiRepoUrl", "aiRepoUrl", util.Ptr("aiRepoBranch")).Return(nil) - iom.EXPECT().ReadFile("aiRepoPath/aiRepoUrl/detections-ai/sigma_summaries.yaml").Return([]byte("{}"), nil) // checkSigmaPipelines iom.EXPECT().ReadFile("sigmaPipelineFinal").Return([]byte("data"), nil) iom.EXPECT().ReadFile("sigmaPipelineSO").Return([]byte("data"), nil) diff --git a/server/modules/strelka/strelka_test.go b/server/modules/strelka/strelka_test.go index 0300e9b6..b6996e10 100644 --- a/server/modules/strelka/strelka_test.go +++ b/server/modules/strelka/strelka_test.go @@ -1089,10 +1089,7 @@ func TestSyncChanges(t *testing.T) { IsRunning: true, }, IOManager: iom, - showAiSummaries: true, - aiRepoUrl: "aiRepoUrl", - aiRepoBranch: "aiRepoBranch", - aiRepoPath: "aiRepoPath", + showAiSummaries: false, } logger := log.WithField("detectionEngine", "test-strelka") @@ -1100,10 +1097,6 @@ func TestSyncChanges(t *testing.T) { workItems := []esutil.BulkIndexerItem{} auditItems := []esutil.BulkIndexerItem{} - // RefreshAiSummaries - iom.EXPECT().ReadDir("aiRepoPath").Return([]fs.DirEntry{}, nil) - iom.EXPECT().CloneRepo(gomock.Any(), "aiRepoPath/aiRepoUrl", "aiRepoUrl", util.Ptr("aiRepoBranch")).Return(nil) - iom.EXPECT().ReadFile("aiRepoPath/aiRepoUrl/detections-ai/yara_summaries.yaml").Return([]byte("{}"), nil) // UpdateRepos iom.EXPECT().ReadDir("repos").Return([]fs.DirEntry{ &handmock.MockDirEntry{ diff --git a/server/modules/suricata/suricata_test.go b/server/modules/suricata/suricata_test.go index aed2206f..e754ec2b 100644 --- a/server/modules/suricata/suricata_test.go +++ b/server/modules/suricata/suricata_test.go @@ -2263,10 +2263,7 @@ func TestSyncChanges(t *testing.T) { IsRunning: true, }, IOManager: iom, - showAiSummaries: true, - aiRepoUrl: "aiRepoUrl", - aiRepoBranch: "aiRepoBranch", - aiRepoPath: "aiRepoPath", + showAiSummaries: false, } logger := log.WithField("detectionEngine", "test-suricata") @@ -2274,10 +2271,6 @@ func TestSyncChanges(t *testing.T) { workItems := []esutil.BulkIndexerItem{} auditItems := []esutil.BulkIndexerItem{} - // RefreshAiSummaries - iom.EXPECT().ReadDir("aiRepoPath").Return([]fs.DirEntry{}, nil) - iom.EXPECT().CloneRepo(gomock.Any(), "aiRepoPath/aiRepoUrl", "aiRepoUrl", util.Ptr("aiRepoBranch")).Return(nil) - iom.EXPECT().ReadFile("aiRepoPath/aiRepoUrl/detections-ai/suricata_summaries.yaml").Return([]byte("{}"), nil) // readAndHash iom.EXPECT().ReadFile("communityRulesFile").Return([]byte(SimpleRule+"\n"+FlowbitsRuleA), nil) // syncCommunityDetections