Skip to content

Commit

Permalink
[Detections] Add validation for Threshold value field (#72611) (#72777)
Browse files Browse the repository at this point in the history
Co-authored-by: Patryk Kopyciński <patryk.kopycinski@elastic.co>
  • Loading branch information
spong and patrykkopycinski authored Jul 22, 2020
1 parent 29c5de6 commit ba36180
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ export const schema: FormSchema = {
defaultMessage: 'Threshold',
}
),
validations: [
{
validator: fieldValidators.numberGreaterThanField({
than: 1,
message: i18n.translate(
'xpack.securitySolution.detectionEngine.validations.thresholdValueFieldData.numberGreaterThanOrEqualOneErrorMessage',
{
defaultMessage: 'Value must be greater than or equal one.',
}
),
allowEquality: true,
}),
},
],
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,39 @@ describe('getThresholdSignalQueryFields', () => {
'event.dataset': 'traefik.access',
});
});

it('should return proper object for exists filters', () => {
const filters = {
bool: {
should: [
{
bool: {
should: [
{
exists: {
field: 'process.name',
},
},
],
minimum_should_match: 1,
},
},
{
bool: {
should: [
{
exists: {
field: 'event.type',
},
},
],
minimum_should_match: 1,
},
},
],
minimum_should_match: 1,
},
};
expect(getThresholdSignalQueryFields(filters)).toEqual({});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const getThresholdSignalQueryFields = (filter: unknown) => {
return { ...acc, ...item.match_phrase };
}

if (item.bool.should && (item.bool.should[0].match || item.bool.should[0].match_phrase)) {
if (item.bool?.should && (item.bool.should[0].match || item.bool.should[0].match_phrase)) {
return { ...acc, ...(item.bool.should[0].match || item.bool.should[0].match_phrase) };
}

Expand Down

0 comments on commit ba36180

Please sign in to comment.