Skip to content

Commit

Permalink
[Security Solution] Allowing to use ftr archives in Cypress (elastic#…
Browse files Browse the repository at this point in the history
…178724)

## Summary

Per @rylnd requirement, we are extending our es_archiver cypress task in
order to be capable to use archives placed in
`x-pack/test/functional/es_archives/security_solution` in Cypress.

## Archives living in our Cypress directory

Use the following commands to load and unload the archive in your test.

```typescript
    cy.task('esArchiverLoad', { archiveName: 'timeline' });
    cy.task('esArchiverUnload', { archiveName: 'timeline' });
```


## Archives living in
`x-pack/test/functional/es_archives/security_solution`

Use the following commands to load and unload the archive in your test.

```typescript
    cy.task('esArchiverLoad', { archiveName: 'alias', type: 'ftr' });
    cy.task('esArchiverUnload', { archiveName: 'alias', type: 'ftr' });
```

In this PR we are also adding the
`/^x-pack/test/functional/es_archives/security_solution` route as a
dependency when executing tests in buildkite to make sure that changes
there are not breaking the Security Solution Cypress tests.

---------

Co-authored-by: Ryland Herrick <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored Mar 15, 2024
1 parent 4ae02b0 commit f1e093e
Show file tree
Hide file tree
Showing 44 changed files with 128 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .buildkite/scripts/pipelines/pull_request/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const uploadPipeline = (pipelineContent: string | object) => {
/^x-pack\/packages\/security-solution/,
/^x-pack\/packages\/kbn-elastic-assistant/,
/^x-pack\/packages\/kbn-elastic-assistant-common/,
/^x-pack\/test\/functional\/es_archives\/security_solution/,
/^x-pack\/test\/security_solution_cypress/,
])) ||
GITHUB_PR_LABELS.includes('ci:all-cypress-suites')
Expand Down Expand Up @@ -271,6 +272,7 @@ const uploadPipeline = (pipelineContent: string | object) => {
/^x-pack\/packages\/security-solution/,
/^x-pack\/packages\/kbn-elastic-assistant/,
/^x-pack\/packages\/kbn-elastic-assistant-common/,
/^x-pack\/test\/functional\/es_archives\/security_solution/,
/^x-pack\/test\/security_solution_cypress/,
])) ||
GITHUB_PR_LABELS.includes('ci:all-cypress-suites')
Expand Down
15 changes: 15 additions & 0 deletions x-pack/test/security_solution_cypress/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ Note that the command will create the folder if it does not exist.
Task [cypress/support/es_archiver.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/support/es_archiver.ts) provides helpers such as `esArchiverLoad` and `esArchiverUnload` by means of `es_archiver`'s CLI.
Archives used only for Cypress tests purposes are stored in `x-pack/test/security_solution_cypress/es_archives` and are used as follow on the tests.
```typescript
cy.task('esArchiverLoad', { archiveName: 'overview' });
cy.task('esArchiverUnload', { archiveName: 'overview'});

```
You can also use archives stored in `kibana/x-pack/test/functional/es_archives`. In order to do sow uste it on the tests as follow.
```typescript
cy.task('esArchiverLoad', { archiveName: 'security_solution/alias' }, type: 'ftr');
cy.task('esArchiverUnload', { archiveName: 'security_solution/alias', type:'ftr'});
```
## Serverless
Note that we use tags in order to select which tests we want to execute, if you want a test to be executed on serverless you need to add @serverless tag to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Alert user assignment - ESS & Serverless', { tags: ['@ess', '@serverle
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Alert user assignment - ESS', { tags: ['@ess'] }, () => {
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Alert user assignment - Basic License', { tags: ['@ess'] }, () => {
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ describe(
});

after(() => {
cy.task('esArchiverUnload', 'threat_indicator');
cy.task('esArchiverUnload', 'suspicious_source_event');
cy.task('esArchiverUnload', { archiveName: 'threat_indicator' });
cy.task('esArchiverUnload', { archiveName: 'suspicious_source_event' });
});

beforeEach(() => {
Expand Down Expand Up @@ -165,7 +165,7 @@ describe(
});

after(() => {
cy.task('esArchiverUnload', 'threat_indicator2');
cy.task('esArchiverUnload', { archiveName: 'threat_indicator2' });
});

it('Displays matched fields from both indicator match rules and investigation time enrichments on Threat Intel tab', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe.skip('Changing alert status', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

context('Opening alerts', { tags: ['@ess', '@serverless'] }, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('Alert tagging', { tags: ['@ess', '@serverless'] }, () => {
});

after(() => {
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'endpoint' });
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe.skip(
const ADDITIONAL_ENTRY = 'host.hostname';

beforeEach(() => {
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', { archiveName: 'endpoint' });
login();
deleteAlertsAndRules();

Expand All @@ -62,7 +62,7 @@ describe.skip(
});

after(() => {
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', { archiveName: 'endpoint' });
});

it('Should be able to create and close single Endpoint exception from overflow menu', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ describe.skip(
const ADDITIONAL_ENTRY = 'host.hostname';

beforeEach(() => {
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', { archiveName: 'endpoint' });
cy.task('esArchiverLoad', { archiveName: 'endpoint' });
login();
createRule(getEndpointRule()).then((rule) => visitRuleDetailsPage(rule.body.id));

waitForAlertsToPopulate();
});
after(() => {
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', { archiveName: 'endpoint' });
deleteAlertsAndRules();
});
afterEach(() => {
cy.task('esArchiverUnload', 'endpoint');
cy.task('esArchiverUnload', { archiveName: 'endpoint' });
});

it('Should create a Rule exception item from alert actions overflow menu and auto populate the conditions using alert Highlighted fields', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Close matching Alerts ', { tags: ['@ess', '@serverless', '@skipInServe
const ITEM_NAME = 'Sample Exception Item';

beforeEach(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
deleteAlertsAndRules();
cy.task('esArchiverLoad', { archiveName: 'exceptions' });

Expand All @@ -50,7 +50,7 @@ describe('Close matching Alerts ', { tags: ['@ess', '@serverless', '@skipInServe
waitForAlertsToPopulate();
});
after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});

// TODO: https://github.com/elastic/kibana/issues/161539
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe.skip('Exceptions flyout', { tags: ['@ess', '@serverless', '@skipInServe
});

after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});

it('Validates empty entry values correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Exceptions match_any', { tags: ['@ess', '@serverless'] }, () => {
});

after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});

it('Creates exception item', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe(
});

after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});

const exceptionName = 'My item name';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe.skip('Use Value list in exception entry', { tags: ['@ess', '@serverless
});

after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});
beforeEach(() => {
login();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Add endpoint exception from rule details', { tags: ['@ess', '@serverle
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe(
});

after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});

beforeEach(() => {
Expand Down Expand Up @@ -263,7 +263,7 @@ describe(
});

afterEach(() => {
cy.task('esArchiverUnload', 'exceptions_2');
cy.task('esArchiverUnload', { archiveName: 'exceptions_2' });
});

it('Cannot create an item to add to rule but not shared list as rule has no lists attached', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe(
});

after(() => {
cy.task('esArchiverUnload', 'exceptions');
cy.task('esArchiverUnload', { archiveName: 'exceptions' });
});

beforeEach(() => {
Expand All @@ -74,7 +74,7 @@ describe(
});

afterEach(() => {
cy.task('esArchiverUnload', 'exceptions_2');
cy.task('esArchiverUnload', { archiveName: 'exceptions_2' });
});

it('Creates an exception item and close all matching alerts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe.skip('CTI Link Panel', { tags: ['@ess', '@serverless', '@skipInServerle
});

after(() => {
cy.task('esArchiverUnload', 'threat_indicator');
cy.task('esArchiverUnload', { archiveName: 'threat_indicator' });
});

it('renders disabled dashboard module as expected when there are no events in the selected time period', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('EQL rules', { tags: ['@ess', '@serverless'] }, () => {
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

it('Creates and enables a new EQL rule with a sequence', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'auditbeat_multiple');
cy.task('esArchiverUnload', { archiveName: 'auditbeat_multiple' });
});

describe('legacy risk score', () => {
Expand Down Expand Up @@ -101,8 +101,8 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_hosts_no_data');
cy.task('esArchiverUnload', 'risk_users_no_data');
cy.task('esArchiverUnload', { archiveName: 'risk_hosts_no_data' });
cy.task('esArchiverUnload', { archiveName: 'risk_users_no_data' });
});

it('shows no data detected prompt for host risk score module', () => {
Expand All @@ -126,8 +126,8 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_hosts_legacy_data');
cy.task('esArchiverUnload', 'risk_users_legacy_data');
cy.task('esArchiverUnload', { archiveName: 'risk_hosts_legacy_data' });
cy.task('esArchiverUnload', { archiveName: 'risk_users_legacy_data' });
});

it('shows enable host risk button', () => {
Expand All @@ -150,7 +150,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_hosts');
cy.task('esArchiverUnload', { archiveName: 'risk_hosts' });
});

it('renders donut chart', () => {
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_users');
cy.task('esArchiverUnload', { archiveName: 'risk_users' });
});

it('renders donut chart', () => {
Expand Down Expand Up @@ -338,7 +338,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_scores_new_no_data');
cy.task('esArchiverUnload', { archiveName: 'risk_scores_new_no_data' });
});

it('shows no data detected prompt for host and user risk scores', () => {
Expand All @@ -353,7 +353,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_scores_new');
cy.task('esArchiverUnload', { archiveName: 'risk_scores_new' });
});

it('renders donut chart', () => {
Expand Down Expand Up @@ -446,7 +446,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'risk_scores_new');
cy.task('esArchiverUnload', { archiveName: 'risk_scores_new' });
});

it('renders donut chart', () => {
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>
});

after(() => {
cy.task('esArchiverUnload', 'network');
cy.task('esArchiverUnload', { archiveName: 'network' });
});

it('should enable a job and renders the table with pagination', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('Upgrade risk scores', { tags: ['@ess', '@serverless'] }, () => {
afterEach(() => {
deleteRiskScore({ riskScoreEntity: RiskScoreEntity.host, spaceId });
deleteRiskScore({ riskScoreEntity: RiskScoreEntity.user, spaceId });
cy.task('esArchiverUnload', 'risk_hosts');
cy.task('esArchiverUnload', 'risk_users');
cy.task('esArchiverUnload', { archiveName: 'risk_hosts' });
cy.task('esArchiverUnload', { archiveName: 'risk_users' });
});

it('shows upgrade panel', () => {
Expand All @@ -77,8 +77,8 @@ describe('Upgrade risk scores', { tags: ['@ess', '@serverless'] }, () => {
});

afterEach(() => {
cy.task('esArchiverUnload', 'risk_hosts');
cy.task('esArchiverUnload', 'risk_users');
cy.task('esArchiverUnload', { archiveName: 'risk_hosts' });
cy.task('esArchiverUnload', { archiveName: 'risk_users' });
deleteRiskScore({ riskScoreEntity: RiskScoreEntity.host, spaceId });
deleteRiskScore({ riskScoreEntity: RiskScoreEntity.user, spaceId });
deleteRiskEngineConfiguration();
Expand Down
Loading

0 comments on commit f1e093e

Please sign in to comment.