Skip to content

Commit

Permalink
[Detection Engine] add validation for new terms history window (elast…
Browse files Browse the repository at this point in the history
…ic#191038)

## Summary

Addresses elastic#164525
  • Loading branch information
yctercero authored Oct 4, 2024
1 parent 7264984 commit 6001786
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,35 @@ export const schema: FormSchema<DefineStepRule> = {
defaultMessage: "New terms rules only alert if terms don't appear in historical data.",
}
),
validations: [
{
validator: (
...args: Parameters<ValidationFunc>
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => {
const [{ path, formData }] = args;
const needsValidation = isNewTermsRule(formData.ruleType);

if (!needsValidation) {
return;
}

const filterTimeVal = formData.historyWindowSize.match(/\d+/g);

if (filterTimeVal <= 0) {
return {
code: 'ERR_MIN_LENGTH',
path,
message: i18n.translate(
'xpack.securitySolution.detectionEngine.validations.stepDefineRule.historyWindowSize.errMin',
{
defaultMessage: 'History window size must be greater than 0.',
}
),
};
}
},
},
],
},
groupByFields: {
type: FIELD_TYPES.COMBO_BOX,
Expand Down

0 comments on commit 6001786

Please sign in to comment.