From c4da722455fb61d3019769872ab06941899106d2 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 4 May 2020 19:25:11 +0200 Subject: [PATCH 1/5] removes prebuilt rules number dependency --- .../signal_detection_rules_custom.spec.ts | 4 ++-- .../integration/signal_detection_rules_ml.spec.ts | 4 ++-- .../signal_detection_rules_prebuilt.spec.ts | 14 ++++++-------- x-pack/plugins/siem/cypress/objects/rule.ts | 7 ++++++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts index b7e42f7e46a706..29a9d3283cf593 100644 --- a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts +++ b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { newRule, totalNumberOfPrebuiltRules } from '../objects/rule'; +import { newRule, totalLoadedRules } from '../objects/rule'; import { ABOUT_FALSE_POSITIVES, @@ -91,7 +91,7 @@ describe('Signal detection rules, custom', () => { changeToThreeHundredRowsPerPage(); waitForRulesToBeLoaded(); - const expectedNumberOfRules = totalNumberOfPrebuiltRules + 1; + const expectedNumberOfRules = totalLoadedRules + 1; cy.get(RULES_TABLE).then($table => { cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules); }); diff --git a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts index db56193c6b51c7..3dc83ebd301b15 100644 --- a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts +++ b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { machineLearningRule, totalNumberOfPrebuiltRules } from '../objects/rule'; +import { machineLearningRule, totalLoadedRules } from '../objects/rule'; import { ABOUT_FALSE_POSITIVES, @@ -88,7 +88,7 @@ describe('Signal detection rules, machine learning', () => { changeToThreeHundredRowsPerPage(); waitForRulesToBeLoaded(); - const expectedNumberOfRules = totalNumberOfPrebuiltRules + 1; + const expectedNumberOfRules = totalLoadedRules + 1; cy.get(RULES_TABLE).then($table => { cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules); }); diff --git a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts index 74a11fb455ac0f..39e95728cc6474 100644 --- a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts +++ b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts @@ -28,12 +28,7 @@ import { waitForSignalsIndexToBeCreated, waitForSignalsPanelToBeLoaded, } from '../tasks/detections'; -import { - esArchiverLoad, - esArchiverLoadEmptyKibana, - esArchiverUnloadEmptyKibana, - esArchiverUnload, -} from '../tasks/es_archiver'; +import { esArchiverLoadEmptyKibana, esArchiverUnloadEmptyKibana } from '../tasks/es_archiver'; import { loginAndWaitForPageWithoutDateRange } from '../tasks/login'; import { DETECTIONS } from '../urls/navigation'; @@ -76,15 +71,18 @@ describe('Signal detection rules, prebuilt rules', () => { describe('Deleting prebuilt rules', () => { beforeEach(() => { - esArchiverLoad('prebuilt_rules_loaded'); + esArchiverLoadEmptyKibana(); loginAndWaitForPageWithoutDateRange(DETECTIONS); waitForSignalsPanelToBeLoaded(); waitForSignalsIndexToBeCreated(); goToManageSignalDetectionRules(); + waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded(); + loadPrebuiltDetectionRules(); + waitForPrebuiltDetectionRulesToBeLoaded(); }); afterEach(() => { - esArchiverUnload('prebuilt_rules_loaded'); + esArchiverUnloadEmptyKibana(); }); it('Does not allow to delete one rule when more than one is selected', () => { diff --git a/x-pack/plugins/siem/cypress/objects/rule.ts b/x-pack/plugins/siem/cypress/objects/rule.ts index 4e0189ea597da1..c12976912aa847 100644 --- a/x-pack/plugins/siem/cypress/objects/rule.ts +++ b/x-pack/plugins/siem/cypress/objects/rule.ts @@ -4,7 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -export const totalNumberOfPrebuiltRules = 127; +// eslint-disable-next-line +import { rawRules } from '../../server/lib/detection_engine/rules/prepackaged_rules/index'; + +export const totalNumberOfPrebuiltRules = rawRules.length; + +export const totalLoadedRules = 127; interface Mitre { tactic: string; From 086a52530fc7d5fc4da40540e7ed39af8f74f7da Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 4 May 2020 21:06:36 +0200 Subject: [PATCH 2/5] fixes type check issue --- x-pack/plugins/siem/cypress/tsconfig.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/siem/cypress/tsconfig.json b/x-pack/plugins/siem/cypress/tsconfig.json index b9c1d950eaaef6..929a3fb39babb0 100644 --- a/x-pack/plugins/siem/cypress/tsconfig.json +++ b/x-pack/plugins/siem/cypress/tsconfig.json @@ -8,6 +8,7 @@ "types": [ "cypress", "node" - ] - } -} \ No newline at end of file + ], + "resolveJsonModule": true, + }, +} From 082ebe85da6460614fdb579c108a339dabaf9d8e Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 4 May 2020 21:08:06 +0200 Subject: [PATCH 3/5] improves eslint comment --- x-pack/plugins/siem/cypress/objects/rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/siem/cypress/objects/rule.ts b/x-pack/plugins/siem/cypress/objects/rule.ts index c12976912aa847..7f0b5fed1986f4 100644 --- a/x-pack/plugins/siem/cypress/objects/rule.ts +++ b/x-pack/plugins/siem/cypress/objects/rule.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -// eslint-disable-next-line +// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { rawRules } from '../../server/lib/detection_engine/rules/prepackaged_rules/index'; export const totalNumberOfPrebuiltRules = rawRules.length; From 3b8ad1c3fdd54801604295fda1b2abe18ba89328 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 4 May 2020 21:11:52 +0200 Subject: [PATCH 4/5] improves constant naming --- .../cypress/integration/signal_detection_rules_custom.spec.ts | 4 ++-- .../cypress/integration/signal_detection_rules_ml.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts index 29a9d3283cf593..24325676f0cca0 100644 --- a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts +++ b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_custom.spec.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { newRule, totalLoadedRules } from '../objects/rule'; +import { newRule, totalNumberOfPrebuiltRulesInEsArchive } from '../objects/rule'; import { ABOUT_FALSE_POSITIVES, @@ -91,7 +91,7 @@ describe('Signal detection rules, custom', () => { changeToThreeHundredRowsPerPage(); waitForRulesToBeLoaded(); - const expectedNumberOfRules = totalLoadedRules + 1; + const expectedNumberOfRules = totalNumberOfPrebuiltRulesInEsArchive + 1; cy.get(RULES_TABLE).then($table => { cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules); }); diff --git a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts index 3dc83ebd301b15..ad56c905aa4fc5 100644 --- a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts +++ b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_ml.spec.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { machineLearningRule, totalLoadedRules } from '../objects/rule'; +import { machineLearningRule, totalNumberOfPrebuiltRulesInEsArchive } from '../objects/rule'; import { ABOUT_FALSE_POSITIVES, @@ -88,7 +88,7 @@ describe('Signal detection rules, machine learning', () => { changeToThreeHundredRowsPerPage(); waitForRulesToBeLoaded(); - const expectedNumberOfRules = totalLoadedRules + 1; + const expectedNumberOfRules = totalNumberOfPrebuiltRulesInEsArchive + 1; cy.get(RULES_TABLE).then($table => { cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules); }); From 32cf919e52010039a46b50fccabf976e04ef28c8 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Tue, 5 May 2020 10:35:38 +0200 Subject: [PATCH 5/5] fixes failures --- .../signal_detection_rules_prebuilt.spec.ts | 14 ++++++++++++++ x-pack/plugins/siem/cypress/objects/rule.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts index 39e95728cc6474..866302e81e1a02 100644 --- a/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts +++ b/x-pack/plugins/siem/cypress/integration/signal_detection_rules_prebuilt.spec.ts @@ -71,6 +71,9 @@ describe('Signal detection rules, prebuilt rules', () => { describe('Deleting prebuilt rules', () => { beforeEach(() => { + const expectedNumberOfRules = totalNumberOfPrebuiltRules; + const expectedElasticRulesBtnText = `Elastic rules (${expectedNumberOfRules})`; + esArchiverLoadEmptyKibana(); loginAndWaitForPageWithoutDateRange(DETECTIONS); waitForSignalsPanelToBeLoaded(); @@ -79,6 +82,17 @@ describe('Deleting prebuilt rules', () => { waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded(); loadPrebuiltDetectionRules(); waitForPrebuiltDetectionRulesToBeLoaded(); + + cy.get(ELASTIC_RULES_BTN) + .invoke('text') + .should('eql', expectedElasticRulesBtnText); + + changeToThreeHundredRowsPerPage(); + waitForRulesToBeLoaded(); + + cy.get(RULES_TABLE).then($table => { + cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules); + }); }); afterEach(() => { diff --git a/x-pack/plugins/siem/cypress/objects/rule.ts b/x-pack/plugins/siem/cypress/objects/rule.ts index 7f0b5fed1986f4..7ce8aa69f33390 100644 --- a/x-pack/plugins/siem/cypress/objects/rule.ts +++ b/x-pack/plugins/siem/cypress/objects/rule.ts @@ -9,7 +9,7 @@ import { rawRules } from '../../server/lib/detection_engine/rules/prepackaged_ru export const totalNumberOfPrebuiltRules = rawRules.length; -export const totalLoadedRules = 127; +export const totalNumberOfPrebuiltRulesInEsArchive = 127; interface Mitre { tactic: string;