-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution] Adds prebuilt rule customization cypress tests #212170
Merged
banderror
merged 1 commit into
elastic:main
from
dplumlee:rule-customization-cypress-tests
Feb 24, 2025
+388
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
348 changes: 348 additions & 0 deletions
348
...ss/cypress/e2e/detection_response/rule_management/prebuilt_rules/rule_customization.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,348 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { clickRuleUpdatesTab } from '../../../../tasks/prebuilt_rules'; | ||
import { | ||
clickUpdateScheduleMenuItem, | ||
openBulkEditAddIndexPatternsForm, | ||
openBulkEditAddInvestigationFieldsForm, | ||
openBulkEditAddTagsForm, | ||
openBulkEditDeleteIndexPatternsForm, | ||
openBulkEditDeleteInvestigationFieldsForm, | ||
openBulkEditDeleteTagsForm, | ||
setScheduleIntervalTimeUnit, | ||
setScheduleLookbackTimeUnit, | ||
submitBulkEditForm, | ||
typeIndexPatterns, | ||
typeInvestigationFields, | ||
typeScheduleInterval, | ||
typeScheduleLookback, | ||
typeTags, | ||
waitForBulkEditActionToFinish, | ||
} from '../../../../tasks/rules_bulk_actions'; | ||
import { | ||
ABOUT_EDIT_TAB, | ||
ACTIONS_EDIT_TAB, | ||
DEFINITION_EDIT_TAB, | ||
SCHEDULE_EDIT_TAB, | ||
} from '../../../../screens/create_new_rule'; | ||
import { ABOUT_RULE_DESCRIPTION } from '../../../../screens/rule_details'; | ||
import { goToRuleEditSettings } from '../../../../tasks/rule_details'; | ||
import { getIndexPatterns, getNewRule } from '../../../../objects/rule'; | ||
import { | ||
editFirstRule, | ||
expectModifiedBadgeToBeDisplayed, | ||
expectModifiedBadgeToNotBeDisplayed, | ||
expectToContainModifiedBadge, | ||
expectToNotContainModifiedBadge, | ||
filterByCustomRules, | ||
filterByElasticRules, | ||
selectAllRules, | ||
} from '../../../../tasks/alerts_detection_rules'; | ||
import { MODIFIED_RULE_BADGE, RULE_NAME } from '../../../../screens/alerts_detection_rules'; | ||
import { createRuleAssetSavedObject } from '../../../../helpers/rules'; | ||
import { | ||
deleteAlertsAndRules, | ||
deletePrebuiltRulesAssets, | ||
} from '../../../../tasks/api_calls/common'; | ||
import { | ||
createAndInstallMockedPrebuiltRules, | ||
installPrebuiltRuleAssets, | ||
preventPrebuiltRulesPackageInstallation, | ||
} from '../../../../tasks/api_calls/prebuilt_rules'; | ||
import { createRule, patchRule } from '../../../../tasks/api_calls/rules'; | ||
|
||
import { login } from '../../../../tasks/login'; | ||
|
||
import { visitRulesManagementTable } from '../../../../tasks/rules_management'; | ||
import { fillDescription, goToAboutStepTab } from '../../../../tasks/create_new_rule'; | ||
import { saveEditedRule } from '../../../../tasks/edit_rule'; | ||
describe( | ||
'Detection rules, Prebuilt Rules Customization workflow', | ||
{ | ||
tags: ['@ess', '@serverless', '@skipInServerlessMKI'], | ||
env: { | ||
ftrConfig: { | ||
kbnServerArgs: [ | ||
`--xpack.securitySolution.enableExperimental=${JSON.stringify([ | ||
'prebuiltRulesCustomizationEnabled', | ||
])}`, | ||
], | ||
}, | ||
}, | ||
}, | ||
|
||
() => { | ||
describe('Customizing prebuilt rules', () => { | ||
const testTags = ['tag 1', 'tag 2']; | ||
const PREBUILT_RULE = createRuleAssetSavedObject({ | ||
name: 'Non-customized prebuilt rule', | ||
rule_id: 'rule_1', | ||
version: 1, | ||
index: getIndexPatterns(), | ||
tags: testTags, | ||
investigation_fields: { field_names: ['source.ip'] }, | ||
}); | ||
|
||
beforeEach(() => { | ||
login(); | ||
deleteAlertsAndRules(); | ||
deletePrebuiltRulesAssets(); | ||
preventPrebuiltRulesPackageInstallation(); | ||
/* Create a new rule and install it */ | ||
createAndInstallMockedPrebuiltRules([PREBUILT_RULE]); | ||
visitRulesManagementTable(); | ||
createRule( | ||
getNewRule({ | ||
name: 'Custom rule', | ||
index: getIndexPatterns(), | ||
tags: testTags, | ||
enabled: false, | ||
}) | ||
); | ||
}); | ||
|
||
it('user can navigate to rule editing page from the rule details page', function () { | ||
cy.get(RULE_NAME).contains('Non-customized prebuilt rule').click(); | ||
|
||
goToRuleEditSettings(); | ||
cy.get(DEFINITION_EDIT_TAB).should('be.enabled'); | ||
cy.get(ABOUT_EDIT_TAB).should('be.enabled'); | ||
cy.get(SCHEDULE_EDIT_TAB).should('be.enabled'); | ||
cy.get(ACTIONS_EDIT_TAB).should('be.enabled'); | ||
}); | ||
|
||
it('user can edit a non-customized prebuilt rule from the rule edit page', function () { | ||
const newDescriptionValue = 'New rule description'; | ||
cy.get(RULE_NAME).contains('Non-customized prebuilt rule').click(); | ||
|
||
goToRuleEditSettings(); | ||
goToAboutStepTab(); | ||
fillDescription(newDescriptionValue); | ||
saveEditedRule(); | ||
|
||
expectModifiedBadgeToBeDisplayed(); | ||
cy.get(ABOUT_RULE_DESCRIPTION).should('have.text', newDescriptionValue); | ||
}); | ||
|
||
it('user can edit a customized prebuilt rule from the rule edit page', function () { | ||
const newDescriptionValue = 'New rule description'; | ||
patchRule('rule_1', { name: 'Customized prebuilt rule' }); // We want to make this a customized prebuilt rule | ||
visitRulesManagementTable(); | ||
|
||
cy.get(RULE_NAME).contains('Customized prebuilt rule').click(); | ||
expectModifiedBadgeToBeDisplayed(); // Expect modified badge to already be displayed | ||
|
||
goToRuleEditSettings(); | ||
goToAboutStepTab(); | ||
fillDescription(newDescriptionValue); | ||
saveEditedRule(); | ||
|
||
expectModifiedBadgeToBeDisplayed(); | ||
cy.get(ABOUT_RULE_DESCRIPTION).should('have.text', newDescriptionValue); | ||
}); | ||
|
||
it('user can navigate to rule editing page from the rule management page', function () { | ||
filterByElasticRules(); | ||
editFirstRule(); | ||
|
||
cy.get(DEFINITION_EDIT_TAB).should('be.enabled'); | ||
cy.get(ABOUT_EDIT_TAB).should('be.enabled'); | ||
cy.get(SCHEDULE_EDIT_TAB).should('be.enabled'); | ||
cy.get(ACTIONS_EDIT_TAB).should('be.enabled'); | ||
}); | ||
|
||
describe('user can bulk edit prebuilt rules from rules management page', () => { | ||
it('add index patterns', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
openBulkEditAddIndexPatternsForm(); | ||
typeIndexPatterns(['test-pattern']); | ||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('delete index patterns', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
openBulkEditDeleteIndexPatternsForm(); | ||
typeIndexPatterns([getIndexPatterns()[0]]); | ||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('add tags', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
openBulkEditAddTagsForm(); | ||
typeTags(['custom-tag']); | ||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('delete tags', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
openBulkEditDeleteTagsForm(); | ||
typeTags([testTags[0]]); | ||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('add custom highlighted fields', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
openBulkEditAddInvestigationFieldsForm(); | ||
typeInvestigationFields(['host.name']); | ||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('delete custom highlighted fields', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
openBulkEditDeleteInvestigationFieldsForm(); | ||
typeInvestigationFields(['source.ip']); | ||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('modify rule schedules', () => { | ||
filterByElasticRules(); | ||
selectAllRules(); | ||
|
||
clickUpdateScheduleMenuItem(); | ||
|
||
typeScheduleInterval('20'); | ||
setScheduleIntervalTimeUnit('Hours'); | ||
|
||
typeScheduleLookback('10'); | ||
setScheduleLookbackTimeUnit('Minutes'); | ||
|
||
submitBulkEditForm(); | ||
|
||
waitForBulkEditActionToFinish({ | ||
updatedCount: 1, | ||
}); | ||
|
||
expectToContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
}); | ||
|
||
describe('calculating the Modified badge', () => { | ||
it('modified badge should appear on the rule details page when prebuilt rule is customized', function () { | ||
patchRule('rule_1', { name: 'Customized prebuilt rule' }); // We want to make this a customized prebuilt rule | ||
visitRulesManagementTable(); | ||
|
||
cy.get(RULE_NAME).contains('Customized prebuilt rule').click(); | ||
expectModifiedBadgeToBeDisplayed(); // Expect modified badge to be displayed | ||
}); | ||
|
||
it("modified badge should not appear on the rule details page when prebuilt rule isn't customized", function () { | ||
visitRulesManagementTable(); | ||
|
||
cy.get(RULE_NAME).contains('Non-customized prebuilt rule').click(); | ||
expectModifiedBadgeToNotBeDisplayed(); // Expect modified badge to not be displayed | ||
}); | ||
|
||
it("modified badge should not appear on a custom rule's rule details page", function () { | ||
visitRulesManagementTable(); | ||
|
||
cy.get(RULE_NAME).contains('Custom rule').click(); | ||
expectModifiedBadgeToNotBeDisplayed(); // Expect modified badge to not be displayed | ||
}); | ||
|
||
it('modified badge should appear on the rule management table when prebuilt rule is modified', function () { | ||
patchRule('rule_1', { name: 'Customized prebuilt rule' }); // We want to make this a customized prebuilt rule | ||
visitRulesManagementTable(); | ||
|
||
filterByElasticRules(); | ||
expectToContainModifiedBadge('Customized prebuilt rule'); | ||
}); | ||
|
||
it("modified badge should not appear on the rule management table when prebuilt rule isn't customized", function () { | ||
visitRulesManagementTable(); | ||
|
||
filterByElasticRules(); | ||
expectToNotContainModifiedBadge('Non-customized prebuilt rule'); | ||
}); | ||
|
||
it('modified badge should not appear on the rule management table when row is a custom rule', function () { | ||
visitRulesManagementTable(); | ||
|
||
filterByCustomRules(); | ||
expectToNotContainModifiedBadge('Custom rule'); | ||
}); | ||
|
||
it('modified badge should appear on the rule updates table when prebuilt rule is customized', function () { | ||
// Create a new version of the rule to trigger the rule update logic | ||
installPrebuiltRuleAssets([ | ||
{ | ||
...PREBUILT_RULE, | ||
'security-rule': { ...PREBUILT_RULE['security-rule'], version: 2 }, | ||
}, | ||
]); | ||
patchRule('rule_1', { name: 'Customized prebuilt rule' }); // We want to make this a customized prebuilt rule | ||
visitRulesManagementTable(); | ||
clickRuleUpdatesTab(); | ||
|
||
cy.get(MODIFIED_RULE_BADGE).should('exist'); | ||
}); | ||
|
||
it("Modified badge should not appear on the rule updates table when prebuilt rule isn't customized", function () { | ||
// Create a new version of the rule to trigger the rule update logic | ||
installPrebuiltRuleAssets([ | ||
{ | ||
...PREBUILT_RULE, | ||
'security-rule': { ...PREBUILT_RULE['security-rule'], version: 2 }, | ||
}, | ||
]); | ||
visitRulesManagementTable(); | ||
clickRuleUpdatesTab(); | ||
|
||
cy.get(MODIFIED_RULE_BADGE).should('not.exist'); | ||
}); | ||
}); | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for all these tests for the badge we should have a single, common setup that would create all the needed rules, and then in each test we'd be just opening the right pages and checking the badge. There's no need to re-setup each test from scratch.