Skip to content

Commit

Permalink
Merge pull request #724 from Security-Onion-Solutions/cogburn/fix-tests
Browse files Browse the repository at this point in the history
Right Number of Dialogs at the Right Times, Check Language and Engine
  • Loading branch information
coreyogburn authored Jan 17, 2025
2 parents 22976a9 + b890a63 commit 8389dae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5911,7 +5911,7 @@ <h3 class="my-2" data-aid="detection_panel_title">
</div>
</div>
<div class="quicklinks pt-2">
<v-btn id="detection-panel-ack" icon variant="text" size="small" @click="ack()" data-aid="detection_panel_ack" :title="i18n.alertAcknowledge">
<v-btn id="detection-panel-ack" icon variant="text" size="small" @click="ack(false)" data-aid="detection_panel_ack" :title="i18n.alertAcknowledge">
<v-icon :color="ackColor">
<span>
<i class="fas fa-bell fa-stack-1x"></i>
Expand Down Expand Up @@ -6287,7 +6287,7 @@ <h3>
<v-card-text v-html="i18n.acknowledgeExistingAlertsText" />
<v-card-actions>
<v-spacer></v-spacer>
<v-btn text id="ack-existing-confirm-yes-button" @click="saveDetection(); ack();" v-text="i18n.yes" data-aid="detection_panel_ack_existing_yes" />
<v-btn text id="ack-existing-confirm-yes-button" @click="saveDetection(); ack(true);" v-text="i18n.yes" data-aid="detection_panel_ack_existing_yes" />
<v-btn text id="ack-existing-confirm-no-button" @click="saveDetection();" v-text="i18n.no" data-aid="detection_panel_ack_existing_no" />
<v-btn text id="ack-existing-confirm-cancel-button" @click="detection.isEnabled = true; ackExistingDialog = false;" v-text="i18n.cancel" data-aid="detection_panel_ack_existing_cancel" />
</v-card-actions>
Expand Down
4 changes: 2 additions & 2 deletions html/js/components/detection-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ components.push({
initParams(params) {
this.showUnreviewedAiSummaries = !!params?.['showUnreviewedAiSummaries'];
},
ack() {
this.emit('ack', [this.alertInfo.item, null, false, null, this.alertInfo.groupIndex, true, true]);
ack(alreadyAcceptedDialog) {
this.emit('ack', [this.alertInfo.item, null, false, null, this.alertInfo.groupIndex, true, alreadyAcceptedDialog]);
},
escalate(e) {
this.emit('chooseCase', [e, this.alertInfo.item, this.alertInfo.groupIndex, true]);
Expand Down
13 changes: 12 additions & 1 deletion html/js/components/detection-panel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,18 @@ test('deleteOverride', async () => {
});

test('ack emits event', () => {
comp.ack();
comp.ack(false);
expect(comp.emit).toHaveBeenCalledWith('ack', [
comp.alertInfo.item,
null,
false,
null,
comp.alertInfo.groupIndex,
true,
false
]);

comp.ack(true);
expect(comp.emit).toHaveBeenCalledWith('ack', [
comp.alertInfo.item,
null,
Expand Down
3 changes: 2 additions & 1 deletion server/detectionhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,8 @@ func (h *DetectionHandler) ConvertContent(w http.ResponseWriter, r *http.Request
return
}

if det.Engine != model.EngineNameElastAlert {
if model.EngineName(strings.ToLower(string(det.Engine))) != model.EngineNameElastAlert &&
model.SigLanguage(strings.ToLower(string(det.Language))) != model.SigLangSigma {
web.Respond(w, r, http.StatusBadRequest, errors.New("that detection's engine doesn't support conversion"))
return
}
Expand Down
18 changes: 18 additions & 0 deletions server/detectionshandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,24 @@ func TestHandlerConvertContent(t *testing.T) {
handled,
},
},
{
// when creating a new detection, the engine isn't specified yet, but language is
Name: "Good Language",
ReqBody: []byte(`{"language": "sigma", "content": "sigma goes here"}`),
InitMock: func(srv *Server, ctrl *gomock.Controller) {
eng := servermock.NewMockDetectionEngine(ctrl)
srv.DetectionEngines[model.EngineNameElastAlert] = eng

eng.EXPECT().ConvertRule(gomock.Any(), &model.Detection{Content: "sigma goes here", Language: model.SigLangSigma}).Return("converted query", nil)
},
Code: 200,
Response: &ConvertContentResp{
Query: "converted query",
},
Logs: []EntryMatcher{
handled,
},
},
{
Name: "Unknown Error",
ReqBody: []byte(`{"engine": "elastalert", "content": "sigma goes here"}`),
Expand Down

0 comments on commit 8389dae

Please sign in to comment.