Skip to content

Commit f98eb0d

Browse files
maximpnbanderror
authored andcommitted
[Security Solution] Install mock prebuilt rules package in Cypress to reduce flakiness (#229689)
**Resolves: #182441 **Resolves: #182442 **Resolves: #228942 **Relates to: #227689 ## Summary This PR installs mock prebuilt rules package for e2e Cypress test to reduce flakniess caused by accessing to the real EPR. It's similar to the mock package installation in integration tests [PR](#227689). **Flaky test runner** - ESS: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/9120 - Serverless: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/9121 (cherry picked from commit 980add1)
1 parent c2d39aa commit f98eb0d

37 files changed

Lines changed: 552 additions & 386 deletions

x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/authorization/all_rules_read_only.cy.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import { ROLES } from '@kbn/security-solution-plugin/common/test';
99

10-
import { getNewRule } from '../../../../objects/rule';
10+
import { installMockPrebuiltRulesPackage } from '../../../../tasks/api_calls/prebuilt_rules';
11+
import { getCustomQueryRuleParams, getNewRule } from '../../../../objects/rule';
1112
import {
1213
COLLAPSED_ACTION_BTN,
1314
RULE_CHECKBOX,
@@ -28,12 +29,16 @@ import { deleteAlertsAndRules } from '../../../../tasks/api_calls/common';
2829
// TODO: https://github.com/elastic/kibana/issues/164451 We should find a way to make this spec work in Serverless
2930
// TODO: https://github.com/elastic/kibana/issues/161540
3031
describe('All rules - read only', { tags: ['@ess', '@serverless', '@skipInServerless'] }, () => {
32+
before(() => {
33+
installMockPrebuiltRulesPackage();
34+
});
35+
3136
beforeEach(() => {
3237
deleteAlertsAndRules();
33-
createRule(getNewRule({ rule_id: '1', enabled: false }));
38+
createRule(getCustomQueryRuleParams({ rule_id: '1', enabled: false }));
3439
login(ROLES.t1_analyst);
3540
visitRulesManagementTable();
36-
cy.get(RULE_NAME).should('have.text', getNewRule().name);
41+
cy.get(RULE_NAME).should('have.text', getCustomQueryRuleParams().name);
3742
});
3843

3944
it('Does not display select boxes for rules', () => {

x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/coverage_overview/coverage_overview.cy.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import { createRule } from '../../../../tasks/api_calls/rules';
2222
import { visit } from '../../../../tasks/navigation';
2323
import { RULES_COVERAGE_OVERVIEW_URL } from '../../../../urls/rules_management';
2424
import { createRuleAssetSavedObject } from '../../../../helpers/rules';
25-
import { getNewRule } from '../../../../objects/rule';
25+
import { getCustomQueryRuleParams, getNewRule } from '../../../../objects/rule';
2626
import {
2727
createAndInstallMockedPrebuiltRules,
28+
installMockPrebuiltRulesPackage,
2829
preventPrebuiltRulesPackageInstallation,
2930
} from '../../../../tasks/api_calls/prebuilt_rules';
3031
import {
@@ -191,6 +192,10 @@ const prebuiltRules = [
191192

192193
// https://github.com/elastic/kibana/issues/179052
193194
describe('Coverage overview', { tags: ['@ess', '@serverless', '@skipInServerless'] }, () => {
195+
before(() => {
196+
installMockPrebuiltRulesPackage();
197+
});
198+
194199
describe('base cases', () => {
195200
beforeEach(() => {
196201
login();
@@ -199,15 +204,15 @@ describe('Coverage overview', { tags: ['@ess', '@serverless', '@skipInServerless
199204
preventPrebuiltRulesPackageInstallation();
200205
createAndInstallMockedPrebuiltRules(prebuiltRules);
201206
createRule(
202-
getNewRule({
207+
getCustomQueryRuleParams({
203208
rule_id: 'enabled_custom_rule',
204209
enabled: true,
205210
name: 'Enabled custom rule',
206211
threat: [MockEnabledCustomRuleThreat],
207212
})
208213
);
209214
createRule(
210-
getNewRule({
215+
getCustomQueryRuleParams({
211216
rule_id: 'disabled_custom_rule',
212217
name: 'Disabled custom rule',
213218
enabled: false,

x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/maintenance_windows/maintenance_window_callout.cy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { INTERNAL_ALERTING_API_MAINTENANCE_WINDOW_PATH } from '@kbn/alerting-plugin/common';
99
import type { MaintenanceWindowCreateBody } from '@kbn/alerting-plugin/common';
1010
import type { AsApiContract } from '@kbn/alerting-plugin/server/routes/lib';
11+
import { installMockPrebuiltRulesPackage } from '../../../../tasks/api_calls/prebuilt_rules';
1112
import { login } from '../../../../tasks/login';
1213
import { visit } from '../../../../tasks/navigation';
1314
import { RULES_MANAGEMENT_URL } from '../../../../urls/rules_management';
@@ -17,6 +18,10 @@ describe(
1718
'Maintenance window callout on Rule Management page',
1819
{ tags: ['@ess', '@serverless', '@skipInServerless'] },
1920
() => {
21+
before(() => {
22+
installMockPrebuiltRulesPackage();
23+
});
24+
2025
let maintenanceWindowId = '';
2126

2227
beforeEach(() => {

x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/prebuilt_rules/customization/revert_prebuilt_rule.cy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from '../../../../../tasks/api_calls/common';
3030
import {
3131
createAndInstallMockedPrebuiltRules,
32+
installMockPrebuiltRulesPackage,
3233
preventPrebuiltRulesPackageInstallation,
3334
} from '../../../../../tasks/api_calls/prebuilt_rules';
3435
import { createRule, patchRule } from '../../../../../tasks/api_calls/rules';
@@ -44,6 +45,10 @@ describe(
4445

4546
() => {
4647
describe('Reverting prebuilt rules', () => {
48+
before(() => {
49+
installMockPrebuiltRulesPackage();
50+
});
51+
4752
const PREBUILT_RULE = createRuleAssetSavedObject({
4853
name: 'Non-customized prebuilt rule',
4954
rule_id: 'rule_1',
@@ -52,12 +57,13 @@ describe(
5257
});
5358

5459
beforeEach(() => {
55-
login();
5660
deleteAlertsAndRules();
5761
deletePrebuiltRulesAssets();
5862
preventPrebuiltRulesPackageInstallation();
5963
/* Create a new rule and install it */
6064
createAndInstallMockedPrebuiltRules([PREBUILT_RULE]);
65+
66+
login();
6167
visitRulesManagementTable();
6268
});
6369

0 commit comments

Comments
 (0)