[8.6] [Security Solution] [Rules] Fixes bug where editing a rule with a data view throws an unhandled exception (#145658) (#146153)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Security Solution] [Rules] Fixes bug where editing a rule with a
data view throws an unhandled exception
(#145658)](https://github.com/elastic/kibana/pull/145658)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Devin W.
Hurley","email":"devin.hurley@elastic.co"},"sourceCommit":{"committedDate":"2022-11-23T14:11:05Z","message":"[Security
Solution] [Rules] Fixes bug where editing a rule with a data view throws
an unhandled exception (#145658)\n\n## Summary\r\n\r\nRef:
https://github.com/elastic/kibana/issues/145078","sha":"584752f36693d2e9af56605f2e914285a1d4d62d","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","release_note:skip","Team:Security
Solution Platform","Feature:Rule
Details","backport:prev-minor","v8.6.0","v8.7.0"],"number":145658,"url":"https://github.com/elastic/kibana/pull/145658","mergeCommit":{"message":"[Security
Solution] [Rules] Fixes bug where editing a rule with a data view throws
an unhandled exception (#145658)\n\n## Summary\r\n\r\nRef:
https://github.com/elastic/kibana/issues/145078","sha":"584752f36693d2e9af56605f2e914285a1d4d62d"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145658","number":145658,"mergeCommit":{"message":"[Security
Solution] [Rules] Fixes bug where editing a rule with a data view throws
an unhandled exception (#145658)\n\n## Summary\r\n\r\nRef:
https://github.com/elastic/kibana/issues/145078","sha":"584752f36693d2e9af56605f2e914285a1d4d62d"}}]}]
BACKPORT-->

Co-authored-by: Devin W. Hurley <devin.hurley@elastic.co>
This commit is contained in:
Kibana Machine 2022-11-23 10:44:50 -05:00 committed by GitHub
parent d458b8f214
commit 7361470460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 1 deletions

View file

@ -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');
});
});
});

View file

@ -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"]';

View file

@ -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
) => {

View file

@ -11,6 +11,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiFormRow,
EuiLoadingSpinner,
EuiSpacer,
EuiButtonGroup,
EuiText,
@ -502,7 +503,9 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
);
const DataViewSelectorMemo = useMemo(() => {
return (
return kibanaDataViews == null || Object.keys(kibanaDataViews).length === 0 ? (
<EuiLoadingSpinner size="l" />
) : (
<UseField
key="DataViewSelector"
path="dataViewId"

View file

@ -292,6 +292,7 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
isDisabled={isLoading}
isLoading={isLoading}
onClick={() => handleSubmit(false)}
data-test-subj="create-enabled-false"
>
{I18n.COMPLETE_WITHOUT_ENABLING}
</EuiButton>