Skip to content

Commit

Permalink
[SIEM] Removes prebuilt rules number dependency (#65128)
Browse files Browse the repository at this point in the history
* removes prebuilt rules number dependency

* fixes type check issue

* improves eslint comment

* improves constant naming

* fixes failures
  • Loading branch information
MadameSheema committed May 5, 2020
1 parent f2d1095 commit 33b3c7b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, totalNumberOfPrebuiltRulesInEsArchive } from '../objects/rule';

import {
ABOUT_FALSE_POSITIVES,
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Signal detection rules, custom', () => {
changeToThreeHundredRowsPerPage();
waitForRulesToBeLoaded();

const expectedNumberOfRules = totalNumberOfPrebuiltRules + 1;
const expectedNumberOfRules = totalNumberOfPrebuiltRulesInEsArchive + 1;
cy.get(RULES_TABLE).then($table => {
cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, totalNumberOfPrebuiltRulesInEsArchive } from '../objects/rule';

import {
ABOUT_FALSE_POSITIVES,
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Signal detection rules, machine learning', () => {
changeToThreeHundredRowsPerPage();
waitForRulesToBeLoaded();

const expectedNumberOfRules = totalNumberOfPrebuiltRules + 1;
const expectedNumberOfRules = totalNumberOfPrebuiltRulesInEsArchive + 1;
cy.get(RULES_TABLE).then($table => {
cy.wrap($table.find(RULES_ROW).length).should('eql', expectedNumberOfRules);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,15 +71,32 @@ describe('Signal detection rules, prebuilt rules', () => {

describe('Deleting prebuilt rules', () => {
beforeEach(() => {
esArchiverLoad('prebuilt_rules_loaded');
const expectedNumberOfRules = totalNumberOfPrebuiltRules;
const expectedElasticRulesBtnText = `Elastic rules (${expectedNumberOfRules})`;

esArchiverLoadEmptyKibana();
loginAndWaitForPageWithoutDateRange(DETECTIONS);
waitForSignalsPanelToBeLoaded();
waitForSignalsIndexToBeCreated();
goToManageSignalDetectionRules();
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(() => {
esArchiverUnload('prebuilt_rules_loaded');
esArchiverUnloadEmptyKibana();
});

it('Does not allow to delete one rule when more than one is selected', () => {
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/siem/cypress/objects/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 @kbn/eslint/no-restricted-paths
import { rawRules } from '../../server/lib/detection_engine/rules/prepackaged_rules/index';

export const totalNumberOfPrebuiltRules = rawRules.length;

export const totalNumberOfPrebuiltRulesInEsArchive = 127;

interface Mitre {
tactic: string;
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/siem/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"types": [
"cypress",
"node"
]
}
}
],
"resolveJsonModule": true,
},
}

0 comments on commit 33b3c7b

Please sign in to comment.