From b59b132ff45223cd63ec2c8534ac895a8316be57 Mon Sep 17 00:00:00 2001 From: Marshall Main <55718608+marshallmain@users.noreply.github.com> Date: Fri, 29 Oct 2021 12:26:06 -0700 Subject: [PATCH] Remove validation requiring action id to be UUID (#116524) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../rules/step_rule_actions/schema.test.tsx | 41 ++----------------- .../rules/step_rule_actions/schema.tsx | 7 +--- 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.test.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.test.tsx index 0513f3754d3d..5e4300878689 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.test.tsx @@ -16,7 +16,6 @@ describe('stepRuleActions schema', () => { describe('validateSingleAction', () => { it('should validate single action', async () => { - (isUuid as jest.Mock).mockReturnValue(true); (validateActionParams as jest.Mock).mockReturnValue([]); (validateMustache as jest.Mock).mockReturnValue([]); @@ -34,7 +33,6 @@ describe('stepRuleActions schema', () => { }); it('should validate single action with invalid mustache template', async () => { - (isUuid as jest.Mock).mockReturnValue(true); (validateActionParams as jest.Mock).mockReturnValue([]); (validateMustache as jest.Mock).mockReturnValue(['Message is not valid mustache template']); @@ -54,8 +52,7 @@ describe('stepRuleActions schema', () => { expect(errors[0]).toEqual('Message is not valid mustache template'); }); - it('should validate single action with incorrect id', async () => { - (isUuid as jest.Mock).mockReturnValue(false); + it('should validate single action with non-uuid formatted id', async () => { (validateMustache as jest.Mock).mockReturnValue([]); (validateActionParams as jest.Mock).mockReturnValue([]); @@ -68,8 +65,7 @@ describe('stepRuleActions schema', () => { }, actionTypeRegistry ); - expect(errors).toHaveLength(1); - expect(errors[0]).toEqual('No connector selected'); + expect(errors).toHaveLength(0); }); }); @@ -89,36 +85,6 @@ describe('stepRuleActions schema', () => { expect(result).toEqual(undefined); }); - it('should validate incorrect rule actions field', async () => { - (getActionTypeName as jest.Mock).mockReturnValue('Slack'); - const validator = validateRuleActionsField(actionTypeRegistry); - - const result = await validator({ - path: '', - value: [ - { - id: '3', - group: 'default', - actionTypeId: '.slack', - params: {}, - }, - ], - form: {} as FormHook, - formData: jest.fn(), - errors: [], - customData: { value: null, provider: () => Promise.resolve(null) }, - }); - - expect(result).toEqual({ - code: 'ERR_FIELD_FORMAT', - message: ` -**Slack:** -* No connector selected -`, - path: '', - }); - }); - it('should validate multiple incorrect rule actions field', async () => { (isUuid as jest.Mock).mockReturnValueOnce(false); (getActionTypeName as jest.Mock).mockReturnValueOnce('Slack'); @@ -156,7 +122,8 @@ describe('stepRuleActions schema', () => { code: 'ERR_FIELD_FORMAT', message: ` **Slack:** -* No connector selected +* Summary is required +* Component is not valid mustache template **Pagerduty:** diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.tsx index 58202929c49a..955c35767368 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/schema.tsx @@ -20,17 +20,12 @@ import { ValidationError, } from '../../../../shared_imports'; import { ActionsStepRule } from '../../../pages/detection_engine/rules/types'; -import * as I18n from './translations'; -import { isUuid, getActionTypeName, validateMustache, validateActionParams } from './utils'; +import { getActionTypeName, validateMustache, validateActionParams } from './utils'; export const validateSingleAction = async ( actionItem: AlertAction, actionTypeRegistry: ActionTypeRegistryContract ): Promise => { - if (!isUuid(actionItem.id)) { - return [I18n.NO_CONNECTOR_SELECTED]; - } - const actionParamsErrors = await validateActionParams(actionItem, actionTypeRegistry); const mustacheErrors = validateMustache(actionItem.params);