mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Security solution][Detections] fixes incorrect counter for exported rules with exceptions (#138598) (#138833)
## Summary
- addresses https://github.com/elastic/kibana/issues/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
(cherry picked from commit c0363b01ba
)
Co-authored-by: Vitalii Dmyterko <92328789+vitaliidm@users.noreply.github.com>
This commit is contained in:
parent
46728b2245
commit
5e5e76c9e9
2 changed files with 49 additions and 1 deletions
|
@ -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();
|
||||
|
@ -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}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue