Skip to content

Commit

Permalink
[Security solution][Detections] fixes incorrect counter for exported …
Browse files Browse the repository at this point in the history
…rules with exceptions (elastic#138598)

## Summary

- addresses elastic#138354
- adds e2e test


### Checklist

Delete any items that are not applicable to this PR.


- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
  • Loading branch information
vitaliidm authored Aug 15, 2022
1 parent 167bb8e commit c0363b0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ import {
bulkExportRules,
selectAllRules,
} from '../../tasks/alerts_detection_rules';
import { createExceptionList, deleteExceptionList } from '../../tasks/api_calls/exceptions';
import { getExceptionList } from '../../objects/exception';
import { createCustomRule } from '../../tasks/api_calls/rules';
import { cleanKibana, deleteAlertsAndRules } from '../../tasks/common';
import { login, visitWithoutDateRange } from '../../tasks/login';

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

const exceptionList = getExceptionList();

describe('Export rules', () => {
before(() => {
cleanKibana();
Expand Down Expand Up @@ -86,4 +90,48 @@ describe('Export rules', () => {
`Successfully exported ${expectedNumberCustomRulesToBeExported} of ${totalNumberOfRules} rules. Prebuilt rules were excluded from the resulting file.`
);
});

context('rules with exceptions', () => {
beforeEach(() => {
deleteExceptionList(exceptionList.list_id, exceptionList.namespace_type);
// create rule with exceptions
createExceptionList(exceptionList, exceptionList.list_id).then((response) =>
createCustomRule(
{
...getNewRule(),
name: 'rule with exceptions',
exceptionLists: [
{
id: response.body.id,
list_id: exceptionList.list_id,
type: exceptionList.type,
namespace_type: exceptionList.namespace_type,
},
],
},
'2'
)
);
});

it('exports custom rules with exceptions', function () {
// one rule with exception, one without it
const expectedNumberCustomRulesToBeExported = 2;

loadPrebuiltDetectionRulesFromHeaderBtn();

selectAllRules();
bulkExportRules();

// should display correct number of custom rules when one of them has exceptions
cy.get(MODAL_CONFIRMATION_BTN)
.should('have.text', `Export ${expectedNumberCustomRulesToBeExported} custom rules`)
.click();

cy.get(TOASTER_BODY).should(
'contain',
`Successfully exported ${expectedNumberCustomRulesToBeExported}`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const processDryRunResult = (response: BulkActionResponse | undefined): D
*/
export const transformExportDetailsToDryRunResult = (details: ExportRulesDetails): DryRunResult => {
return {
succeededRulesCount: details.exported_count,
succeededRulesCount: details.exported_rules_count,
failedRulesCount: details.missing_rules_count,
// if there are rules that can't be exported, it means they are immutable. So we can safely put error code as immutable
ruleErrors: details.missing_rules.length
Expand Down

0 comments on commit c0363b0

Please sign in to comment.