Skip to content

Commit

Permalink
Removes archives (#86537)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema committed Dec 28, 2020
1 parent 47ce575 commit c0d6e12
Show file tree
Hide file tree
Showing 50 changed files with 281 additions and 37,917 deletions.
11 changes: 4 additions & 7 deletions x-pack/plugins/security_solution/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ CYPRESS_BASE_URL=http(s)://<username>:<password>@<kbnUrl> CYPRESS_ELASTICSEARCH_

## Best Practices

### Clean up the state between tests
### Clean up the state

Remember to clean up the state of the test after its execution.
Remember to use the `cleanKibana` method before starting the execution of the test

### Minimize the use of es_archive

Expand All @@ -192,15 +192,12 @@ When possible, create all the data that you need for executing the tests using t
Loading the web page takes a big amount of time, in order to minimize that impact, the following points should be
taken into consideration until another solution is implemented:

- Don't refresh the page for every test to clean the state of it.
- Instead, group the tests that are similar in different contexts.
- Group the tests that are similar in different contexts.
- For every context login only once, clean the state between tests if needed without re-loading the page.
- All tests in a spec file must be order-independent.
- If you need to reload the page to make the tests order-independent, consider to create a new context.


Remember that minimizing the number of times the web page is loaded, we minimize as well the execution time.


## Reporting

When Cypress tests are run on the command line via non visual mode
Expand Down
139 changes: 67 additions & 72 deletions x-pack/plugins/security_solution/cypress/integration/alerts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { newRule } from '../objects/rule';
import {
ALERTS,
ALERTS_COUNT,
Expand All @@ -24,37 +25,35 @@ import {
waitForAlertsToBeLoaded,
markInProgressFirstAlert,
goToInProgressAlerts,
waitForAlertsIndexToBeCreated,
} from '../tasks/alerts';
import { removeSignalsIndex } from '../tasks/api_calls/rules';
import { createCustomRuleActivated } from '../tasks/api_calls/rules';
import { cleanKibana } from '../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { waitForAlertsToPopulate } from '../tasks/create_new_rule';
import { loginAndWaitForPage } from '../tasks/login';
import { refreshPage } from '../tasks/security_header';

import { DETECTIONS_URL } from '../urls/navigation';

describe('Alerts', () => {
context('Closing alerts', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('alerts');
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('alerts');
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
createCustomRuleActivated(newRule);
refreshPage();
waitForAlertsToPopulate();
});

it('Closes and opens alerts', () => {
waitForAlertsPanelToBeLoaded();
waitForAlertsToBeLoaded();

const numberOfAlertsToBeClosed = 3;
cy.get(ALERTS_COUNT)
.invoke('text')
.then((numberOfAlerts) => {
cy.get(SHOWING_ALERTS).should('have.text', `Showing ${numberOfAlerts} alerts`);

const numberOfAlertsToBeClosed = 3;
selectNumberOfAlerts(numberOfAlertsToBeClosed);

cy.get(SELECTED_ALERTS).should(
Expand All @@ -64,8 +63,6 @@ describe('Alerts', () => {

closeAlerts();
waitForAlerts();
cy.reload();
waitForAlerts();

const expectedNumberOfAlertsAfterClosing = +numberOfAlerts - numberOfAlertsToBeClosed;
cy.get(ALERTS_COUNT).should('have.text', expectedNumberOfAlertsAfterClosing.toString());
Expand All @@ -92,11 +89,6 @@ describe('Alerts', () => {

openAlerts();
waitForAlerts();
cy.reload();
waitForAlertsToBeLoaded();
waitForAlerts();
goToClosedAlerts();
waitForAlerts();

const expectedNumberOfClosedAlertsAfterOpened = 2;
cy.get(ALERTS_COUNT).should(
Expand Down Expand Up @@ -124,8 +116,6 @@ describe('Alerts', () => {
});

it('Closes one alert when more than one opened alerts are selected', () => {
waitForAlertsToBeLoaded();

cy.get(ALERTS_COUNT)
.invoke('text')
.then((numberOfAlerts) => {
Expand All @@ -137,8 +127,6 @@ describe('Alerts', () => {
cy.get(TAKE_ACTION_POPOVER_BTN).should('not.have.attr', 'disabled');

closeFirstAlert();
cy.reload();
waitForAlertsToBeLoaded();
waitForAlerts();

const expectedNumberOfAlerts = +numberOfAlerts - numberOfAlertsToBeClosed;
Expand All @@ -164,73 +152,82 @@ describe('Alerts', () => {
context('Opening alerts', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('closed_alerts');
loginAndWaitForPage(DETECTIONS_URL);
});
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
createCustomRuleActivated(newRule);
refreshPage();
waitForAlertsToPopulate();
selectNumberOfAlerts(5);

cy.get(SELECTED_ALERTS).should('have.text', `Selected 5 alerts`);

afterEach(() => {
esArchiverUnload('closed_alerts');
closeAlerts();
waitForAlerts();
refreshPage();
});

it('Open one alert when more than one closed alerts are selected', () => {
waitForAlerts();
goToClosedAlerts();
waitForAlertsToBeLoaded();
waitForAlertsToPopulate();

cy.get(ALERTS_COUNT)
.invoke('text')
.then((numberOfAlerts) => {
const numberOfAlertsToBeOpened = 1;
const numberOfAlertsToBeSelected = 3;

cy.get(TAKE_ACTION_POPOVER_BTN).should('have.attr', 'disabled');
selectNumberOfAlerts(numberOfAlertsToBeSelected);
cy.get(TAKE_ACTION_POPOVER_BTN).should('not.have.attr', 'disabled');

openFirstAlert();
cy.reload();
.then((numberOfOpenedAlertsText) => {
const numberOfOpenedAlerts = parseInt(numberOfOpenedAlertsText, 10);
goToClosedAlerts();
waitForAlertsToBeLoaded();
waitForAlerts();

const expectedNumberOfAlerts = +numberOfAlerts - numberOfAlertsToBeOpened;
cy.get(ALERTS_COUNT).should('have.text', expectedNumberOfAlerts.toString());
cy.get(SHOWING_ALERTS).should(
'have.text',
`Showing ${expectedNumberOfAlerts.toString()} alerts`
);

goToOpenedAlerts();
waitForAlerts();

cy.get(ALERTS_COUNT).should('have.text', numberOfAlertsToBeOpened.toString());
cy.get(SHOWING_ALERTS).should(
'have.text',
`Showing ${numberOfAlertsToBeOpened.toString()} alert`
);
cy.get(ALERTS).should('have.length', numberOfAlertsToBeOpened);
cy.get(ALERTS_COUNT)
.invoke('text')
.then((numberOfAlerts) => {
const numberOfAlertsToBeOpened = 1;
const numberOfAlertsToBeSelected = 3;

cy.get(TAKE_ACTION_POPOVER_BTN).should('have.attr', 'disabled');
selectNumberOfAlerts(numberOfAlertsToBeSelected);
cy.get(SELECTED_ALERTS).should(
'have.text',
`Selected ${numberOfAlertsToBeSelected} alerts`
);

cy.get(TAKE_ACTION_POPOVER_BTN).should('not.have.attr', 'disabled');

openFirstAlert();
waitForAlerts();

const expectedNumberOfAlerts = +numberOfAlerts - numberOfAlertsToBeOpened;
cy.get(ALERTS_COUNT).should('have.text', expectedNumberOfAlerts.toString());
cy.get(SHOWING_ALERTS).should(
'have.text',
`Showing ${expectedNumberOfAlerts.toString()} alerts`
);

goToOpenedAlerts();
waitForAlerts();

cy.get(ALERTS_COUNT).should(
'have.text',
(numberOfOpenedAlerts + numberOfAlertsToBeOpened).toString()
);
cy.get(SHOWING_ALERTS).should(
'have.text',
`Showing ${(numberOfOpenedAlerts + numberOfAlertsToBeOpened).toString()} alerts`
);
});
});
});
});

context('Marking alerts as in-progress', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('alerts');
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('alerts');
removeSignalsIndex();
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
createCustomRuleActivated(newRule);
refreshPage();
waitForAlertsToPopulate();
});

it('Mark one alert in progress when more than one open alerts are selected', () => {
waitForAlerts();
waitForAlertsToBeLoaded();

cy.get(ALERTS_COUNT)
.invoke('text')
.then((numberOfAlerts) => {
Expand All @@ -242,8 +239,6 @@ describe('Alerts', () => {
cy.get(TAKE_ACTION_POPOVER_BTN).should('not.have.attr', 'disabled');

markInProgressFirstAlert();
cy.reload();
goToOpenedAlerts();
waitForAlertsToBeLoaded();

const expectedNumberOfAlerts = +numberOfAlerts - numberOfAlertsToBeMarkedInProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../tasks/login';
import { waitForAlertsIndexToBeCreated } from '../tasks/alerts';
import { goToRuleDetails } from '../tasks/alerts_detection_rules';
import { createCustomRule, deleteCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { createCustomRule, deleteCustomRule } from '../tasks/api_calls/rules';
import { getCallOut, waitForCallOutToBeShown, dismissCallOut } from '../tasks/common/callouts';
import { cleanKibana } from '../tasks/common';

Expand All @@ -42,7 +42,6 @@ describe('Detections > Callouts indicating read-only access to resources', () =>
// First, we have to open the app on behalf of a priviledged user in order to initialize it.
// Otherwise the app will be disabled and show a "welcome"-like page.
cleanKibana();
removeSignalsIndex();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL, ROLES.platform_engineer);
waitForAlertsIndexToBeCreated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
goToOpenedAlerts,
waitForAlertsIndexToBeCreated,
} from '../tasks/alerts';
import { createCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { createCustomRule } from '../tasks/api_calls/rules';
import { goToRuleDetails } from '../tasks/alerts_detection_rules';
import { waitForAlertsToPopulate } from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
Expand All @@ -35,11 +35,10 @@ import { refreshPage } from '../tasks/security_header';
import { DETECTIONS_URL } from '../urls/navigation';
import { cleanKibana } from '../tasks/common';

describe.skip('Exceptions', () => {
describe('Exceptions', () => {
const NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS = '1';
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsIndexToBeCreated();
createCustomRule(newRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
import {
FIFTH_RULE,
FIRST_RULE,
RULE_NAME,
RULE_SWITCH,
SECOND_RULE,
SEVENTH_RULE,
RULE_AUTO_REFRESH_IDLE_MODAL,
FOURTH_RULE,
} from '../screens/alerts_detection_rules';

import {
Expand All @@ -28,43 +27,45 @@ import {
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForRuleToBeActivated,
} from '../tasks/alerts_detection_rules';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
import { DEFAULT_RULE_REFRESH_INTERVAL_VALUE } from '../../common/constants';

import { DETECTIONS_URL } from '../urls/navigation';
import { removeSignalsIndex } from '../tasks/api_calls/rules';
import { createCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { cleanKibana } from '../tasks/common';
import { existingRule, newOverrideRule, newRule, newThresholdRule } from '../objects/rule';

describe('Alerts detection rules', () => {
before(() => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('prebuilt_rules_loaded');
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
createCustomRule(newRule, 'rule1');
createCustomRule(existingRule, 'rule2');
createCustomRule(newOverrideRule, 'rule3');
createCustomRule(newThresholdRule, 'rule4');
});

after(() => {
esArchiverUnload('prebuilt_rules_loaded');
cy.clock().invoke('restore');
});

it('Sorts by activated rules', () => {
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
goToManageAlertsDetectionRules();
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded();

cy.get(RULE_NAME)
.eq(FIFTH_RULE)
.eq(SECOND_RULE)
.invoke('text')
.then((fifthRuleName) => {
activateRule(FIFTH_RULE);
.then((secondInitialRuleName) => {
activateRule(SECOND_RULE);
waitForRuleToBeActivated();
cy.get(RULE_NAME)
.eq(SEVENTH_RULE)
.eq(FOURTH_RULE)
.invoke('text')
.then((seventhRuleName) => {
activateRule(SEVENTH_RULE);
.then((fourthInitialRuleName) => {
activateRule(FOURTH_RULE);
waitForRuleToBeActivated();
sortByActivatedRules();
cy.get(RULE_NAME)
Expand All @@ -76,8 +77,8 @@ describe('Alerts detection rules', () => {
.invoke('text')
.then((secondRuleName) => {
const expectedRulesNames = `${firstRuleName} ${secondRuleName}`;
cy.wrap(expectedRulesNames).should('include', fifthRuleName);
cy.wrap(expectedRulesNames).should('include', seventhRuleName);
cy.wrap(expectedRulesNames).should('include', secondInitialRuleName);
cy.wrap(expectedRulesNames).should('include', fourthInitialRuleName);
});
});
cy.get(RULE_SWITCH).eq(FIRST_RULE).should('have.attr', 'role', 'switch');
Expand Down
Loading

0 comments on commit c0d6e12

Please sign in to comment.