Skip to content

Commit

Permalink
Add assertions for editing a rule
Browse files Browse the repository at this point in the history
We already were asserting on the population of the Edit form after
creation; this additionally makes modifications, saves them, and asserts
the resulting values on the Rule Details page.
  • Loading branch information
rylnd committed Sep 9, 2020
1 parent 07d5f91 commit 6a87ca4
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ import {
expectScheduleStepForm,
goToScheduleStepTab,
goToActionsStepTab,
fillAboutRule,
} from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';
import { ACTIONS_THROTTLE_INPUT } from '../screens/create_new_rule';
import { saveEditedRule, expectRuleDetails } from '../tasks/edit_rule';

describe('Detection rules, custom', () => {
before(() => {
Expand Down Expand Up @@ -251,5 +253,17 @@ describe('Deletes custom rules', () => {
expectScheduleStepForm(existingRule);
goToActionsStepTab();
cy.get(ACTIONS_THROTTLE_INPUT).invoke('val').should('eql', 'no_actions');

goToAboutStepTab();

const editedRule = {
...existingRule,
severity: 'Medium',
description: 'Edited Rule description',
};

fillAboutRule(editedRule);
saveEditedRule();
expectRuleDetails(editedRule);
});
});
7 changes: 7 additions & 0 deletions x-pack/plugins/security_solution/cypress/screens/edit_rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const EDIT_SUBMIT_BUTTON = '[data-test-subj="ruleEditSubmitButton"]';
27 changes: 18 additions & 9 deletions x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ export const createAndActivateRule = () => {
cy.get(CREATE_AND_ACTIVATE_BTN).should('not.exist');
};

export const fillAboutRuleAndContinue = (
rule: CustomRule | MachineLearningRule | ThresholdRule
) => {
cy.get(RULE_NAME_INPUT).type(rule.name, { force: true });
cy.get(RULE_DESCRIPTION_INPUT).type(rule.description, { force: true });
export const fillAboutRule = (rule: CustomRule | MachineLearningRule | ThresholdRule) => {
cy.get(RULE_NAME_INPUT).clear({ force: true }).type(rule.name, { force: true });
cy.get(RULE_DESCRIPTION_INPUT).clear({ force: true }).type(rule.description, { force: true });

cy.get(SEVERITY_DROPDOWN).click({ force: true });
cy.get(`#${rule.severity.toLowerCase()}`).click();
Expand All @@ -85,12 +83,15 @@ export const fillAboutRuleAndContinue = (
cy.get(ADVANCED_SETTINGS_BTN).click({ force: true });

rule.referenceUrls.forEach((url, index) => {
cy.get(REFERENCE_URLS_INPUT).eq(index).type(url, { force: true });
cy.get(REFERENCE_URLS_INPUT).eq(index).clear({ force: true }).type(url, { force: true });
cy.get(ADD_REFERENCE_URL_BTN).click({ force: true });
});

rule.falsePositivesExamples.forEach((falsePositive, index) => {
cy.get(FALSE_POSITIVES_INPUT).eq(index).type(falsePositive, { force: true });
cy.get(FALSE_POSITIVES_INPUT)
.eq(index)
.clear({ force: true })
.type(falsePositive, { force: true });
cy.get(ADD_FALSE_POSITIVE_BTN).click({ force: true });
});

Expand All @@ -99,14 +100,22 @@ export const fillAboutRuleAndContinue = (
cy.contains(MITRE_TACTIC, mitre.tactic).click();

mitre.techniques.forEach((technique) => {
cy.get(MITRE_TECHNIQUES_INPUT).eq(index).type(`${technique}{enter}`, { force: true });
cy.get(MITRE_TECHNIQUES_INPUT)
.eq(index)
.clear({ force: true })
.type(`${technique}{enter}`, { force: true });
});

cy.get(MITRE_BTN).click({ force: true });
});

cy.get(INVESTIGATION_NOTES_TEXTAREA).type(rule.note, { force: true });
cy.get(INVESTIGATION_NOTES_TEXTAREA).clear({ force: true }).type(rule.note, { force: true });
};

export const fillAboutRuleAndContinue = (
rule: CustomRule | MachineLearningRule | ThresholdRule
) => {
fillAboutRule(rule);
cy.get(ABOUT_CONTINUE_BTN).should('exist').click({ force: true });
};

Expand Down
73 changes: 73 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/edit_rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CustomRule } from '../objects/rule';
import {
RULE_NAME_HEADER,
ABOUT_RULE_DESCRIPTION,
ABOUT_STEP,
ABOUT_SEVERITY,
ABOUT_RISK,
RULE_ABOUT_DETAILS_HEADER_TOGGLE,
INVESTIGATION_NOTES_TOGGLE,
ABOUT_INVESTIGATION_NOTES,
INVESTIGATION_NOTES_MARKDOWN,
DEFINITION_INDEX_PATTERNS,
DEFINITION_STEP,
DEFINITION_CUSTOM_QUERY,
DEFINITION_TIMELINE,
SCHEDULE_STEP,
SCHEDULE_RUNS,
SCHEDULE_LOOPBACK,
} from '../screens/rule_details';
import { EDIT_SUBMIT_BUTTON } from '../screens/edit_rule';

export const expectRuleDetails = (rule: CustomRule) => {
const expectedTags = rule.tags.join('');
const expectedIndexPatterns =
rule.index && rule.index.length
? rule.index
: [
'apm-*-transaction*',
'auditbeat-*',
'endgame-*',
'filebeat-*',
'logs-*',
'packetbeat-*',
'winlogbeat-*',
];

cy.get(RULE_NAME_HEADER).invoke('text').should('eql', `${rule.name} Beta`);

cy.get(ABOUT_RULE_DESCRIPTION).invoke('text').should('eql', rule.description);
cy.get(ABOUT_STEP).eq(ABOUT_SEVERITY).invoke('text').should('eql', rule.severity);
cy.get(ABOUT_STEP).eq(ABOUT_RISK).invoke('text').should('eql', rule.riskScore);
cy.get(ABOUT_STEP).eq(2).invoke('text').should('eql', expectedTags);

cy.get(RULE_ABOUT_DETAILS_HEADER_TOGGLE).eq(INVESTIGATION_NOTES_TOGGLE).click({ force: true });
cy.get(ABOUT_INVESTIGATION_NOTES).invoke('text').should('eql', rule.note);

cy.get(DEFINITION_INDEX_PATTERNS).then((patterns) => {
cy.wrap(patterns).each((pattern, index) => {
cy.wrap(pattern).invoke('text').should('eql', expectedIndexPatterns[index]);
});
});
cy.get(DEFINITION_STEP)
.eq(DEFINITION_CUSTOM_QUERY)
.invoke('text')
.should('eql', `${rule.customQuery} `);
cy.get(DEFINITION_STEP).eq(2).invoke('text').should('eql', 'Query');
cy.get(DEFINITION_STEP).eq(DEFINITION_TIMELINE).invoke('text').should('eql', 'None');

if (rule.interval) {
cy.get(SCHEDULE_STEP).eq(SCHEDULE_RUNS).invoke('text').should('eql', rule.interval);
}
};

export const saveEditedRule = () => {
cy.get(EDIT_SUBMIT_BUTTON).should('exist').click({ force: true });
cy.get(EDIT_SUBMIT_BUTTON).should('not.exist');
};
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ const EditRulePageComponent: FC = () => {

<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="ruleEditSubmitButton"
fill
onClick={onSubmit}
iconType="save"
Expand Down

0 comments on commit 6a87ca4

Please sign in to comment.