From 584752f36693d2e9af56605f2e914285a1d4d62d Mon Sep 17 00:00:00 2001 From: "Devin W. Hurley" Date: Wed, 23 Nov 2022 09:11:05 -0500 Subject: [PATCH] [Security Solution] [Rules] Fixes bug where editing a rule with a data view throws an unhandled exception (#145658) ## Summary Ref: https://github.com/elastic/kibana/issues/145078 --- .../custom_query_rule_data_view.cy.ts | 26 +++++++++++++++++++ .../cypress/screens/create_new_rule.ts | 2 ++ .../cypress/tasks/create_new_rule.ts | 8 ++++++ .../rules/step_define_rule/index.tsx | 5 +++- .../rules/step_rule_actions/index.tsx | 1 + 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/cypress/e2e/detection_rules/custom_query_rule_data_view.cy.ts b/x-pack/plugins/security_solution/cypress/e2e/detection_rules/custom_query_rule_data_view.cy.ts index 727c7257b6682f..04e08d5de572a9 100644 --- a/x-pack/plugins/security_solution/cypress/e2e/detection_rules/custom_query_rule_data_view.cy.ts +++ b/x-pack/plugins/security_solution/cypress/e2e/detection_rules/custom_query_rule_data_view.cy.ts @@ -20,6 +20,11 @@ import { RULE_SWITCH, SEVERITY, } from '../../screens/alerts_detection_rules'; +import { + ABOUT_CONTINUE_BTN, + RULE_DESCRIPTION_INPUT, + RULE_NAME_INPUT, +} from '../../screens/create_new_rule'; import { ADDITIONAL_LOOK_BACK_DETAILS, @@ -44,6 +49,7 @@ import { TAGS_DETAILS, TIMELINE_TEMPLATE_DETAILS, DATA_VIEW_DETAILS, + EDIT_RULE_SETTINGS_LINK, } from '../../screens/rule_details'; import { goToRuleDetails } from '../../tasks/alerts_detection_rules'; @@ -51,6 +57,7 @@ import { createTimeline } from '../../tasks/api_calls/timelines'; import { postDataView } from '../../tasks/common'; import { createAndEnableRule, + createRuleWithoutEnabling, fillAboutRuleAndContinue, fillDefineCustomRuleAndContinue, fillScheduleRuleAndContinue, @@ -158,5 +165,24 @@ describe('Custom query rules', () => { .should('match', /^[1-9].+$/); cy.get(ALERT_GRID_CELL).contains(this.rule.name); }); + it('Creates and edits a new rule with a data view', function () { + visit(RULE_CREATION); + fillDefineCustomRuleAndContinue(this.rule); + cy.get(RULE_NAME_INPUT).clear({ force: true }).type(this.rule.name, { force: true }); + cy.get(RULE_DESCRIPTION_INPUT) + .clear({ force: true }) + .type(this.rule.description, { force: true }); + + cy.get(ABOUT_CONTINUE_BTN).should('exist').click({ force: true }); + + fillScheduleRuleAndContinue(this.rule); + createRuleWithoutEnabling(); + + goToRuleDetails(); + + cy.get(EDIT_RULE_SETTINGS_LINK).click({ force: true }); + + cy.get(RULE_NAME_HEADER).should('contain', 'Edit rule settings'); + }); }); }); diff --git a/x-pack/plugins/security_solution/cypress/screens/create_new_rule.ts b/x-pack/plugins/security_solution/cypress/screens/create_new_rule.ts index c57e2c603e4618..1d59f2ce83ce11 100644 --- a/x-pack/plugins/security_solution/cypress/screens/create_new_rule.ts +++ b/x-pack/plugins/security_solution/cypress/screens/create_new_rule.ts @@ -32,6 +32,8 @@ export const COMBO_BOX_CLEAR_BTN = '[data-test-subj="comboBoxClearButton"]'; export const CREATE_AND_ENABLE_BTN = '[data-test-subj="create-enable"]'; +export const CREATE_WITHOUT_ENABLING_BTN = '[data-test-subj="create-enabled-false"]'; + export const CUSTOM_QUERY_INPUT = '[data-test-subj="queryInput"]'; export const CUSTOM_QUERY_BAR = '[data-test-subj="detectionEngineStepDefineRuleQueryBar"]'; diff --git a/x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts b/x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts index fc1f3b389bdf5c..fe3809f1d3cc75 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts @@ -104,6 +104,7 @@ import { NEW_TERMS_INPUT_AREA, ACTIONS_THROTTLE_INPUT, CONTINUE_BUTTON, + CREATE_WITHOUT_ENABLING_BTN, } from '../screens/create_new_rule'; import { INDEX_SELECTOR, @@ -125,6 +126,13 @@ export const createAndEnableRule = () => { cy.get(BACK_TO_ALL_RULES_LINK).should('not.exist'); }; +export const createRuleWithoutEnabling = () => { + cy.get(CREATE_WITHOUT_ENABLING_BTN).click({ force: true }); + cy.get(CREATE_WITHOUT_ENABLING_BTN).should('not.exist'); + cy.get(BACK_TO_ALL_RULES_LINK).click({ force: true }); + cy.get(BACK_TO_ALL_RULES_LINK).should('not.exist'); +}; + export const fillAboutRule = ( rule: CustomRule | MachineLearningRule | ThresholdRule | ThreatIndicatorRule ) => { diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_define_rule/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_define_rule/index.tsx index 82018631712278..e8fec6d0e9186a 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_define_rule/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_define_rule/index.tsx @@ -11,6 +11,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiFormRow, + EuiLoadingSpinner, EuiSpacer, EuiButtonGroup, EuiText, @@ -502,7 +503,9 @@ const StepDefineRuleComponent: FC = ({ ); const DataViewSelectorMemo = useMemo(() => { - return ( + return kibanaDataViews == null || Object.keys(kibanaDataViews).length === 0 ? ( + + ) : ( = ({ isDisabled={isLoading} isLoading={isLoading} onClick={() => handleSubmit(false)} + data-test-subj="create-enabled-false" > {I18n.COMPLETE_WITHOUT_ENABLING}