Skip to content

Commit

Permalink
[Security Solution][Detections] -Fixes rule edit flow bug with max_si…
Browse files Browse the repository at this point in the history
…gnals (elastic#92748)

### Summary

Fixes a bug where max_signals was being reverted to it's default value when the rule was edited via the UI.
  • Loading branch information
yctercero authored and kibanamachine committed Mar 2, 2021
1 parent 7c4c797 commit bce8c8a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import {
} from '../../tasks/create_new_rule';
import { saveEditedRule, waitForKibana } from '../../tasks/edit_rule';
import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
import { activatesRule } from '../../tasks/rule_details';

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

Expand Down Expand Up @@ -308,6 +309,21 @@ describe('Custom detection rules deletion and edition', () => {
reload();
});

it('Only modifies rule active status on enable/disable', () => {
activatesRule();

cy.intercept('GET', `/api/detection_engine/rules?id=`).as('fetchRuleDetails');

goToRuleDetails();

cy.wait('@fetchRuleDetails').then(({ response }) => {
cy.wrap(response!.statusCode).should('eql', 200);

cy.wrap(response!.body.max_signals).should('eql', existingRule.maxSignals);
cy.wrap(response!.body.enabled).should('eql', false);
});
});

it('Allows a rule to be edited', () => {
editFirstRule();
waitForKibana();
Expand Down Expand Up @@ -347,8 +363,17 @@ describe('Custom detection rules deletion and edition', () => {
goToAboutStepTab();
cy.get(TAGS_CLEAR_BUTTON).click({ force: true });
fillAboutRule(editedRule);

cy.intercept('GET', '/api/detection_engine/rules?id').as('getRule');

saveEditedRule();

cy.wait('@getRule').then(({ response }) => {
cy.wrap(response!.statusCode).should('eql', 200);
// ensure that editing rule does not modify max_signals
cy.wrap(response!.body.max_signals).should('eql', existingRule.maxSignals);
});

cy.get(RULE_NAME_HEADER).should('have.text', `${editedRule.name}`);
cy.get(ABOUT_RULE_DESCRIPTION).should('have.text', editedRule.description);
cy.get(ABOUT_DETAILS).within(() => {
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/security_solution/cypress/objects/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface CustomRule {
runsEvery: Interval;
lookBack: Interval;
timeline: CompleteTimeline;
maxSignals: number;
}

export interface ThresholdRule extends CustomRule {
Expand Down Expand Up @@ -174,6 +175,7 @@ export const newRule: CustomRule = {
runsEvery,
lookBack,
timeline,
maxSignals: 100,
};

export const existingRule: CustomRule = {
Expand All @@ -192,6 +194,9 @@ export const existingRule: CustomRule = {
runsEvery,
lookBack,
timeline,
// Please do not change, or if you do, needs
// to be any number other than default value
maxSignals: 500,
};

export const newOverrideRule: OverrideRule = {
Expand All @@ -213,6 +218,7 @@ export const newOverrideRule: OverrideRule = {
runsEvery,
lookBack,
timeline,
maxSignals: 100,
};

export const newThresholdRule: ThresholdRule = {
Expand All @@ -232,6 +238,7 @@ export const newThresholdRule: ThresholdRule = {
runsEvery,
lookBack,
timeline,
maxSignals: 100,
};

export const machineLearningRule: MachineLearningRule = {
Expand Down Expand Up @@ -265,6 +272,7 @@ export const eqlRule: CustomRule = {
runsEvery,
lookBack,
timeline,
maxSignals: 100,
};

export const eqlSequenceRule: CustomRule = {
Expand All @@ -285,6 +293,7 @@ export const eqlSequenceRule: CustomRule = {
runsEvery,
lookBack,
timeline,
maxSignals: 100,
};

export const newThreatIndicatorRule: ThreatIndicatorRule = {
Expand All @@ -304,6 +313,7 @@ export const newThreatIndicatorRule: ThreatIndicatorRule = {
indicatorMapping: 'agent.id',
indicatorIndexField: 'agent.threat',
timeline,
maxSignals: 100,
};

export const severitiesOverride = ['Low', 'Medium', 'High', 'Critical'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const createCustomRuleActivated = (rule: CustomRule, ruleId = '1') =>
language: 'kuery',
enabled: true,
tags: ['rule1'],
max_signals: 500,
},
headers: { 'kbn-xsrf': 'cypress-creds' },
failOnStatusCode: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export const activatesRule = () => {
});
};

export const deactivatesRule = () => {
cy.get(RULE_SWITCH).should('be.visible');
cy.get(RULE_SWITCH).click();
};

export const addsException = (exception: Exception) => {
cy.get(LOADING_SPINNER).should('exist');
cy.get(LOADING_SPINNER).should('not.exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const EditRulePageComponent: FC = () => {
rule
),
...(ruleId ? { id: ruleId } : {}),
...(rule != null ? { max_signals: rule.max_signals } : {}),
});
}
}, [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Query With Max Signals",
"description": "Simplest query with max signals set to something other than default",
"risk_score": 1,
"severity": "high",
"type": "query",
"query": "user.name: root or user.name: admin",
"max_signals": 500
}

0 comments on commit bce8c8a

Please sign in to comment.