Skip to content

Commit 1ba3dbc

Browse files
[Detections] Add validation for Threshold value field (#72611) (#72776)
Co-authored-by: Patryk Kopyciński <[email protected]>
1 parent 996f0ad commit 1ba3dbc

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

x-pack/plugins/security_solution/public/detections/components/rules/step_define_rule/schema.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ export const schema: FormSchema = {
202202
defaultMessage: 'Threshold',
203203
}
204204
),
205+
validations: [
206+
{
207+
validator: fieldValidators.numberGreaterThanField({
208+
than: 1,
209+
message: i18n.translate(
210+
'xpack.securitySolution.detectionEngine.validations.thresholdValueFieldData.numberGreaterThanOrEqualOneErrorMessage',
211+
{
212+
defaultMessage: 'Value must be greater than or equal one.',
213+
}
214+
),
215+
allowEquality: true,
216+
}),
217+
},
218+
],
205219
},
206220
},
207221
};

x-pack/plugins/security_solution/server/lib/detection_engine/signals/bulk_create_threshold_signals.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,39 @@ describe('getThresholdSignalQueryFields', () => {
193193
'event.dataset': 'traefik.access',
194194
});
195195
});
196+
197+
it('should return proper object for exists filters', () => {
198+
const filters = {
199+
bool: {
200+
should: [
201+
{
202+
bool: {
203+
should: [
204+
{
205+
exists: {
206+
field: 'process.name',
207+
},
208+
},
209+
],
210+
minimum_should_match: 1,
211+
},
212+
},
213+
{
214+
bool: {
215+
should: [
216+
{
217+
exists: {
218+
field: 'event.type',
219+
},
220+
},
221+
],
222+
minimum_should_match: 1,
223+
},
224+
},
225+
],
226+
minimum_should_match: 1,
227+
},
228+
};
229+
expect(getThresholdSignalQueryFields(filters)).toEqual({});
230+
});
196231
});

x-pack/plugins/security_solution/server/lib/detection_engine/signals/bulk_create_threshold_signals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const getThresholdSignalQueryFields = (filter: unknown) => {
8383
return { ...acc, ...item.match_phrase };
8484
}
8585

86-
if (item.bool.should && (item.bool.should[0].match || item.bool.should[0].match_phrase)) {
86+
if (item.bool?.should && (item.bool.should[0].match || item.bool.should[0].match_phrase)) {
8787
return { ...acc, ...(item.bool.should[0].match || item.bool.should[0].match_phrase) };
8888
}
8989

0 commit comments

Comments
 (0)