[security_solution] Refactor Cypress es_archiver task (#162228)

## Summary

Use `EsArchiver` directly as Cypress task, instead of spawning
additional node process
This commit is contained in:
Patryk Kopyciński 2023-07-20 13:04:54 +02:00 committed by GitHub
parent c892067f75
commit ebcc894e8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
67 changed files with 304 additions and 399 deletions

View file

@ -402,11 +402,7 @@ Note that the command will create the folder if it does not exist.
### Using an archive from within the Cypress tests
Task [cypress/tasks/es_archiver.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/cypress/tasks/es_archiver.ts) provides helpers such as `esArchiverLoad` and `esArchiverUnload` by means of `es_archiver`'s CLI.
Because of `cy.exec`, used to invoke `es_archiver`, it's necessary to override its environment with `NODE_TLS_REJECT_UNAUTHORIZED=1`. It indeed would inject `NODE_TLS_REJECT_UNAUTHORIZED=0` and make `es_archive` otherwise abort with the following warning if used over https:
> Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Task [cypress/support/es_archiver.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/cypress/support/es_archiver.ts) provides helpers such as `esArchiverLoad` and `esArchiverUnload` by means of `es_archiver`'s CLI.
### CCS
@ -419,10 +415,10 @@ Incorrect handling of the above points might result in false positives, in that
#### Remote data loading
Helpers `esArchiverCCSLoad` and `esArchiverCCSUnload` are provided by [cypress/tasks/es_archiver.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/cypress/tasks/es_archiver.ts):
Helpers `esArchiverCCSLoad` and `esArchiverCCSUnload` are provided by [cypress/support/es_archiver.ts](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/cypress/support/es_archiver.ts):
```javascript
import { esArchiverCCSLoad, esArchiverCCSUnload } from '../../tasks/es_archiver';
cy.task('esArchiverCCSLoad', '<archive_name>');
```
They will use the `CYPRESS_CCS_*_URL` environment variables for accessing the remote cluster. Complex tests involving local and remote data can interleave them with `esArchiverLoad` and `esArchiverUnload` as needed.

View file

@ -11,7 +11,6 @@ import { expandFirstAlert, waitForAlerts } from '../../tasks/alerts';
import { openJsonView } from '../../tasks/alerts_details';
import { createRule } from '../../tasks/api_calls/rules';
import { cleanKibana } from '../../tasks/common';
import { esArchiverCCSLoad } from '../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { getUnmappedCCSRule } from '../../objects/rule';
@ -22,7 +21,7 @@ describe('Alert details with unmapped fields', () => {
beforeEach(() => {
login();
cleanKibana();
esArchiverCCSLoad('unmapped_fields');
cy.task('esArchiverCCSLoad', 'unmapped_fields');
createRule(getUnmappedCCSRule());
visitWithoutDateRange(ALERTS_URL);
waitForAlerts();

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { esArchiverCCSLoad } from '../../tasks/es_archiver';
import { getCCSEqlRule } from '../../objects/rule';
import { ALERTS_COUNT, ALERT_DATA_GRID } from '../../screens/alerts';
@ -30,7 +29,7 @@ describe('Detection rules', function () {
});
it('EQL rule on remote indices generates alerts', function () {
esArchiverCCSLoad('linux_process');
cy.task('esArchiverCCSLoad', 'linux_process');
const rule = getCCSEqlRule();
login();
createRule(rule);

View file

@ -6,6 +6,7 @@
*/
import { defineCypressConfig } from '@kbn/cypress-config';
import { esArchiver } from './support/es_archiver';
export default defineCypressConfig({
defaultCommandTimeout: 60000,
@ -22,5 +23,8 @@ export default defineCypressConfig({
e2e: {
experimentalRunAllSpecs: true,
experimentalMemoryManagement: true,
setupNodeEvents(on, config) {
esArchiver(on, config);
},
},
});

View file

@ -6,6 +6,7 @@
*/
import { defineCypressConfig } from '@kbn/cypress-config';
import { esArchiver } from './support/es_archiver';
// eslint-disable-next-line import/no-default-export
export default defineCypressConfig({
@ -26,5 +27,8 @@ export default defineCypressConfig({
baseUrl: 'http://localhost:5601',
experimentalMemoryManagement: true,
specPattern: './cypress/e2e/**/*.cy.ts',
setupNodeEvents(on, config) {
esArchiver(on, config);
},
},
});

View file

@ -35,7 +35,6 @@ import { SOURCERER } from '../../screens/sourcerer';
import { createTimeline } from '../../tasks/api_calls/timelines';
import { getTimeline, getTimelineModifiedSourcerer } from '../../objects/timeline';
import { closeTimeline, openTimelineById } from '../../tasks/timeline';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
const usersToCreate = [secReadCasesAllUser];
const rolesToCreate = [secReadCasesAll];
@ -44,7 +43,7 @@ const dataViews = ['auditbeat-*,fakebeat-*', 'auditbeat-*,*beat*,siem-read*,.kib
describe('Sourcerer', () => {
before(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
dataViews.forEach((dataView: string) => postDataView(dataView));
});
describe('permissions', () => {

View file

@ -23,25 +23,24 @@ import {
SELECTED_ALERT_TAG,
UNSELECTED_ALERT_TAG,
} from '../../screens/alerts';
import { esArchiverLoad, esArchiverResetKibana, esArchiverUnload } from '../../tasks/es_archiver';
describe('Alert tagging', () => {
before(() => {
cleanKibana();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
});
beforeEach(() => {
login();
deleteAlertsAndRules();
esArchiverLoad('endpoint');
cy.task('esArchiverLoad', 'endpoint');
createRule(getNewRule({ rule_id: 'new custom rule' }));
visit(ALERTS_URL);
waitForAlertsToPopulate();
});
afterEach(() => {
esArchiverUnload('endpoint');
cy.task('esArchiverUnload', 'endpoint');
});
it('Add and remove a tag using the alert bulk action menu', () => {

View file

@ -7,7 +7,6 @@
import { getNewThreatIndicatorRule, indicatorRuleMatchingDoc } from '../../objects/rule';
import { cleanKibana } from '../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../tasks/login';
import {
JSON_TEXT,
@ -31,15 +30,15 @@ import { addsFieldsToTimeline } from '../../tasks/rule_details';
describe('CTI Enrichment', () => {
before(() => {
cleanKibana();
esArchiverLoad('threat_indicator');
esArchiverLoad('suspicious_source_event');
cy.task('esArchiverLoad', 'threat_indicator');
cy.task('esArchiverLoad', 'suspicious_source_event');
login();
createRule({ ...getNewThreatIndicatorRule(), rule_id: 'rule_testing', enabled: true });
});
after(() => {
esArchiverUnload('threat_indicator');
esArchiverUnload('suspicious_source_event');
cy.task('esArchiverUnload', 'threat_indicator');
cy.task('esArchiverUnload', 'suspicious_source_event');
});
beforeEach(() => {
@ -153,7 +152,7 @@ describe('CTI Enrichment', () => {
describe('with additional indicators', () => {
before(() => {
esArchiverLoad('threat_indicator2');
cy.task('esArchiverLoad', 'threat_indicator2');
});
beforeEach(() => {
@ -163,7 +162,7 @@ describe('CTI Enrichment', () => {
});
after(() => {
esArchiverUnload('threat_indicator2');
cy.task('esArchiverUnload', 'threat_indicator2');
});
it('Displays matched fields from both indicator match rules and investigation time enrichments on Threat Intel tab', () => {

View file

@ -15,7 +15,6 @@ import {
ALERTS_COUNT,
} from '../../screens/alerts';
import { ENRICHED_DATA_ROW } from '../../screens/alerts_details';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { createRule } from '../../tasks/api_calls/rules';
import { cleanKibana, deleteAlertsAndRules } from '../../tasks/common';
@ -33,16 +32,16 @@ import { ALERTS_URL } from '../../urls/navigation';
describe('Enrichment', () => {
before(() => {
cleanKibana();
esArchiverLoad('risk_users');
cy.task('esArchiverLoad', 'risk_users');
});
after(() => {
esArchiverUnload('risk_users');
cy.task('esArchiverUnload', 'risk_users');
});
describe('Custom query rule', () => {
beforeEach(() => {
esArchiverLoad('risk_hosts');
cy.task('esArchiverLoad', 'risk_hosts');
deleteAlertsAndRules();
createRule(getNewRule({ rule_id: 'rule1' }));
login();
@ -51,8 +50,8 @@ describe('Enrichment', () => {
});
afterEach(() => {
esArchiverUnload('risk_hosts');
esArchiverUnload('risk_hosts_updated');
cy.task('esArchiverUnload', 'risk_hosts');
cy.task('esArchiverUnload', 'risk_hosts_updated');
});
it('Should has enrichment fields', function () {
@ -73,8 +72,8 @@ describe('Enrichment', () => {
cy.get(ENRICHED_DATA_ROW).contains('Original host risk classification').should('not.exist');
closeAlertFlyout();
esArchiverUnload('risk_hosts');
esArchiverLoad('risk_hosts_updated');
cy.task('esArchiverUnload', 'risk_hosts');
cy.task('esArchiverLoad', 'risk_hosts_updated');
expandFirstAlert();
cy.get(ENRICHED_DATA_ROW).contains('Critical');
cy.get(ENRICHED_DATA_ROW).contains('Original host risk classification');

View file

@ -10,14 +10,13 @@ import { login, visit } from '../../tasks/login';
import { ALERTS_URL, TIMELINES_URL } from '../../urls/navigation';
import { ALERTS_HISTOGRAM_SERIES, ALERT_RULE_NAME, MESSAGE } from '../../screens/alerts';
import { esArchiverLoad } from '../../tasks/es_archiver';
import { TIMELINE_QUERY, TIMELINE_VIEW_IN_ANALYZER } from '../../screens/timeline';
import { selectAlertsHistogram } from '../../tasks/alerts';
import { createTimeline } from '../../tasks/timelines';
describe('Ransomware Detection Alerts', () => {
before(() => {
esArchiverLoad('ransomware_detection');
cy.task('esArchiverLoad', 'ransomware_detection');
});
describe('Ransomware display in Alerts Section', () => {

View file

@ -10,18 +10,17 @@ import { login, visit } from '../../tasks/login';
import { ALERTS_URL, TIMELINES_URL } from '../../urls/navigation';
import { ALERTS_HISTOGRAM_SERIES, ALERT_RULE_NAME, MESSAGE } from '../../screens/alerts';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { TIMELINE_QUERY, TIMELINE_VIEW_IN_ANALYZER } from '../../screens/timeline';
import { selectAlertsHistogram } from '../../tasks/alerts';
import { createTimeline } from '../../tasks/timelines';
describe('Ransomware Prevention Alerts', () => {
before(() => {
esArchiverLoad('ransomware_prevention');
cy.task('esArchiverLoad', 'ransomware_prevention');
});
after(() => {
esArchiverUnload('ransomware_prevention');
cy.task('esArchiverUnload', 'ransomware_prevention');
});
describe('Ransomware display in Alerts Section', () => {

View file

@ -24,8 +24,6 @@ import { cleanKibana, resetRulesTableState, deleteAlertsAndRules } from '../../t
import { getNewRule } from '../../objects/rule';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { createRuleExceptionItem } from '../../tasks/api_calls/exceptions';
import { EXCEPTION_CARD_ITEM_NAME } from '../../screens/exceptions';
import {
@ -60,7 +58,7 @@ describe('Detection rules, bulk duplicate', () => {
// Make sure persisted rules table state is cleared
resetRulesTableState();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
createRule(getNewRule({ name: RULE_NAME, ...defaultRuleData, rule_id: '1' })).then(
(response) => {
createRuleExceptionItem(response.body.id, [

View file

@ -88,7 +88,6 @@ import {
getNewTermsRule,
} from '../../objects/rule';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import {
getAvailablePrebuiltRulesCount,
excessivelyInstallAllPrebuiltRules,
@ -127,7 +126,7 @@ describe('Detection rules, bulk edit', () => {
// Make sure persisted rules table state is cleared
resetRulesTableState();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
createRule(getNewRule({ name: RULE_NAME, ...defaultRuleData, rule_id: '1' }));
createRule(getEqlRule({ ...defaultRuleData, rule_id: '2' }));
createRule(getMachineLearningRule({ tags: ['test-default-tag-1', 'test-default-tag-2'] }));

View file

@ -42,7 +42,6 @@ import {
openBulkActionsMenu,
} from '../../tasks/rules_bulk_edit';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { SECURITY_DETECTIONS_RULES_URL } from '../../urls/navigation';
@ -78,7 +77,7 @@ describe.skip('Detection rules, bulk edit of rule actions', () => {
beforeEach(() => {
deleteAlertsAndRules();
deleteConnectors();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
createSlackConnector().then(({ body }) => {
const actions: RuleActionArray = [

View file

@ -44,8 +44,6 @@ import {
getNewTermsRule,
} from '../../objects/rule';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
const DATA_VIEW_ID = 'auditbeat';
const expectedIndexPatterns = ['index-1-*', 'index-2-*'];
@ -59,7 +57,7 @@ describe('Bulk editing index patterns of rules with a data view only', () => {
beforeEach(() => {
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
postDataView(DATA_VIEW_ID);
@ -188,7 +186,7 @@ describe('Bulk editing index patterns of rules with index patterns and rules wit
beforeEach(() => {
login();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
postDataView(DATA_VIEW_ID);

View file

@ -62,7 +62,6 @@ import {
waitForTheRuleToBeExecuted,
} from '../../tasks/create_new_rule';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { login, visit } from '../../tasks/login';
import { getDetails } from '../../tasks/rule_details';
@ -83,7 +82,7 @@ describe('Custom query rules', () => {
are creating a data view we'll use after and cleanKibana does not delete all the data views created, esArchiverReseKibana does.
We don't use esArchiverReseKibana in all the tests because is a time-consuming method and we don't need to perform an exhaustive
cleaning in all the other tests. */
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
if (rule.data_view_id != null) {
postDataView(rule.data_view_id);
}

View file

@ -60,7 +60,6 @@ import {
import { login, visit } from '../../tasks/login';
import { RULE_CREATION } from '../../urls/navigation';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
describe('EQL rules', () => {
before(() => {
@ -152,10 +151,10 @@ describe('EQL rules', () => {
const rule = getEqlSequenceRule();
before(() => {
esArchiverLoad('auditbeat_big');
cy.task('esArchiverLoad', 'auditbeat_big');
});
after(() => {
esArchiverUnload('auditbeat_big');
cy.task('esArchiverUnload', 'auditbeat_big');
});
it('Creates and enables a new EQL rule with a sequence', function () {

View file

@ -101,7 +101,6 @@ import {
SCHEDULE_LOOKBACK_UNITS_INPUT,
} from '../../screens/create_new_rule';
import { goBackToRuleDetails } from '../../tasks/edit_rule';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { login, visit, visitWithoutDateRange } from '../../tasks/login';
import { goBackToRulesTable, getDetails } from '../../tasks/rule_details';
@ -121,8 +120,8 @@ describe('indicator match', () => {
before(() => {
cleanKibana();
esArchiverLoad('threat_indicator');
esArchiverLoad('suspicious_source_event');
cy.task('esArchiverLoad', 'threat_indicator');
cy.task('esArchiverLoad', 'suspicious_source_event');
});
beforeEach(() => {
@ -130,8 +129,8 @@ describe('indicator match', () => {
});
after(() => {
esArchiverUnload('threat_indicator');
esArchiverUnload('suspicious_source_event');
cy.task('esArchiverUnload', 'threat_indicator');
cy.task('esArchiverUnload', 'suspicious_source_event');
});
describe('Creating new indicator match rules', () => {

View file

@ -48,7 +48,6 @@ import {
} from '../../screens/rule_details';
import { expectNumberOfRules, goToRuleDetails } from '../../tasks/alerts_detection_rules';
import { cleanKibana } from '../../tasks/common';
import {
createAndEnableRule,
fillAboutRuleWithOverrideAndContinue,
@ -70,10 +69,6 @@ describe('Detection rules, override', () => {
const mitreAttack = rule.threat;
const expectedMitre = formatMitreAttackDescription(mitreAttack ?? []);
before(() => {
cleanKibana();
});
beforeEach(() => {
login();
});

View file

@ -10,7 +10,6 @@ import { createRuleAssetSavedObject } from '../../helpers/rules';
import { waitForRulesTableToBeLoaded } from '../../tasks/alerts_detection_rules';
import { createAndInstallMockedPrebuiltRules } from '../../tasks/api_calls/prebuilt_rules';
import { resetRulesTableState, deleteAlertsAndRules } from '../../tasks/common';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { login, waitForPageWithoutDateRange } from '../../tasks/login';
import { SECURITY_DETECTIONS_RULES_URL } from '../../urls/navigation';
import { ROLES } from '../../../common/test';
@ -57,7 +56,7 @@ describe('Detection rules, Prebuilt Rules Installation and Update - Authorizatio
login();
resetRulesTableState();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
waitForRulesTableToBeLoaded();
createAndInstallMockedPrebuiltRules({ rules: [OUTDATED_RULE_1, OUTDATED_RULE_2] });
});

View file

@ -9,7 +9,6 @@ import { createRuleAssetSavedObject } from '../../helpers/rules';
import { waitForRulesTableToBeLoaded } from '../../tasks/alerts_detection_rules';
import { createAndInstallMockedPrebuiltRules } from '../../tasks/api_calls/prebuilt_rules';
import { resetRulesTableState, deleteAlertsAndRules, reload } from '../../tasks/common';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { SECURITY_DETECTIONS_RULES_URL } from '../../urls/navigation';
import {
@ -30,7 +29,7 @@ describe('Detection rules, Prebuilt Rules Installation and Update - Error handli
login();
resetRulesTableState();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
visitWithoutDateRange(SECURITY_DETECTIONS_RULES_URL);
});

View file

@ -25,7 +25,6 @@ import {
createAndInstallMockedPrebuiltRules,
} from '../../tasks/api_calls/prebuilt_rules';
import { resetRulesTableState, deleteAlertsAndRules, reload } from '../../tasks/common';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { SECURITY_DETECTIONS_RULES_URL } from '../../urls/navigation';
import {
@ -46,7 +45,7 @@ describe('Detection rules, Prebuilt Rules Installation and Update workflow', ()
login();
resetRulesTableState();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
visitWithoutDateRange(SECURITY_DETECTIONS_RULES_URL);
});

View file

@ -7,7 +7,6 @@
import { cleanKibana, resetRulesTableState, deleteAlertsAndRules } from '../../tasks/common';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { esArchiverResetKibana } from '../../tasks/es_archiver';
import {
expectRulesWithExecutionStatus,
filterByExecutionStatus,
@ -33,7 +32,7 @@ describe('Rule management filters', () => {
// Make sure persisted rules table state is cleared
resetRulesTableState();
deleteAlertsAndRules();
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
});
describe('Last response filter', () => {

View file

@ -18,7 +18,6 @@ import {
import { login, visit, visitWithoutDateRange } from '../../tasks/login';
import { cleanKibana } from '../../tasks/common';
import { ENTITY_ANALYTICS_MANAGEMENT_URL, ALERTS_URL } from '../../urls/navigation';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { getNewRule } from '../../objects/rule';
import { createRule } from '../../tasks/api_calls/rules';
import { updateDateRangeInLocalDatePickers } from '../../tasks/date_picker';
@ -27,7 +26,7 @@ import { fillLocalSearchBar, submitLocalSearch } from '../../tasks/search_bar';
describe('Entity analytics management page', () => {
before(() => {
cleanKibana();
esArchiverLoad('all_users');
cy.task('esArchiverLoad', 'all_users');
});
beforeEach(() => {
@ -38,7 +37,7 @@ describe('Entity analytics management page', () => {
});
after(() => {
esArchiverUnload('all_users');
cy.task('esArchiverUnload', 'all_users');
});
it('renders page as expected', () => {

View file

@ -21,11 +21,6 @@ import {
waitForAlertsToPopulate,
waitForTheRuleToBeExecuted,
} from '../../../tasks/create_new_rule';
import {
esArchiverLoad,
esArchiverResetKibana,
esArchiverUnload,
} from '../../../tasks/es_archiver';
import { DETECTIONS_RULE_MANAGEMENT_URL } from '../../../urls/navigation';
import {
addExceptionEntryFieldValue,
@ -55,11 +50,12 @@ describe('Endpoint Exceptions workflows from Alert', () => {
const ITEM_NAME = 'Sample Exception List Item';
const ITEM_NAME_EDIT = 'Sample Exception List Item';
const ADDITIONAL_ENTRY = 'host.hostname';
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
deleteAlertsAndRules();
esArchiverLoad('endpoint');
cy.task('esArchiverLoad', 'endpoint');
createRule(getEndpointRule());
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
goToRuleDetails();
@ -68,8 +64,8 @@ describe('Endpoint Exceptions workflows from Alert', () => {
});
after(() => {
esArchiverUnload('endpoint');
esArchiverUnload('endpoint_2');
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', 'endpoint_2');
});
it('Should be able to create and close single Endpoint exception from overflow menu', () => {
@ -103,7 +99,7 @@ describe('Endpoint Exceptions workflows from Alert', () => {
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
// load more docs
esArchiverLoad('endpoint_2');
cy.task('esArchiverLoad', 'endpoint_2');
goToAlertsTab();
goToOpenedAlertsOnRuleDetailsPage();

View file

@ -32,11 +32,6 @@ import {
validateHighlightedFieldsPopulatedAsExceptionConditions,
validateEmptyExceptionConditionField,
} from '../../../tasks/exceptions';
import {
esArchiverLoad,
esArchiverResetKibana,
esArchiverUnload,
} from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
goToAlertsTab,
@ -58,7 +53,7 @@ import {
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
const loadEndpointRuleAndAlerts = () => {
esArchiverLoad('endpoint');
cy.task('esArchiverLoad', 'endpoint');
login();
createRule(getEndpointRule());
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
@ -74,18 +69,18 @@ describe('Rule Exceptions workflows from Alert', () => {
const newRule = getNewRule();
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
});
after(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
deleteAlertsAndRules();
});
afterEach(() => {
esArchiverUnload('exceptions_2');
cy.task('esArchiverUnload', 'exceptions_2');
});
it('Should create a Rule exception item from alert actions overflow menu and close all matching alerts', () => {
esArchiverLoad('exceptions');
cy.task('esArchiverLoad', 'exceptions');
login();
postDataView('exceptions-*');
createRule({
@ -132,7 +127,7 @@ describe('Rule Exceptions workflows from Alert', () => {
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
// load more docs
esArchiverLoad('exceptions_2');
cy.task('esArchiverLoad', 'exceptions_2');
// now that there are no more exceptions, the docs should match and populate alerts
goToAlertsTab();

View file

@ -12,7 +12,6 @@ import { getNewRule } from '../../../objects/rule';
import { createRule } from '../../../tasks/api_calls/rules';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
import { esArchiverResetKibana } from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
addExceptionFlyoutFromViewerHeader,
@ -55,7 +54,7 @@ interface ResponseType {
describe('Add, copy comments in different exceptions type and validate sharing them between users', () => {
describe('Rule exceptions', () => {
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
const exceptionList = getExceptionList();
// create rule with exceptions
@ -153,7 +152,7 @@ describe('Add, copy comments in different exceptions type and validate sharing t
describe('Endpoint exceptions', () => {
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
// create rule with exception
createEndpointExceptionList().then((response) => {

View file

@ -11,11 +11,6 @@ import { RULE_STATUS } from '../../../screens/create_new_rule';
import { createRule } from '../../../tasks/api_calls/rules';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
import {
esArchiverLoad,
esArchiverResetKibana,
esArchiverUnload,
} from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
openExceptionFlyoutFromEmptyViewerPrompt,
@ -72,14 +67,14 @@ import { getExceptionList } from '../../../objects/exception';
// ensure the most basic logic holds.
describe.skip('Exceptions flyout', { testIsolation: false }, () => {
before(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
// this is a made-up index that has just the necessary
// mappings to conduct tests, avoiding loading large
// amounts of data like in auditbeat_exceptions
esArchiverLoad('exceptions');
cy.task('esArchiverLoad', 'exceptions');
// Comment the Conflicts here as they are skipped
// esArchiverLoad('conflicts_1');
// esArchiverLoad('conflicts_2');
// cy.task('esArchiverLoad', 'conflicts_1');
// cy.task('esArchiverLoad', 'conflicts_2');
login();
createExceptionList(getExceptionList(), getExceptionList().list_id).then((response) =>
createRule(
@ -110,7 +105,7 @@ describe.skip('Exceptions flyout', { testIsolation: false }, () => {
});
after(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
});
it('Validates empty entry values correctly', () => {

View file

@ -9,7 +9,6 @@ import { getNewRule } from '../../../objects/rule';
import { createRule } from '../../../tasks/api_calls/rules';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
import { esArchiverResetKibana, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
openExceptionFlyoutFromEmptyViewerPrompt,
@ -34,7 +33,7 @@ describe(
{ testIsolation: false },
() => {
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
// At least create Rule with exceptions_list to be able to view created exceptions
createRule({
@ -50,7 +49,7 @@ describe(
});
after(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
});
const exceptionName = 'My item name';

View file

@ -33,7 +33,6 @@ import {
closeValueListsModal,
} from '../../../tasks/lists';
import { createRule } from '../../../tasks/api_calls/rules';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import {
CLOSE_ALERTS_CHECKBOX,
EXCEPTIONS_TABLE_MODAL,
@ -54,7 +53,7 @@ describe('Use Value list in exception entry', () => {
before(() => {
cleanKibana();
login();
esArchiverLoad('exceptions');
cy.task('esArchiverLoad', 'exceptions');
createRule({
...getNewRule(),
query: 'user.name:*',
@ -69,7 +68,7 @@ describe('Use Value list in exception entry', () => {
});
afterEach(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
});
it('Should use value list in exception entry, and validate deleting value list prompt', () => {

View file

@ -9,11 +9,6 @@ import { getNewRule } from '../../../objects/rule';
import { createRule } from '../../../tasks/api_calls/rules';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
import {
esArchiverLoad,
esArchiverResetKibana,
esArchiverUnload,
} from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
goToEndpointExceptionsTab,
@ -53,8 +48,8 @@ describe('Add endpoint exception from rule details', () => {
const ITEM_NAME = 'Sample Exception List Item';
before(() => {
esArchiverResetKibana();
esArchiverLoad('auditbeat');
cy.task('esArchiverResetKibana');
cy.task('esArchiverLoad', 'auditbeat');
login();
deleteAlertsAndRules();
// create rule with exception
@ -97,7 +92,7 @@ describe('Add endpoint exception from rule details', () => {
});
after(() => {
esArchiverUnload('auditbeat');
cy.task('esArchiverUnload', 'auditbeat');
});
it('creates an exception item', () => {

View file

@ -15,11 +15,6 @@ import {
goToClosedAlertsOnRuleDetailsPage,
goToOpenedAlertsOnRuleDetailsPage,
} from '../../../tasks/alerts';
import {
esArchiverLoad,
esArchiverUnload,
esArchiverResetKibana,
} from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
addExceptionFlyoutFromViewerHeader,
@ -70,13 +65,13 @@ describe('Add/edit exception from rule details', () => {
const ITEM_FIELD = 'unique_value.test';
before(() => {
esArchiverResetKibana();
esArchiverLoad('exceptions');
cy.task('esArchiverResetKibana');
cy.task('esArchiverLoad', 'exceptions');
login();
});
after(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
});
describe('existing list and items', () => {
@ -266,7 +261,7 @@ describe('Add/edit exception from rule details', () => {
});
afterEach(() => {
esArchiverUnload('exceptions_2');
cy.task('esArchiverUnload', 'exceptions_2');
});
it('Cannot create an item to add to rule but not shared list as rule has no lists attached', () => {
@ -324,7 +319,7 @@ describe('Add/edit exception from rule details', () => {
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
// load more docs
esArchiverLoad('exceptions_2');
cy.task('esArchiverLoad', 'exceptions_2');
// now that there are no more exceptions, the docs should match and populate alerts
goToAlertsTab();

View file

@ -18,11 +18,6 @@ import {
editExceptionFlyoutItemName,
submitEditedExceptionItem,
} from '../../../tasks/exceptions';
import {
esArchiverLoad,
esArchiverUnload,
esArchiverResetKibana,
} from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import {
addFirstExceptionFromRuleDetails,
@ -51,14 +46,14 @@ describe('Add exception using data views from rule details', () => {
const ITEM_NAME = 'Sample Exception List Item';
before(() => {
esArchiverResetKibana();
esArchiverLoad('exceptions');
cy.task('esArchiverResetKibana');
cy.task('esArchiverLoad', 'exceptions');
login();
postDataView('exceptions-*');
});
after(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
});
beforeEach(() => {
@ -78,7 +73,7 @@ describe('Add exception using data views from rule details', () => {
});
afterEach(() => {
esArchiverUnload('exceptions_2');
cy.task('esArchiverUnload', 'exceptions_2');
});
it('Creates an exception item and close all matching alerts', () => {
@ -119,7 +114,7 @@ describe('Add exception using data views from rule details', () => {
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
// load more docs
esArchiverLoad('exceptions_2');
cy.task('esArchiverLoad', 'exceptions_2');
// now that there are no more exceptions, the docs should match and populate alerts
goToAlertsTab();

View file

@ -9,7 +9,6 @@ import { getExceptionList } from '../../../objects/exception';
import { getNewRule } from '../../../objects/rule';
import { ROLES } from '../../../../common/test';
import { createRule } from '../../../tasks/api_calls/rules';
import { esArchiverResetKibana } from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import { goToExceptionsTab, goToAlertsTab } from '../../../tasks/rule_details';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
@ -32,7 +31,7 @@ describe('Exceptions viewer read only', () => {
const exceptionList = getExceptionList();
before(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
// create rule with exceptions
createExceptionList(exceptionList, exceptionList.list_id).then((response) => {
createRule(

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { esArchiverResetKibana } from '../../../../tasks/es_archiver';
import { getExceptionList } from '../../../../objects/exception';
import { getNewRule } from '../../../../objects/rule';
@ -43,7 +42,7 @@ const EXCEPTION_LIST_NAME = 'Newly created list';
describe('Exception list detail page', () => {
before(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
// Create exception list associated with a rule

View file

@ -4,11 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import {
esArchiverLoad,
esArchiverUnload,
esArchiverResetKibana,
} from '../../../tasks/es_archiver';
import { getNewRule } from '../../../objects/rule';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import { createRule } from '../../../tasks/api_calls/rules';
@ -44,8 +40,8 @@ import {
describe('Add, edit and delete exception', () => {
before(() => {
esArchiverResetKibana();
esArchiverLoad('exceptions');
cy.task('esArchiverResetKibana');
cy.task('esArchiverLoad', 'exceptions');
createRule(getNewRule());
});
@ -56,7 +52,7 @@ describe('Add, edit and delete exception', () => {
waitForExceptionsTableToBeLoaded();
});
after(() => {
esArchiverUnload('exceptions');
cy.task('esArchiverUnload', 'exceptions');
});
const exceptionName = 'My item name';

View file

@ -20,7 +20,6 @@ import {
createExceptionList,
createExceptionListItem,
} from '../../../../tasks/api_calls/exceptions';
import { esArchiverResetKibana } from '../../../../tasks/es_archiver';
import { getNewRule } from '../../../../objects/rule';
const expiredDate = new Date(Date.now() - 1000000).toISOString();
@ -43,7 +42,7 @@ const getExceptionList2 = () => ({
describe('Duplicate List', () => {
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
createRule(getNewRule({ name: 'Another rule' }));

View file

@ -12,7 +12,6 @@ import {
} from '../../../../screens/exceptions';
import { createExceptionList } from '../../../../tasks/api_calls/exceptions';
import { createRule } from '../../../../tasks/api_calls/rules';
import { esArchiverResetKibana } from '../../../../tasks/es_archiver';
import {
waitForExceptionsTableToBeLoaded,
searchForExceptionList,
@ -37,7 +36,7 @@ const getExceptionList2 = () => ({
});
describe('Filter Lists', () => {
beforeEach(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
login();
// Create exception list associated with a rule

View file

@ -19,12 +19,11 @@ import {
} from '../../../../tasks/exceptions_table';
import { login, visitWithoutDateRange } from '../../../../tasks/login';
import { EXCEPTIONS_URL } from '../../../../urls/navigation';
import { esArchiverResetKibana } from '../../../../tasks/es_archiver';
describe('Import Lists', () => {
const LIST_TO_IMPORT_FILENAME = 'cypress/fixtures/7_16_exception_list.ndjson';
before(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
});
beforeEach(() => {
login();
@ -32,6 +31,7 @@ describe('Import Lists', () => {
waitForExceptionsTableToBeLoaded();
cy.intercept(/(\/api\/exception_lists\/_import)/).as('import');
});
it('Should import exception list successfully if the list does not exist', () => {
importExceptionLists(LIST_TO_IMPORT_FILENAME);

View file

@ -25,7 +25,6 @@ import {
EXCEPTIONS_TABLE_SHOWING_LISTS,
} from '../../../../screens/exceptions';
import { createExceptionList } from '../../../../tasks/api_calls/exceptions';
import { esArchiverResetKibana } from '../../../../tasks/es_archiver';
import { TOASTER } from '../../../../screens/alerts_detection_rules';
@ -47,8 +46,6 @@ const getExceptionList2 = () => ({
describe('Manage lists from "Shared Exception Lists" page', () => {
describe('Create/Export/Delete List', () => {
before(() => {
esArchiverResetKibana();
createRule(getNewRule({ name: 'Another rule' }));
// Create exception list associated with a rule

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { esArchiverResetKibana } from '../../../../tasks/es_archiver';
import { ROLES } from '../../../../../common/test';
import { getExceptionList } from '../../../../objects/exception';
import {
@ -25,7 +24,7 @@ const MISSING_PRIVILEGES_CALLOUT = 'missing-user-privileges';
describe('Shared exception lists - read only', () => {
before(() => {
esArchiverResetKibana();
cy.task('esArchiverResetKibana');
});
beforeEach(() => {

View file

@ -9,7 +9,6 @@ import { login, visit } from '../../../tasks/login';
import { ALERTS_URL, ENTITY_ANALYTICS_URL } from '../../../urls/navigation';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import {
cleanKibana,
deleteAlertsAndRules,
@ -79,8 +78,8 @@ describe('Entity Analytics Dashboard', () => {
describe('Risk Score enabled but still no data', () => {
before(() => {
esArchiverLoad('risk_hosts_no_data');
esArchiverLoad('risk_users_no_data');
cy.task('esArchiverLoad', 'risk_hosts_no_data');
cy.task('esArchiverLoad', 'risk_users_no_data');
});
beforeEach(() => {
@ -89,8 +88,8 @@ describe('Entity Analytics Dashboard', () => {
});
after(() => {
esArchiverUnload('risk_hosts_no_data');
esArchiverUnload('risk_users_no_data');
cy.task('esArchiverUnload', 'risk_hosts_no_data');
cy.task('esArchiverUnload', 'risk_users_no_data');
});
it('shows no data detected prompt for host risk score module', () => {
@ -104,8 +103,8 @@ describe('Entity Analytics Dashboard', () => {
describe('With Legacy data', () => {
before(() => {
esArchiverLoad('risk_hosts_legacy_data');
esArchiverLoad('risk_users_legacy_data');
cy.task('esArchiverLoad', 'risk_hosts_legacy_data');
cy.task('esArchiverLoad', 'risk_users_legacy_data');
});
beforeEach(() => {
@ -114,8 +113,8 @@ describe('Entity Analytics Dashboard', () => {
});
after(() => {
esArchiverUnload('risk_hosts_legacy_data');
esArchiverUnload('risk_users_legacy_data');
cy.task('esArchiverUnload', 'risk_hosts_legacy_data');
cy.task('esArchiverUnload', 'risk_users_legacy_data');
});
it('shows upgrade host risk button', () => {
@ -129,7 +128,7 @@ describe('Entity Analytics Dashboard', () => {
describe('With host risk data', () => {
before(() => {
esArchiverLoad('risk_hosts');
cy.task('esArchiverLoad', 'risk_hosts');
});
beforeEach(() => {
@ -138,7 +137,7 @@ describe('Entity Analytics Dashboard', () => {
});
after(() => {
esArchiverUnload('risk_hosts');
cy.task('esArchiverUnload', 'risk_hosts');
});
it('renders donut chart', () => {
@ -218,7 +217,7 @@ describe('Entity Analytics Dashboard', () => {
describe('With user risk data', () => {
before(() => {
esArchiverLoad('risk_users');
cy.task('esArchiverLoad', 'risk_users');
});
beforeEach(() => {
@ -227,7 +226,7 @@ describe('Entity Analytics Dashboard', () => {
});
after(() => {
esArchiverUnload('risk_users');
cy.task('esArchiverUnload', 'risk_users');
});
it('renders donut chart', () => {
@ -308,11 +307,11 @@ describe('Entity Analytics Dashboard', () => {
// tracked by https://github.com/elastic/kibana/issues/161874
describe.skip('With anomalies data', () => {
before(() => {
esArchiverLoad('network');
cy.task('esArchiverLoad', 'network');
});
after(() => {
esArchiverUnload('network');
cy.task('esArchiverUnload', 'network');
});
beforeEach(() => {

View file

@ -8,13 +8,12 @@
import { login, visitHostDetailsPage } from '../../../tasks/login';
import { cleanKibana, waitForTableToLoad } from '../../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { TABLE_CELL, TABLE_ROWS } from '../../../screens/alerts_details';
describe('risk tab', () => {
before(() => {
cleanKibana();
esArchiverLoad('risk_hosts');
cy.task('esArchiverLoad', 'risk_hosts');
});
beforeEach(() => {
@ -22,7 +21,7 @@ describe('risk tab', () => {
});
after(() => {
esArchiverUnload('risk_hosts');
cy.task('esArchiverUnload', 'risk_hosts');
});
it('renders risk tab', () => {

View file

@ -34,7 +34,6 @@ import { kqlSearch } from '../../../tasks/security_header';
import { HOSTS_URL } from '../../../urls/navigation';
import { resetFields } from '../../../tasks/timeline';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
const defaultHeadersInDefaultEcsCategory = [
{ id: '@timestamp' },
@ -48,11 +47,11 @@ const defaultHeadersInDefaultEcsCategory = [
describe('Events Viewer', () => {
before(() => {
esArchiverLoad('auditbeat_big');
cy.task('esArchiverLoad', 'auditbeat_big');
});
after(() => {
esArchiverUnload('auditbeat_big');
cy.task('esArchiverUnload', 'auditbeat_big');
});
context('Fields rendering', () => {

View file

@ -6,7 +6,6 @@
*/
import { cleanKibana } from '../../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import {
navigateToHostRiskDetailTab,
openRiskTableFilterAndSelectTheCriticalOption,
@ -25,7 +24,7 @@ import { clearSearchBar, kqlSearch } from '../../../tasks/security_header';
describe('risk tab', () => {
before(() => {
cleanKibana();
esArchiverLoad('risk_hosts');
cy.task('esArchiverLoad', 'risk_hosts');
});
beforeEach(() => {
@ -35,7 +34,7 @@ describe('risk tab', () => {
});
after(() => {
esArchiverUnload('risk_hosts');
cy.task('esArchiverUnload', 'risk_hosts');
});
it('renders the table', () => {

View file

@ -9,14 +9,13 @@ import { login, visit } from '../../../tasks/login';
import { HOSTS_URL } from '../../../urls/navigation';
import { cleanKibana } from '../../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { TABLE_CELL } from '../../../screens/alerts_details';
import { kqlSearch } from '../../../tasks/security_header';
describe('All hosts table', () => {
before(() => {
cleanKibana();
esArchiverLoad('risk_hosts');
cy.task('esArchiverLoad', 'risk_hosts');
});
beforeEach(() => {
@ -24,7 +23,7 @@ describe('All hosts table', () => {
});
after(() => {
esArchiverUnload('risk_hosts');
cy.task('esArchiverUnload', 'risk_hosts');
});
it('it renders risk column', () => {

View file

@ -20,7 +20,6 @@ import {
openHoverActions,
} from '../../../tasks/network/flows';
import { openTimelineUsingToggle } from '../../../tasks/security_main';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
const testDomain = 'myTest';
@ -32,11 +31,11 @@ describe.skip('Hover actions', () => {
};
before(() => {
esArchiverLoad('network');
cy.task('esArchiverLoad', 'network');
});
after(() => {
esArchiverUnload('network');
cy.task('esArchiverUnload', 'network');
});
beforeEach(() => {

View file

@ -13,7 +13,6 @@ import {
FILTER_OUT,
SHOW_TOP_FIELD,
} from '../../../screens/network/flows';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visit } from '../../../tasks/login';
import { mouseoverOnToOverflowItem, openHoverActions } from '../../../tasks/network/flows';
@ -26,7 +25,7 @@ const testDomainTwo = 'myTest2';
describe('Overflow items', () => {
context('Network stats and tables', () => {
before(() => {
esArchiverLoad('network');
cy.task('esArchiverLoad', 'network');
});
beforeEach(() => {
@ -44,7 +43,7 @@ describe('Overflow items', () => {
});
after(() => {
esArchiverUnload('network');
cy.task('esArchiverUnload', 'network');
});
it('Shows more items in the popover', () => {

View file

@ -15,12 +15,11 @@ import { OVERVIEW_URL } from '../../../urls/navigation';
import { cleanKibana } from '../../../tasks/common';
import { createTimeline, favoriteTimeline } from '../../../tasks/api_calls/timelines';
import { getTimeline } from '../../../objects/timeline';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
describe('Overview Page', () => {
before(() => {
cleanKibana();
esArchiverLoad('overview');
cy.task('esArchiverLoad', 'overview');
});
beforeEach(() => {
@ -29,7 +28,7 @@ describe('Overview Page', () => {
});
after(() => {
esArchiverUnload('overview');
cy.task('esArchiverUnload', 'overview');
});
it('Host stats render with correct values', () => {
@ -67,10 +66,10 @@ describe('Overview Page', () => {
describe('Overview page with no data', () => {
before(() => {
esArchiverUnload('auditbeat');
cy.task('esArchiverUnload', 'auditbeat');
});
after(() => {
esArchiverLoad('auditbeat');
cy.task('esArchiverLoad', 'auditbeat');
});
it('Splash screen should be here', () => {

View file

@ -10,7 +10,6 @@ import {
UNCOMMON_PROCESSES_TABLE,
} from '../../../screens/hosts/uncommon_processes';
import { TABLE_FIRST_PAGE, TABLE_SECOND_PAGE } from '../../../screens/table_pagination';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { waitsForEventsToBeLoaded } from '../../../tasks/hosts/events';
import { openEvents, openUncommonProcesses } from '../../../tasks/hosts/main';
import { waitForUncommonProcessesToBeLoaded } from '../../../tasks/hosts/uncommon_processes';
@ -24,7 +23,7 @@ import { goToTablePage, sortFirstTableColumn } from '../../../tasks/table_pagina
describe('Pagination', () => {
describe('Host uncommon processes table)', () => {
before(() => {
esArchiverLoad('host_uncommon_processes');
cy.task('esArchiverLoad', 'host_uncommon_processes');
});
beforeEach(() => {
@ -34,7 +33,7 @@ describe('Pagination', () => {
});
after(() => {
esArchiverUnload('host_uncommon_processes');
cy.task('esArchiverUnload', 'host_uncommon_processes');
});
it('pagination updates results and page number', () => {
@ -100,7 +99,7 @@ describe('Pagination', () => {
describe('All users and all Hosts tables', () => {
before(() => {
esArchiverLoad('all_users');
cy.task('esArchiverLoad', 'all_users');
});
beforeEach(() => {
@ -108,7 +107,7 @@ describe('Pagination', () => {
});
after(() => {
esArchiverUnload('all_users');
cy.task('esArchiverUnload', 'all_users');
});
it(`reset all Hosts pagination when sorting column`, () => {

View file

@ -14,7 +14,6 @@ import {
import { EVENTS_TAB, EVENTS_TAB_CONTENT } from '../../../screens/users/user_events';
import { RISK_SCORE_TAB, RISK_SCORE_TAB_CONTENT } from '../../../screens/users/user_risk_score';
import { cleanKibana } from '../../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visit, visitUserDetailsPage } from '../../../tasks/login';
@ -23,9 +22,9 @@ import { USERS_URL } from '../../../urls/navigation';
describe('Users stats and tables', () => {
before(() => {
cleanKibana();
esArchiverLoad('users');
cy.task('esArchiverLoad', 'users');
esArchiverLoad('risk_users');
cy.task('esArchiverLoad', 'risk_users');
});
beforeEach(() => {
@ -34,8 +33,8 @@ describe('Users stats and tables', () => {
});
after(() => {
esArchiverUnload('users');
esArchiverUnload('risk_users');
cy.task('esArchiverUnload', 'users');
cy.task('esArchiverUnload', 'risk_users');
});
describe('Users page tabs', () => {

View file

@ -22,15 +22,14 @@ import {
waitForPageToBeLoaded,
waitForWelcomePanelToBeLoaded,
} from '../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { selectDataView } from '../../tasks/sourcerer';
const DATA_VIEW = 'auditbeat-*';
describe('Inspect Explore pages', () => {
before(() => {
esArchiverLoad('risk_users');
esArchiverLoad('risk_hosts');
cy.task('esArchiverLoad', 'risk_users');
cy.task('esArchiverLoad', 'risk_hosts');
login();
// Create and select data view
@ -38,8 +37,8 @@ describe('Inspect Explore pages', () => {
});
after(() => {
esArchiverUnload('risk_users');
esArchiverUnload('risk_hosts');
cy.task('esArchiverUnload', 'risk_users');
cy.task('esArchiverUnload', 'risk_hosts');
});
INSPECT_BUTTONS_IN_SECURITY.forEach(({ pageName, url, lensVisualizations, tables }) => {

View file

@ -12,14 +12,13 @@ import {
} from '../../../tasks/alerts';
import { cleanKibana } from '../../../tasks/common';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visit } from '../../../tasks/login';
import { ALERTS_URL } from '../../../urls/navigation';
describe('Alerts Table Action column', () => {
before(() => {
cleanKibana();
esArchiverLoad('process_ancestry');
cy.task('esArchiverLoad', 'process_ancestry');
});
beforeEach(() => {
@ -29,7 +28,7 @@ describe('Alerts Table Action column', () => {
});
after(() => {
esArchiverUnload('process_ancestry');
cy.task('esArchiverUnload', 'process_ancestry');
});
it('should have session viewer button visible & open session viewer on click', () => {

View file

@ -25,7 +25,6 @@ import {
import { createRule } from '../../../tasks/api_calls/rules';
import { cleanKibana } from '../../../tasks/common';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visit, visitWithoutDateRange } from '../../../tasks/login';
import { getNewRule, getUnmappedRule } from '../../../objects/rule';
import { ALERTS_URL } from '../../../urls/navigation';
@ -59,7 +58,7 @@ describe('Alert details flyout', () => {
describe('With unmapped fields', () => {
before(() => {
cleanKibana();
esArchiverLoad('unmapped_fields');
cy.task('esArchiverLoad', 'unmapped_fields');
createRule(getUnmappedRule());
});
@ -71,7 +70,7 @@ describe('Alert details flyout', () => {
});
after(() => {
esArchiverUnload('unmapped_fields');
cy.task('esArchiverUnload', 'unmapped_fields');
});
it('should display the unmapped field on the JSON view', () => {
@ -124,7 +123,7 @@ describe('Alert details flyout', () => {
describe('Url state management', () => {
before(() => {
cleanKibana();
esArchiverLoad('query_alert');
cy.task('esArchiverLoad', 'query_alert');
});
beforeEach(() => {
@ -169,7 +168,7 @@ describe('Alert details flyout', () => {
describe('Localstorage management', () => {
before(() => {
cleanKibana();
esArchiverLoad('query_alert');
cy.task('esArchiverLoad', 'query_alert');
});
beforeEach(() => {

View file

@ -16,7 +16,6 @@ import {
waitForAlertsToPopulate,
waitForTheRuleToBeExecuted,
} from '../../../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import { navigateFromHeaderTo } from '../../../tasks/security_header';
import { DETECTIONS_RULE_MANAGEMENT_URL } from '../../../urls/navigation';
@ -25,7 +24,7 @@ const EXPECTED_NUMBER_OF_ALERTS = 5;
describe('Alerts generated by building block rules', () => {
before(() => {
esArchiverLoad('auditbeat_big');
cy.task('esArchiverLoad', 'auditbeat_big');
cleanKibana();
login();
});
@ -33,7 +32,7 @@ describe('Alerts generated by building block rules', () => {
createRule(getBuildingBlockRule());
});
after(() => {
esArchiverUnload('auditbeat_big');
cy.task('esArchiverUnload', 'auditbeat_big');
});
it('Alerts should be visible on the Rule Detail page and not visible on the Overview page', () => {

View file

@ -34,19 +34,18 @@ import {
import { createRule } from '../../../tasks/api_calls/rules';
import { cleanKibana, deleteAlertsAndRules } from '../../../tasks/common';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visit } from '../../../tasks/login';
import { ALERTS_URL } from '../../../urls/navigation';
describe('Changing alert status', () => {
before(() => {
esArchiverLoad('auditbeat_big');
cy.task('esArchiverLoad', 'auditbeat_big');
cleanKibana();
});
after(() => {
esArchiverUnload('auditbeat_big');
cy.task('esArchiverUnload', 'auditbeat_big');
});
context('Opening alerts', () => {

View file

@ -17,7 +17,6 @@ import {
selectFirstPageEvents,
} from '../../../tasks/common/event_table';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { waitsForEventsToBeLoaded } from '../../../tasks/hosts/events';
import { openEvents, openSessions } from '../../../tasks/hosts/main';
import { login, visit } from '../../../tasks/login';
@ -26,12 +25,12 @@ import { ALERTS_URL, HOSTS_URL } from '../../../urls/navigation';
describe('Bulk Investigate in Timeline', () => {
before(() => {
cleanKibana();
esArchiverLoad('bulk_process');
cy.task('esArchiverLoad', 'bulk_process');
login();
});
after(() => {
esArchiverUnload('bulk_process');
cy.task('esArchiverUnload', 'bulk_process');
});
context('Alerts', () => {

View file

@ -15,7 +15,6 @@ import {
TIMELINE_FLYOUT,
} from '../../../screens/timeline';
import { cleanKibana } from '../../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../../tasks/es_archiver';
import { login, visit } from '../../../tasks/login';
import { openTimelineUsingToggle } from '../../../tasks/security_main';
@ -27,7 +26,7 @@ const defaultPageSize = 25;
describe('Pagination', () => {
before(() => {
cleanKibana();
esArchiverLoad('timeline');
cy.task('esArchiverLoad', 'timeline');
});
beforeEach(() => {
@ -38,7 +37,7 @@ describe('Pagination', () => {
});
after(() => {
esArchiverUnload('timeline');
cy.task('esArchiverUnload', 'timeline');
});
it(`should have ${defaultPageSize} events in the page by default`, () => {

View file

@ -14,7 +14,6 @@ import {
import { login, visit } from '../../tasks/login';
import { OVERVIEW_URL } from '../../urls/navigation';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
describe('CTI Link Panel', () => {
beforeEach(() => {
@ -33,7 +32,7 @@ describe('CTI Link Panel', () => {
describe('enabled threat intel module', () => {
before(() => {
esArchiverLoad('threat_indicator');
cy.task('esArchiverLoad', 'threat_indicator');
});
beforeEach(() => {
@ -41,7 +40,7 @@ describe('CTI Link Panel', () => {
});
after(() => {
esArchiverUnload('threat_indicator');
cy.task('esArchiverUnload', 'threat_indicator');
});
it('renders disabled dashboard module as expected when there are no events in the selected time period', () => {

View file

@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { EsArchiver } from '@kbn/es-archiver';
import { KbnClient } from '@kbn/test';
import { Client, HttpConnection } from '@elastic/elasticsearch';
import { ToolingLog } from '@kbn/tooling-log';
export const esArchiver = (
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): EsArchiver => {
const log = new ToolingLog({ level: 'verbose', writeTo: process.stdout });
const client = new Client({
node: config.env.ELASTICSEARCH_URL,
Connection: HttpConnection,
});
const kbnClient = new KbnClient({
log,
url: config.env.CYPRESS_BASE_URL as string,
});
const esArchiverInstance = new EsArchiver({
log,
client,
kbnClient,
baseDir: '../../../test/security_solution_cypress/es_archives',
});
on('task', {
esArchiverLoad: async (archiveName) => esArchiverInstance.load(archiveName),
esArchiverUnload: async (archiveName) => esArchiverInstance.unload(archiveName),
esArchiverResetKibana: async () => esArchiverInstance.emptyKibanaIndex(),
esArchiverCCSLoad: async (archiveName) => {
const ccsEsArchiverInstance = new EsArchiver({
client: new Client({
node: config.env.CCS_ELASTICSEARCH_URL,
Connection: HttpConnection,
}),
log,
kbnClient: new KbnClient({
log,
url: config.env.CCS_KIBANA_URL,
}),
baseDir: '../../../test/security_solution_cypress/es_archives',
});
return ccsEsArchiverInstance.load(archiveName);
},
});
return esArchiverInstance;
};

View file

@ -1,52 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import Path from 'path';
const ES_ARCHIVE_DIR = '../../test/security_solution_cypress/es_archives';
const CONFIG_PATH = '../../test/functional/config.base.js';
const ES_URL = Cypress.env('ELASTICSEARCH_URL');
const KIBANA_URL = Cypress.config().baseUrl;
const CCS_ES_URL = Cypress.env('CCS_ELASTICSEARCH_URL');
const CCS_KIBANA_URL = Cypress.env('CCS_KIBANA_URL');
// Otherwise cy.exec would inject NODE_TLS_REJECT_UNAUTHORIZED=0 and node would abort if used over https
const NODE_TLS_REJECT_UNAUTHORIZED = '1';
export const esArchiverLoad = (folder: string) => {
const path = Path.join(ES_ARCHIVE_DIR, folder);
cy.log(`exec esArchiverLoad`, path);
cy.exec(
`node ../../../scripts/es_archiver load "${path}" --config "${CONFIG_PATH}" --es-url "${ES_URL}" --kibana-url "${KIBANA_URL}"`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED } }
);
};
export const esArchiverUnload = (folder: string) => {
const path = Path.join(ES_ARCHIVE_DIR, folder);
cy.log(`exec esArchiverUnload`, path);
cy.exec(
`node ../../../scripts/es_archiver unload "${path}" --config "${CONFIG_PATH}" --es-url "${ES_URL}" --kibana-url "${KIBANA_URL}"`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED } }
);
};
export const esArchiverResetKibana = () => {
cy.log(`exec esArchiverResetKibana`);
cy.exec(
`node ../../../scripts/es_archiver empty-kibana-index --config "${CONFIG_PATH}" --es-url "${ES_URL}" --kibana-url "${KIBANA_URL}"`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED }, failOnNonZeroExit: false }
);
};
export const esArchiverCCSLoad = (folder: string) => {
const path = Path.join(ES_ARCHIVE_DIR, folder);
cy.exec(
`node ../../../scripts/es_archiver load "${path}" --config "${CONFIG_PATH}" --es-url "${CCS_ES_URL}" --kibana-url "${CCS_KIBANA_URL}"`,
{ env: { NODE_TLS_REJECT_UNAUTHORIZED } }
);
};

View file

@ -37,6 +37,9 @@
"@kbn/data-plugin",
"@kbn/core-http-common",
"@kbn/data-views-plugin",
"@kbn/es-archiver",
"@kbn/test",
"@kbn/tooling-log",
"@kbn/fleet-plugin",
]
}

View file

@ -8,7 +8,6 @@
import { run } from '@kbn/dev-cli-runner';
import yargs from 'yargs';
import _ from 'lodash';
import * as fs from 'fs';
import globby from 'globby';
import pMap from 'p-map';
import { ToolingLog } from '@kbn/tooling-log';
@ -28,18 +27,12 @@ import {
ProviderCollection,
readProviderSpec,
} from '@kbn/test/src/functional_test_runner/lib';
import * as parser from '@babel/parser';
import type {
ExpressionStatement,
Identifier,
ObjectExpression,
ObjectProperty,
} from '@babel/types';
import { createFailError } from '@kbn/dev-cli-errors';
import pRetry from 'p-retry';
import { renderSummaryTable } from './print_run';
import { getLocalhostRealIp } from '../endpoint/common/localhost_services';
import { parseTestFileConfig } from './utils';
/**
* Retrieve test files using a glob pattern.
@ -77,6 +70,7 @@ export const cli = () => {
async () => {
const { argv } = yargs(process.argv.slice(2));
const isOpen = argv._[0] === 'open';
const cypressConfigFile = await import(require.resolve(`../../${argv.configFile}`));
const spec: string | undefined = argv?.spec as string;
const files = retrieveIntegrations(spec ? [spec] : cypressConfigFile?.e2e?.specPattern);
@ -138,69 +132,6 @@ export const cli = () => {
_.pull(fleetServerPorts, fleetServerPort);
};
const parseTestFileConfig = (
filePath: string
): Record<string, string | number | Record<string, string | number>> | undefined => {
const testFile = fs.readFileSync(filePath, { encoding: 'utf8' });
const ast = parser.parse(testFile, {
sourceType: 'module',
plugins: ['typescript'],
});
const expressionStatement = _.find(ast.program.body, ['type', 'ExpressionStatement']) as
| ExpressionStatement
| undefined;
const callExpression = expressionStatement?.expression;
// @ts-expect-error
if (expressionStatement?.expression?.arguments?.length === 3) {
// @ts-expect-error
const callExpressionArguments = _.find(callExpression?.arguments, [
'type',
'ObjectExpression',
]) as ObjectExpression | undefined;
const callExpressionProperties = _.find(callExpressionArguments?.properties, [
'key.name',
'env',
]) as ObjectProperty[] | undefined;
// @ts-expect-error
const ftrConfig = _.find(callExpressionProperties?.value?.properties, [
'key.name',
'ftrConfig',
]);
if (!ftrConfig) {
return {};
}
return _.reduce(
ftrConfig.value.properties,
(acc: Record<string, string | number | Record<string, string>>, property) => {
const key = (property.key as Identifier).name;
let value;
if (property.value.type === 'ArrayExpression') {
value = _.map(property.value.elements, (element) => {
if (element.type === 'StringLiteral') {
return element.value as string;
}
return element.value as string;
});
} else if (property.value.type === 'StringLiteral') {
value = property.value.value;
}
if (key && value) {
acc[key] = value;
}
return acc;
},
{}
);
}
return undefined;
};
const log = new ToolingLog({
level: 'info',
writeTo: process.stdout,
@ -208,8 +139,6 @@ export const cli = () => {
const hostRealIp = getLocalhostRealIp();
const isOpen = argv._[0] === 'open';
await pMap(
files,
async (filePath) => {

View file

@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import _ from 'lodash';
import * as fs from 'fs';
import * as parser from '@babel/parser';
import type {
ExpressionStatement,
Identifier,
ObjectExpression,
ObjectProperty,
} from '@babel/types';
export const parseTestFileConfig = (
filePath: string
): Record<string, string | number | Record<string, string | number>> | undefined => {
const testFile = fs.readFileSync(filePath, { encoding: 'utf8' });
const ast = parser.parse(testFile, {
sourceType: 'module',
plugins: ['typescript'],
});
const expressionStatement = _.find(ast.program.body, ['type', 'ExpressionStatement']) as
| ExpressionStatement
| undefined;
const callExpression = expressionStatement?.expression;
// @ts-expect-error
if (expressionStatement?.expression?.arguments?.length === 3) {
// @ts-expect-error
const callExpressionArguments = _.find(callExpression?.arguments, [
'type',
'ObjectExpression',
]) as ObjectExpression | undefined;
const callExpressionProperties = _.find(callExpressionArguments?.properties, [
'key.name',
'env',
]) as ObjectProperty[] | undefined;
// @ts-expect-error
const ftrConfig = _.find(callExpressionProperties?.value?.properties, [
'key.name',
'ftrConfig',
]);
if (!ftrConfig) {
return {};
}
return _.reduce(
ftrConfig.value.properties,
(acc: Record<string, string | number | Record<string, string>>, property) => {
const key = (property.key as Identifier).name;
let value;
if (property.value.type === 'ArrayExpression') {
value = _.map(property.value.elements, (element) => {
if (element.type === 'StringLiteral') {
return element.value as string;
}
return element.value as string;
});
} else if (property.value.type === 'StringLiteral') {
value = property.value.value;
}
if (key && value) {
acc[key] = value;
}
return acc;
},
{}
);
}
return undefined;
};

View file

@ -6,8 +6,6 @@
*/
import { FtrConfigProviderContext } from '@kbn/test';
import type { FtrProviderContext } from './runner';
import { SecuritySolutionConfigurableCypressTestRunner } from './runner';
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
@ -16,7 +14,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
return {
...securitySolutionCypressConfig.getAll(),
testRunner: (context: FtrProviderContext) =>
SecuritySolutionConfigurableCypressTestRunner(context),
testRunner: SecuritySolutionConfigurableCypressTestRunner,
};
}

View file

@ -7,8 +7,6 @@
import { FtrConfigProviderContext } from '@kbn/test';
import { CA_CERT_PATH } from '@kbn/dev-utils';
import type { FtrProviderContext } from './runner';
import { SecuritySolutionConfigurableCypressTestRunner } from './runner';
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
@ -47,7 +45,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
],
},
testRunner: (context: FtrProviderContext) =>
SecuritySolutionConfigurableCypressTestRunner(context),
testRunner: SecuritySolutionConfigurableCypressTestRunner,
};
}

View file

@ -15,10 +15,9 @@ import { FtrProviderContext } from '../common/ftr_provider_context';
export type { FtrProviderContext } from '../common/ftr_provider_context';
export async function SecuritySolutionConfigurableCypressTestRunner(
{ getService }: FtrProviderContext,
envVars?: Record<string, string>
) {
export async function SecuritySolutionConfigurableCypressTestRunner({
getService,
}: FtrProviderContext) {
const config = getService('config');
const esArchiver = getService('esArchiver');
@ -30,33 +29,12 @@ export async function SecuritySolutionConfigurableCypressTestRunner(
CYPRESS_ELASTICSEARCH_URL: Url.format(config.get('servers.elasticsearch')),
CYPRESS_ELASTICSEARCH_USERNAME: config.get('servers.elasticsearch.username'),
CYPRESS_ELASTICSEARCH_PASSWORD: config.get('servers.elasticsearch.password'),
...envVars,
baseUrl: Url.format(config.get('servers.kibana')),
BASE_URL: Url.format(config.get('servers.kibana')),
ELASTICSEARCH_URL: Url.format(config.get('servers.elasticsearch')),
ELASTICSEARCH_USERNAME: config.get('servers.elasticsearch.username'),
ELASTICSEARCH_PASSWORD: config.get('servers.elasticsearch.password'),
};
// await withProcRunner(log, async (procs) => {
// // TODO: use Cypress module API wrapper to make it easier to run Cypress programmatically
// await procs.run('cypress', {
// cmd: 'yarn',
// args: [command],
// cwd: resolve(__dirname, '../../plugins/security_solution'),
// env: {
// FORCE_COLOR: '1',
// CYPRESS_BASE_URL: Url.format(config.get('servers.kibana')),
// CYPRESS_ELASTICSEARCH_URL: Url.format(config.get('servers.elasticsearch')),
// CYPRESS_ELASTICSEARCH_USERNAME: config.get('servers.elasticsearch.username'),
// CYPRESS_ELASTICSEARCH_PASSWORD: config.get('servers.elasticsearch.password'),
// ...(config.get('kbnTestServer.env')?.cypress?.env || {}),
// ...process.env,
// ...envVars,
// },
// wait: true,
// });
// });
}
export async function SecuritySolutionCypressCcsTestRunner({ getService }: FtrProviderContext) {