Skip to content

Commit

Permalink
[Security Solution] Cover persistent rules table state by e2e tests (e…
Browse files Browse the repository at this point in the history
…lastic#149638)

**Relates to:** elastic#140263

## Summary

This PR adds Cypress e2e tests to cover persistent rules table state functionality.

## Details

It implements a test plan for the persistent rules table state functionality and includes some improvements to the other e2e tests to facilitate writing tests

- `visit()` helper function input parameters were changed to match `cy.visit()`. It allows to pass a query string via `qs` and use the other fields.
- added a skip agent installation step in `installAwsCloudFrontWithPolicy ` used in `detection_rules/related_integrations.cy.ts`. The agent installation screen started appearing after changes to the `visit()` helper function. It looks like a bug since url `app/integrations/detail/aws-1.17.0/overview?integration=cloudfront` was concatenated with `timeline=...` query string inside `visit()` and `cy.visit()` finally invoked with `app/integrations/detail/aws-1.17.0/overview?integration=cloudfront?timeline=...`. Fixing that cause test to fail due to agent installation screen.
- use default type delay for `NOTES_TEXT_AREA` in `timelines/creation.cy.ts`. It looks that zero typing delay caused test flakiness.
- selectors and helper functions were reorganized to facilitate its usage.

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios

(cherry picked from commit 513a1f0)
  • Loading branch information
maximpn committed Feb 22, 2023
1 parent aa47a95 commit 0eb4279
Show file tree
Hide file tree
Showing 36 changed files with 876 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,12 @@ export const AddFirstIntegrationSplashScreen: React.FC<{
<CreatePackagePolicyBottomBar
cancelUrl={cancelUrl}
cancelMessage={
<FormattedMessage
id="xpack.fleet.createPackagePolicyBottomBar.skipAddAgentButton"
defaultMessage="Add integration only (skip agent installation)"
/>
<span data-test-subj="skipAgentInstallation">
<FormattedMessage
id="xpack.fleet.createPackagePolicyBottomBar.skipAddAgentButton"
defaultMessage="Add integration only (skip agent installation)"
/>
</span>
}
cancelClickHandler={cancelClickHandler}
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { login, visitWithoutDateRange } from '../../tasks/login';
import { getUnmappedRule } from '../../objects/rule';

import { ALERTS_URL } from '../../urls/navigation';
import { pageSelector } from '../../screens/alerts_detection_rules';
import { tablePageSelector } from '../../screens/table_pagination';

describe('Alert details with unmapped fields', () => {
before(() => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Alert details with unmapped fields', () => {
};

openTable();
cy.get(ALERT_FLYOUT).find(pageSelector(4)).click({ force: true });
cy.get(ALERT_FLYOUT).find(tablePageSelector(4)).click({ force: true });
cy.get(ALERT_FLYOUT)
.find(TABLE_ROWS)
.last()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { TIMELINE_TEMPLATE_DETAILS } from '../../screens/rule_details';
import { EUI_FILTER_SELECT_ITEM } from '../../screens/common/controls';

import {
changeRowsPerPageTo,
waitForRulesTableToBeLoaded,
selectAllRules,
goToTheRuleDetailsOf,
Expand Down Expand Up @@ -100,6 +99,7 @@ import { getIndicatorMatchTimelineTemplate } from '../../objects/timeline';

import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { getAvailablePrebuiltRulesCount } from '../../tasks/api_calls/prebuilt_rules';
import { setRowsPerPageTo } from '../../tasks/table_pagination';

const RULE_NAME = 'Custom rule for bulk actions';

Expand Down Expand Up @@ -224,7 +224,7 @@ describe('Detection rules, bulk edit', () => {
it('should not lose rules selection after edit action', () => {
const rulesCount = 4;
// Switch to 5 rules per page, to have few pages in pagination(ideal way to test auto refresh and selection of few items)
changeRowsPerPageTo(numberOfRulesPerPage);
setRowsPerPageTo(numberOfRulesPerPage);
selectNumberOfRules(rulesCount);

// open add tags form and add 2 new tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
RISK_SCORE,
RULE_NAME,
RULES_ROW,
RULES_TABLE,
RULES_MANAGEMENT_TABLE,
RULE_SWITCH,
SEVERITY,
} from '../../screens/alerts_detection_rules';
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Custom query rules', () => {
cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

cy.log('Asserting rule view in rules list');
cy.get(RULES_TABLE).find(RULES_ROW).should('have.length', expectedNumberOfRules);
cy.get(RULES_MANAGEMENT_TABLE).find(RULES_ROW).should('have.length', expectedNumberOfRules);
cy.get(RULE_NAME).should('have.text', ruleFields.ruleName);
cy.get(RISK_SCORE).should('have.text', ruleFields.riskScore);
cy.get(SEVERITY)
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('Custom query rules', () => {
});

it('Deletes one rule', () => {
cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.find(RULES_ROW)
.then((rules) => {
const initialNumberOfRules = rules.length;
Expand All @@ -260,7 +260,7 @@ describe('Custom query rules', () => {

deleteFirstRule();

cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.find(RULES_ROW)
.should('have.length', expectedNumberOfRulesAfterDeletion);
cy.request({ url: '/api/detection_engine/rules/_find' }).then(({ body }) => {
Expand All @@ -275,7 +275,7 @@ describe('Custom query rules', () => {
});

it('Deletes more than one rule', () => {
cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.find(RULES_ROW)
.then((rules) => {
const initialNumberOfRules = rules.length;
Expand All @@ -286,21 +286,21 @@ describe('Custom query rules', () => {
selectNumberOfRules(numberOfRulesToBeDeleted);
deleteSelectedRules();

cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.get(RULES_ROW)
.first()
.within(() => {
cy.get(RULE_SWITCH).should('not.exist');
});

cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.find(RULES_ROW)
.should('have.length', expectedNumberOfRulesAfterDeletion);
cy.request({ url: '/api/detection_engine/rules/_find' }).then(({ body }) => {
const numberOfRules = body.data.length;
expect(numberOfRules).to.eql(expectedNumberOfRulesAfterDeletion);
});
cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.get(RULES_ROW)
.first()
.within(() => {
Expand All @@ -314,7 +314,7 @@ describe('Custom query rules', () => {
});

it('Deletes one rule from detail page', () => {
cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE)
.find(RULES_ROW)
.then((rules) => {
const initialNumberOfRules = rules.length;
Expand All @@ -327,8 +327,8 @@ describe('Custom query rules', () => {

// @ts-expect-error update types
cy.waitFor('@deleteRule').then(() => {
cy.get(RULES_TABLE).should('exist');
cy.get(RULES_TABLE)
cy.get(RULES_MANAGEMENT_TABLE).should('exist');
cy.get(RULES_MANAGEMENT_TABLE)
.find(RULES_ROW)
.should('have.length', expectedNumberOfRulesAfterDeletion);
cy.request({ url: '/api/detection_engine/rules/_find' }).then(({ body }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
RISK_SCORE,
RULE_NAME,
RULES_ROW,
RULES_TABLE,
RULES_MANAGEMENT_TABLE,
RULE_SWITCH,
SEVERITY,
} from '../../screens/alerts_detection_rules';
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Custom query rules', () => {

cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

cy.get(RULES_TABLE).find(RULES_ROW).should('have.length', expectedNumberOfRules);
cy.get(RULES_MANAGEMENT_TABLE).find(RULES_ROW).should('have.length', expectedNumberOfRules);
cy.get(RULE_NAME).should('have.text', this.rule.name);
cy.get(RISK_SCORE).should('have.text', this.rule.riskScore);
cy.get(SEVERITY).should('have.text', this.rule.severity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ALERT_DATA_GRID, NUMBER_OF_ALERTS } from '../../screens/alerts';
import {
CUSTOM_RULES_BTN,
RISK_SCORE,
RULES_MANAGEMENT_TABLE,
RULE_NAME,
RULE_SWITCH,
SEVERITY,
Expand Down Expand Up @@ -102,7 +103,7 @@ describe('EQL rules', () => {

cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

expectNumberOfRules(expectedNumberOfRules);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, expectedNumberOfRules);

cy.get(RULE_NAME).should('have.text', this.rule.name);
cy.get(RISK_SCORE).should('have.text', this.rule.riskScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { TOASTER } from '../../screens/alerts_detection_rules';
import { RULES_MANAGEMENT_TABLE, TOASTER } from '../../screens/alerts_detection_rules';
import {
expectNumberOfRules,
expectToContainRule,
Expand Down Expand Up @@ -41,8 +41,8 @@ describe('Import rules', () => {
'Successfully imported 1 ruleSuccessfully imported 1 exception.'
);

expectNumberOfRules(expectedNumberOfRules);
expectToContainRule(expectedImportedRuleName);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, expectedNumberOfRules);
expectToContainRule(RULES_MANAGEMENT_TABLE, expectedImportedRuleName);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import {
CUSTOM_RULES_BTN,
RISK_SCORE,
RULES_MANAGEMENT_TABLE,
RULE_NAME,
RULE_SWITCH,
SEVERITY,
Expand Down Expand Up @@ -432,7 +433,7 @@ describe('indicator match', () => {

cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

expectNumberOfRules(expectedNumberOfRules);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, expectedNumberOfRules);

cy.get(RULE_NAME).should('have.text', rule.name);
cy.get(RISK_SCORE).should('have.text', rule.riskScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { getNewRule } from '../../objects/rule';
import { RULES_MONITORING_TABLE, RULE_NAME } from '../../screens/alerts_detection_rules';
import { RULES_MONITORING_TAB, RULE_NAME } from '../../screens/alerts_detection_rules';
import { createCustomRuleEnabled } from '../../tasks/api_calls/rules';
import { cleanKibana, deleteAlertsAndRules } from '../../tasks/common';
import { login, visitWithoutDateRange } from '../../tasks/login';
Expand All @@ -29,7 +29,7 @@ describe('Rules talbes links', () => {
});

it('should render correct link for rule name - rule monitoring', () => {
cy.get(RULES_MONITORING_TABLE).first().click();
cy.get(RULES_MONITORING_TAB).click();
cy.get(RULE_NAME).first().click();
cy.url().should('contain', 'rules/id/');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getMachineLearningRule } from '../../objects/rule';
import {
CUSTOM_RULES_BTN,
RISK_SCORE,
RULES_MANAGEMENT_TABLE,
RULE_NAME,
RULE_SWITCH,
SEVERITY,
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('Detection rules, machine learning', () => {

cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

expectNumberOfRules(expectedNumberOfRules);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, expectedNumberOfRules);

cy.get(RULE_NAME).should('have.text', getMachineLearningRule().name);
cy.get(RISK_SCORE).should('have.text', getMachineLearningRule().riskScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ALERT_DATA_GRID } from '../../screens/alerts';
import {
CUSTOM_RULES_BTN,
RISK_SCORE,
RULES_MANAGEMENT_TABLE,
RULE_NAME,
RULE_SWITCH,
SEVERITY,
Expand Down Expand Up @@ -98,7 +99,7 @@ describe('New Terms rules', () => {

cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

expectNumberOfRules(expectedNumberOfRules);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, expectedNumberOfRules);

cy.get(RULE_NAME).should('have.text', this.rule.name);
cy.get(RISK_SCORE).should('have.text', this.rule.riskScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { NUMBER_OF_ALERTS, ALERT_GRID_CELL } from '../../screens/alerts';
import {
CUSTOM_RULES_BTN,
RISK_SCORE,
RULES_MANAGEMENT_TABLE,
RULE_NAME,
RULE_SWITCH,
SEVERITY,
Expand Down Expand Up @@ -97,7 +98,7 @@ describe('Detection rules, override', () => {

cy.get(CUSTOM_RULES_BTN).should('have.text', 'Custom rules (1)');

expectNumberOfRules(1);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);

cy.get(RULE_NAME).should('have.text', this.rule.name);
cy.get(RISK_SCORE).should('have.text', this.rule.riskScore);
Expand Down
Loading

0 comments on commit 0eb4279

Please sign in to comment.