Skip to content

Commit

Permalink
fixes cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Dec 4, 2020
1 parent c0db334 commit a7a7771
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 44 deletions.
21 changes: 21 additions & 0 deletions x-pack/plugins/security_solution/cypress/helpers/rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Mitre } from '../objects/rule';

export const formatMitreAttackDescription = (mitre: Mitre[]) => {
return mitre
.map(
(threat) =>
threat.tactic +
threat.techniques
.map((technique) => {
return technique.name + technique.subtechniques.join('');
})
.join('')
)
.join('');
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { formatMitreAttackDescription } from '../helpers/rules';
import { newRule, existingRule, indexPatterns, editedRule } from '../objects/rule';
import {
ALERT_RULE_METHOD,
Expand Down Expand Up @@ -105,11 +106,7 @@ import { DETECTIONS_URL } from '../urls/navigation';
const expectedUrls = newRule.referenceUrls.join('');
const expectedFalsePositives = newRule.falsePositivesExamples.join('');
const expectedTags = newRule.tags.join('');
const expectedMitre = newRule.mitre
.map(function (mitre) {
return mitre.tactic + mitre.techniques.join('');
})
.join('');
const expectedMitre = formatMitreAttackDescription(newRule.mitre);
const expectedNumberOfRules = 1;
const expectedEditedtags = editedRule.tags.join('');
const expectedEditedIndexPatterns =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { formatMitreAttackDescription } from '../helpers/rules';
import { eqlRule, eqlSequenceRule, indexPatterns } from '../objects/rule';

import {
Expand Down Expand Up @@ -79,11 +80,7 @@ import { DETECTIONS_URL } from '../urls/navigation';
const expectedUrls = eqlRule.referenceUrls.join('');
const expectedFalsePositives = eqlRule.falsePositivesExamples.join('');
const expectedTags = eqlRule.tags.join('');
const expectedMitre = eqlRule.mitre
.map(function (mitre) {
return mitre.tactic + mitre.techniques.join('');
})
.join('');
const expectedMitre = formatMitreAttackDescription(eqlRule.mitre);
const expectedNumberOfRules = 1;
const expectedNumberOfAlerts = 7;
const expectedNumberOfSequenceAlerts = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { formatMitreAttackDescription } from '../helpers/rules';
import { newThreatIndicatorRule } from '../objects/rule';

import {
Expand Down Expand Up @@ -83,11 +84,7 @@ import { DETECTIONS_URL } from '../urls/navigation';
const expectedUrls = newThreatIndicatorRule.referenceUrls.join('');
const expectedFalsePositives = newThreatIndicatorRule.falsePositivesExamples.join('');
const expectedTags = newThreatIndicatorRule.tags.join('');
const expectedMitre = newThreatIndicatorRule.mitre
.map(function (mitre) {
return mitre.tactic + mitre.techniques.join('');
})
.join('');
const expectedMitre = formatMitreAttackDescription(newThreatIndicatorRule.mitre);
const expectedNumberOfRules = 1;
const expectedNumberOfAlerts = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { formatMitreAttackDescription } from '../helpers/rules';
import { machineLearningRule, totalNumberOfPrebuiltRulesInEsArchive } from '../objects/rule';

import {
Expand Down Expand Up @@ -67,17 +68,7 @@ import { DETECTIONS_URL } from '../urls/navigation';
const expectedUrls = machineLearningRule.referenceUrls.join('');
const expectedFalsePositives = machineLearningRule.falsePositivesExamples.join('');
const expectedTags = machineLearningRule.tags.join('');
const expectedMitre = machineLearningRule.mitre
.map(
(mitre) =>
mitre.tactic +
mitre.techniques
.map((technique) => {
return technique.name + technique.subtechniques.join('');
})
.join('')
)
.join('');
const expectedMitre = formatMitreAttackDescription(machineLearningRule.mitre);
const expectedNumberOfRules = totalNumberOfPrebuiltRulesInEsArchive + 1;

describe('Detection rules, machine learning', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { formatMitreAttackDescription } from '../helpers/rules';
import { indexPatterns, newOverrideRule, severitiesOverride } from '../objects/rule';
import {
NUMBER_OF_ALERTS,
Expand Down Expand Up @@ -83,11 +84,7 @@ import { DETECTIONS_URL } from '../urls/navigation';
const expectedUrls = newOverrideRule.referenceUrls.join('');
const expectedFalsePositives = newOverrideRule.falsePositivesExamples.join('');
const expectedTags = newOverrideRule.tags.join('');
const expectedMitre = newOverrideRule.mitre
.map(function (mitre) {
return mitre.tactic + mitre.techniques.join('');
})
.join('');
const expectedMitre = formatMitreAttackDescription(newOverrideRule.mitre);

describe('Detection rules, override', () => {
before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { formatMitreAttackDescription } from '../helpers/rules';
import { indexPatterns, newThresholdRule } from '../objects/rule';
import {
ALERT_RULE_METHOD,
Expand Down Expand Up @@ -80,11 +81,7 @@ import { DETECTIONS_URL } from '../urls/navigation';
const expectedUrls = newThresholdRule.referenceUrls.join('');
const expectedFalsePositives = newThresholdRule.falsePositivesExamples.join('');
const expectedTags = newThresholdRule.tags.join('');
const expectedMitre = newThresholdRule.mitre
.map(function (mitre) {
return mitre.tactic + mitre.techniques.join('');
})
.join('');
const expectedMitre = formatMitreAttackDescription(newThresholdRule.mitre);

describe('Detection rules, threshold', () => {
before(() => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/cypress/objects/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface MitreAttackTechnique {
subtechniques: string[];
}

interface Mitre {
export interface Mitre {
tactic: string;
techniques: MitreAttackTechnique[];
}
Expand Down
22 changes: 15 additions & 7 deletions x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,30 @@ export const fillAboutRule = (
cy.get(ADD_FALSE_POSITIVE_BTN).click({ force: true });
});

rule.mitre.forEach((mitre, index) => {
cy.get(MITRE_ATTACK_TACTIC_DROPDOWN).eq(index).click({ force: true });
let techniqueIndex = 0;
let subtechniqueInputIndex = 0;
rule.mitre.forEach((mitre, tacticIndex) => {
cy.get(MITRE_ATTACK_TACTIC_DROPDOWN).eq(tacticIndex).click({ force: true });
cy.contains(MITRE_TACTIC, mitre.tactic).click();
cy.get(MITRE_ATTACK_ADD_TECHNIQUE_BUTTON).eq(tacticIndex).click({ force: true });

mitre.techniques.forEach((technique) => {
cy.get(MITRE_ATTACK_TECHNIQUE_DROPDOWN).eq(index).click({ force: true });
cy.get(MITRE_ATTACK_TECHNIQUE_DROPDOWN).eq(techniqueIndex).click({ force: true });
cy.contains(MITRE_TACTIC, technique.name).click();

technique.subtechniques.forEach((subtechnique) => {
cy.get(MITRE_ATTACK_SUBTECHNIQUE_DROPDOWN).eq(index).click({ force: true });
cy.get(MITRE_ATTACK_ADD_SUBTECHNIQUE_BUTTON).eq(techniqueIndex).click({ force: true });
cy.get(MITRE_ATTACK_SUBTECHNIQUE_DROPDOWN)
.eq(subtechniqueInputIndex)
.click({ force: true });
cy.contains(MITRE_TACTIC, subtechnique).click();

cy.get(MITRE_ATTACK_ADD_SUBTECHNIQUE_BUTTON).click({ force: true });
subtechniqueInputIndex++;
});

cy.get(MITRE_ATTACK_ADD_TECHNIQUE_BUTTON).click({ force: true });
if (techniqueIndex < mitre.techniques.length - 1) {
cy.get(MITRE_ATTACK_ADD_TECHNIQUE_BUTTON).eq(tacticIndex).click({ force: true });
}
techniqueIndex++;
});

cy.get(MITRE_ATTACK_ADD_TACTIC_BUTTON).click({ force: true });
Expand Down

0 comments on commit a7a7771

Please sign in to comment.