[Security Solution][Detection Rules] Fixes Threshold rule schema validator (#87946)

This commit is contained in:
Davis Plumlee 2021-01-12 08:57:06 -07:00 committed by GitHub
parent 752a2bd943
commit 25bac19321
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,7 @@ import {
singleEntryThreat,
containsInvalidItems,
} from '../../../../common/components/threat_match/helpers';
import { isThreatMatchRule } from '../../../../../common/detection_engine/utils';
import { isThreatMatchRule, isThresholdRule } from '../../../../../common/detection_engine/utils';
import { isMlRule } from '../../../../../common/machine_learning/helpers';
import { esKuery } from '../../../../../../../../src/plugins/data/public';
import { FieldValueQueryBar } from '../query_bar';
@ -216,16 +216,25 @@ export const schema: FormSchema<DefineStepRule> = {
),
validations: [
{
validator: fieldValidators.numberGreaterThanField({
than: 1,
message: i18n.translate(
'xpack.securitySolution.detectionEngine.validations.thresholdValueFieldData.numberGreaterThanOrEqualOneErrorMessage',
{
defaultMessage: 'Value must be greater than or equal to one.',
}
),
allowEquality: true,
}),
validator: (
...args: Parameters<ValidationFunc>
): ReturnType<ValidationFunc<{}, ERROR_CODE>> | undefined => {
const [{ formData }] = args;
const needsValidation = isThresholdRule(formData.ruleType);
if (!needsValidation) {
return;
}
return fieldValidators.numberGreaterThanField({
than: 1,
message: i18n.translate(
'xpack.securitySolution.detectionEngine.validations.thresholdValueFieldData.numberGreaterThanOrEqualOneErrorMessage',
{
defaultMessage: 'Value must be greater than or equal to one.',
}
),
allowEquality: true,
})(...args);
},
},
],
},