Remove validation requiring action id to be UUID (#116524)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marshall Main 2021-10-29 12:26:06 -07:00 committed by GitHub
parent ee61368cff
commit b59b132ff4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 43 deletions

View file

@ -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:**

View file

@ -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<string[]> => {
if (!isUuid(actionItem.id)) {
return [I18n.NO_CONNECTOR_SELECTED];
}
const actionParamsErrors = await validateActionParams(actionItem, actionTypeRegistry);
const mustacheErrors = validateMustache(actionItem.params);