Skip to content

Commit

Permalink
minimizes the uses of es_archiver
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema committed Dec 6, 2020
1 parent 5354008 commit 2eccf8a
Show file tree
Hide file tree
Showing 25 changed files with 342 additions and 8,934 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
goToOpenedAlerts,
waitForAlertsIndexToBeCreated,
} from '../tasks/alerts';
import { createCustomRule, deleteCustomRule, removeSignalsIndex } from '../tasks/api_calls';
import { createCustomRule, deleteCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { goToRuleDetails } from '../tasks/alerts_detection_rules';
import { waitForAlertsToPopulate } from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForRulesToBeLoaded,
} from '../tasks/alerts_detection_rules';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';
import {
createAndActivateRule,
fillAboutRule,
Expand Down Expand Up @@ -115,14 +116,16 @@ const expectedEditedtags = editedRule.tags.join('');
const expectedEditedIndexPatterns =
editedRule.index && editedRule.index.length ? editedRule.index : indexPatterns;

describe('Custom detection rules creation', () => {
before(() => {
esArchiverLoad('timeline');
describe('Custom detection rules creation', async () => {
before(async () => {
const createdTimeline = await createTimeline(newRule.timeline);
// eslint-disable-next-line require-atomic-updates
newRule.timeline.id = createdTimeline[0];
});

after(() => {
deleteTimeline(newRule.timeline.id!);
deleteRule();
esArchiverUnload('timeline');
});

it('Creates and activates a new rule', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForRulesToBeLoaded,
} from '../tasks/alerts_detection_rules';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';
import {
createAndActivateRule,
fillAboutRuleAndContinue,
Expand All @@ -71,7 +72,6 @@ import {
waitForAlertsToPopulate,
waitForTheRuleToBeExecuted,
} from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';
Expand All @@ -89,13 +89,15 @@ const expectedNumberOfAlerts = 7;
const expectedNumberOfSequenceAlerts = 1;

describe('Detection rules, EQL', () => {
beforeEach(() => {
esArchiverLoad('timeline');
beforeEach(async () => {
const createdTimeline = await createTimeline(eqlRule.timeline);
// eslint-disable-next-line require-atomic-updates
eqlRule.timeline.id = createdTimeline[0];
});

afterEach(() => {
deleteTimeline(eqlRule.timeline.id!);
deleteRule();
esArchiverUnload('timeline');
});

it('Creates and activates a new EQL rule', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { expectedExportedRule, newRule } from '../objects/rule';
import {
goToManageAlertsDetectionRules,
waitForAlertsIndexToBeCreated,
waitForAlertsPanelToBeLoaded,
} from '../tasks/alerts';
import { exportFirstRule } from '../tasks/alerts_detection_rules';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { createCustomRule, deleteCustomRule } from '../tasks/api_calls/rules';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';

const EXPECTED_EXPORTED_RULE_FILE_PATH = 'cypress/test_files/expected_rules_export.ndjson';
let rule = '';

describe('Export rules', () => {
before(() => {
esArchiverLoad('export_rule');
before(async () => {
cy.server();
cy.route(
'POST',
'**api/detection_engine/rules/_export?exclude_export_details=false&file_name=rules_export.ndjson*'
).as('export');
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
rule = await createCustomRule(newRule);
});

after(() => {
esArchiverUnload('export_rule');
deleteCustomRule();
});

it('Exports a custom rule', () => {
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
goToManageAlertsDetectionRules();
exportFirstRule();
const jsonRule = JSON.parse(JSON.stringify(rule));
cy.wait('@export').then((xhr) => {
cy.readFile(EXPECTED_EXPORTED_RULE_FILE_PATH).then(($expectedExportedJson) => {
cy.wrap(xhr.responseBody).should('eql', $expectedExportedJson);
});
cy.wrap(xhr.responseBody).should('eql', expectedExportedRule(jsonRule));
});
});
});
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, totalNumberOfPrebuiltRulesInEsArchive } from '../objects/rule';
import { machineLearningRule } from '../objects/rule';

import {
CUSTOM_RULES_BTN,
Expand Down Expand Up @@ -59,7 +59,6 @@ import {
fillScheduleRuleAndContinue,
selectMachineLearningRuleType,
} from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';
Expand All @@ -72,16 +71,11 @@ const expectedMitre = machineLearningRule.mitre
return mitre.tactic + mitre.techniques.join('');
})
.join('');
const expectedNumberOfRules = totalNumberOfPrebuiltRulesInEsArchive + 1;
const expectedNumberOfRules = 1;

describe('Detection rules, machine learning', () => {
before(() => {
esArchiverLoad('prebuilt_rules_loaded');
});

after(() => {
deleteRule();
esArchiverUnload('prebuilt_rules_loaded');
});

it('Creates and activates a new ml rule', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { indexPatterns, newOverrideRule, severitiesOverride } from '../objects/rule';

import {
NUMBER_OF_ALERTS,
ALERT_RULE_NAME,
Expand Down Expand Up @@ -61,12 +62,14 @@ import {
} from '../tasks/alerts';
import {
changeToThreeHundredRowsPerPage,
deleteRule,
filterByCustomRules,
goToCreateNewRule,
goToRuleDetails,
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForRulesToBeLoaded,
} from '../tasks/alerts_detection_rules';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';
import {
createAndActivateRule,
fillAboutRuleWithOverrideAndContinue,
Expand All @@ -75,7 +78,6 @@ import {
waitForAlertsToPopulate,
waitForTheRuleToBeExecuted,
} from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';
Expand All @@ -90,12 +92,15 @@ const expectedMitre = newOverrideRule.mitre
.join('');

describe('Detection rules, override', () => {
before(() => {
esArchiverLoad('timeline');
beforeEach(async () => {
const createdTimeline = await createTimeline(newOverrideRule.timeline);
// eslint-disable-next-line require-atomic-updates
newOverrideRule.timeline.id = createdTimeline[0];
});

after(() => {
esArchiverUnload('timeline');
afterEach(() => {
deleteTimeline(newOverrideRule.timeline.id!);
deleteRule();
});

it('Creates and activates a new custom rule with override option', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { indexPatterns, newThresholdRule } from '../objects/rule';

import {
ALERT_RULE_METHOD,
ALERT_RULE_NAME,
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
waitForLoadElasticPrebuiltDetectionRulesTableToBeLoaded,
waitForRulesToBeLoaded,
} from '../tasks/alerts_detection_rules';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';
import {
createAndActivateRule,
fillAboutRuleAndContinue,
Expand All @@ -72,7 +74,6 @@ import {
waitForAlertsToPopulate,
waitForTheRuleToBeExecuted,
} from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';
Expand All @@ -87,13 +88,15 @@ const expectedMitre = newThresholdRule.mitre
.join('');

describe('Detection rules, threshold', () => {
before(() => {
esArchiverLoad('timeline');
beforeEach(async () => {
const createdTimeline = await createTimeline(newThresholdRule.timeline);
// eslint-disable-next-line require-atomic-updates
newThresholdRule.timeline.id = createdTimeline[0];
});

after(() => {
afterEach(() => {
deleteTimeline(newThresholdRule.timeline.id!);
deleteRule();
esArchiverUnload('timeline');
});

it('Creates and activates a new threshold rule', () => {
Expand Down
15 changes: 10 additions & 5 deletions x-pack/plugins/security_solution/cypress/integration/cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,30 @@ import {
import { TIMELINE_DESCRIPTION, TIMELINE_QUERY, TIMELINE_TITLE } from '../screens/timeline';

import { goToCaseDetails, goToCreateNewCase } from '../tasks/all_cases';
import { openCaseTimeline } from '../tasks/case_details';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';
import { deleteCase, openCaseTimeline } from '../tasks/case_details';
import {
attachTimeline,
backToCases,
createCase,
fillCasesMandatoryfields,
} from '../tasks/create_new_case';
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { closeTimeline } from '../tasks/timeline';

import { CASES_URL } from '../urls/navigation';

describe('Cases', () => {
before(() => {
esArchiverLoad('timeline');
before(async () => {
const createdTimeline = await createTimeline(case1.timeline);
// eslint-disable-next-line require-atomic-updates
case1.timeline.id = createdTimeline[0];
});

after(() => {
esArchiverUnload('timeline');
closeTimeline();
deleteTimeline(case1.timeline.id!);
deleteCase();
});

it('Creates a new case with timeline and opens the timeline', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,45 @@ import {
} from '../tasks/timeline';
import { DESCRIPTION_INPUT, ADD_COMMENT_INPUT } from '../screens/create_new_case';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { caseTimeline, TIMELINE_CASE_ID } from '../objects/case';
import { TIMELINE_CASE_ID } from '../objects/case';
import { caseTimeline, timeline } from '../objects/timeline';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';

describe('attach timeline to case', () => {
beforeEach(() => {
loginAndWaitForTimeline(caseTimeline.id);
});
context('without cases created', () => {
before(() => {
esArchiverLoad('timeline');
before(async () => {
const createdTimeline = await createTimeline(timeline);
// eslint-disable-next-line require-atomic-updates
timeline.id = createdTimeline[0];
});

after(() => {
esArchiverUnload('timeline');
deleteTimeline(timeline.id!);
});

it('attach timeline to a new case', () => {
loginAndWaitForTimeline(timeline.id!);
attachTimelineToNewCase();

cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:%27${caseTimeline.id}%27,isOpen:!t))`
`[${timeline.title}](${origin}/app/security/timelines?timeline=(id:%27${timeline.id}%27,isOpen:!t))`
);
});
});

it('attach timeline to an existing case with no case', () => {
loginAndWaitForTimeline(timeline.id!);
attachTimelineToExistingCase();
addNewCase();

cy.location('origin').then((origin) => {
cy.get(DESCRIPTION_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:%27${caseTimeline.id}%27,isOpen:!t))`
`[${
timeline.title
}](${origin}/app/security/timelines?timeline=(id:%27${timeline.id!}%27,isOpen:!t))`
);
});
});
Expand All @@ -62,13 +67,16 @@ describe('attach timeline to case', () => {
});

it('attach timeline to an existing case', () => {
loginAndWaitForTimeline(caseTimeline.id!);
attachTimelineToExistingCase();
selectCase(TIMELINE_CASE_ID);

cy.location('origin').then((origin) => {
cy.get(ADD_COMMENT_INPUT).should(
'have.text',
`[${caseTimeline.title}](${origin}/app/security/timelines?timeline=(id:%27${caseTimeline.id}%27,isOpen:!t))`
`[${
caseTimeline.title
}](${origin}/app/security/timelines?timeline=(id:%27${caseTimeline.id!}%27,isOpen:!t))`
);
});
});
Expand Down
Loading

0 comments on commit 2eccf8a

Please sign in to comment.