Skip to content

Commit 6f8e39d

Browse files
[9.1] [Security Solution] Make importing prebuilt rules with missing base version tests matching the test scenario (#234735) (#235114)
# Backport This will backport the following commits from `main` to `9.1`: - [[Security Solution] Make importing prebuilt rules with missing base version tests matching the test scenario (#234735)](#234735) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Maxim Palenov","email":"maxim.palenov@elastic.co"},"sourceCommit":{"committedDate":"2025-09-15T16:36:35Z","message":"[Security Solution] Make importing prebuilt rules with missing base version tests matching the test scenario (#234735)\n\n**Relates to:** https://github.com/elastic/kibana/pull/223421\n\n## Summary\n\nThis PR makes little adjustments to [Importing Prebuilt\nRules](#223421) with missing base\nversion test scenario implementation to make it matching test scenario\nsteps. In particular it makes sure an installed prebuilt rule gets\ncustomized before testing import.","sha":"10533ebfa440c6ac91166cc1d6d33b72d7102dc9","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rule Management","Feature:Prebuilt Detection Rules","backport:version","v9.2.0","v9.1.3","v8.19.3","v9.0.6","v8.18.7"],"title":"[Security Solution] Make importing prebuilt rules with missing base version tests matching the test scenario","number":234735,"url":"https://github.com/elastic/kibana/pull/234735","mergeCommit":{"message":"[Security Solution] Make importing prebuilt rules with missing base version tests matching the test scenario (#234735)\n\n**Relates to:** https://github.com/elastic/kibana/pull/223421\n\n## Summary\n\nThis PR makes little adjustments to [Importing Prebuilt\nRules](#223421) with missing base\nversion test scenario implementation to make it matching test scenario\nsteps. In particular it makes sure an installed prebuilt rule gets\ncustomized before testing import.","sha":"10533ebfa440c6ac91166cc1d6d33b72d7102dc9"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.0","8.18"],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/234735","number":234735,"mergeCommit":{"message":"[Security Solution] Make importing prebuilt rules with missing base version tests matching the test scenario (#234735)\n\n**Relates to:** https://github.com/elastic/kibana/pull/223421\n\n## Summary\n\nThis PR makes little adjustments to [Importing Prebuilt\nRules](#223421) with missing base\nversion test scenario implementation to make it matching test scenario\nsteps. In particular it makes sure an installed prebuilt rule gets\ncustomized before testing import.","sha":"10533ebfa440c6ac91166cc1d6d33b72d7102dc9"}},{"branch":"9.1","label":"v9.1.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Maxim Palenov <maxim.palenov@elastic.co>
1 parent 991185d commit 6f8e39d

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

x-pack/solutions/security/plugins/security_solution/docs/testing/test_plans/detection_response/prebuilt_rules/prebuilt_rule_import.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,10 @@ If this rule is already installed, it should be updated. Its `is_customized` fie
555555
**Automation**: 1 API integration test.
556556

557557
```Gherkin
558-
Given the import payload contains a non-customized prebuilt rule
558+
Given the import payload contains a prebuilt rule
559559
And its rule_id matches one or more rule assets from the installed package
560560
And its version does NOT match any of those rule assets
561-
And this rule is already installed and marked as non-customized
561+
And this rule is already installed and marked as <customization_state>
562562
And the installed rule is NOT equal to the import payload
563563
When the user imports the rule
564564
Then the rule should be updated
@@ -568,6 +568,10 @@ And the updated rule's version should match the import payload
568568
And the updated rule's parameters should match the import payload
569569
```
570570

571+
**Examples:**
572+
573+
`<customization_state>` = `customized` | `non-customized`
574+
571575
#### **Scenario: Importing a prebuilt rule with a missing base version when it's already installed, is not customized, and is equal to the import payload**
572576

573577
If this rule is already installed, it should be updated. Its `is_customized` field should stay unchanged (`false` or `true`) if the rule from the import payload is equal to the installed rule.

x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/common/import_export/import_with_missing_base_version.ts

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default ({ getService }: FtrProviderContext): void => {
2020
const supertest = getService('supertest');
2121
const es = getService('es');
2222
const log = getService('log');
23+
const securitySolutionApi = getService('securitySolutionApi');
2324

2425
const PREBUILT_RULE_ID = 'prebuilt-rule';
2526
const CURRENT_PREBUILT_RULE_VERSION = 5;
@@ -112,7 +113,7 @@ export default ({ getService }: FtrProviderContext): void => {
112113
});
113114

114115
describe('with override (prebuilt rule is installed)', () => {
115-
it('imports a non-customized prebuilt rule with a missing base version when import payload is not equal to the installed prebuilt rule', async () => {
116+
it('imports a prebuilt rule with a missing base version when import payload IS NOT EQUAL to the installed and non-customized prebuilt rule', async () => {
116117
await installPrebuiltRules(es, supertest);
117118

118119
const VERSION = CURRENT_PREBUILT_RULE_VERSION - 1;
@@ -147,9 +148,54 @@ export default ({ getService }: FtrProviderContext): void => {
147148
});
148149
});
149150

151+
it('imports a prebuilt rule with a missing base version when import payload IS NOT EQUAL to the installed and customized prebuilt rule', async () => {
152+
await installPrebuiltRules(es, supertest);
153+
await securitySolutionApi
154+
.patchRule({
155+
body: {
156+
rule_id: PREBUILT_RULE_ID,
157+
name: 'Customized prebuilt rule A',
158+
tags: ['custom-tag'],
159+
},
160+
})
161+
.expect(200);
162+
163+
const VERSION = CURRENT_PREBUILT_RULE_VERSION - 1;
164+
const NON_CUSTOMIZED_PREBUILT_RULE_TO_IMPORT = {
165+
...PREBUILT_RULE_ASSET['security-rule'],
166+
name: 'Some old prebuilt rule A',
167+
description: 'Some old value',
168+
version: VERSION,
169+
immutable: true,
170+
rule_source: {
171+
type: 'external',
172+
is_customized: false,
173+
},
174+
};
175+
176+
await importRulesWithSuccess({
177+
getService,
178+
rules: [NON_CUSTOMIZED_PREBUILT_RULE_TO_IMPORT],
179+
overwrite: true,
180+
});
181+
182+
await assertImportedRule({
183+
getService,
184+
expectedRule: {
185+
...NON_CUSTOMIZED_PREBUILT_RULE_TO_IMPORT,
186+
version: VERSION,
187+
immutable: true,
188+
rule_source: {
189+
type: 'external',
190+
is_customized: true,
191+
},
192+
},
193+
});
194+
});
195+
150196
// The test fails most probably due to a bug. It requires further investigation.
151197
// https://github.com/elastic/kibana/issues/223253 has been created to track it.
152-
it.skip('imports a non-customized prebuilt rule with a missing base version when import payload is equal to the installed prebuilt rule', async () => {
198+
it.skip('imports a prebuilt rule with a missing base version when import payload IS EQUAL to the installed and not-customized prebuilt rule', async () => {
153199
await installPrebuiltRules(es, supertest);
154200

155201
const VERSION = CURRENT_PREBUILT_RULE_VERSION - 1;
@@ -183,14 +229,22 @@ export default ({ getService }: FtrProviderContext): void => {
183229
});
184230
});
185231

186-
it('imports a customized prebuilt rule with a missing base version when import payload and is equal to the installed customized prebuilt rule', async () => {
232+
it('imports a prebuilt rule with a missing base version when import payload IS EQUAL to the installed customized prebuilt rule', async () => {
187233
await installPrebuiltRules(es, supertest);
234+
await securitySolutionApi
235+
.patchRule({
236+
body: {
237+
rule_id: PREBUILT_RULE_ID,
238+
name: 'Customized prebuilt rule A',
239+
tags: ['custom-tag'],
240+
},
241+
})
242+
.expect(200);
188243

189-
const VERSION = CURRENT_PREBUILT_RULE_VERSION - 1;
190244
const NON_CUSTOMIZED_PREBUILT_RULE_TO_IMPORT = {
191245
...PREBUILT_RULE_ASSET['security-rule'],
246+
name: 'Customized prebuilt rule A',
192247
tags: ['custom-tag'],
193-
version: VERSION,
194248
immutable: true,
195249
rule_source: {
196250
type: 'external',
@@ -208,7 +262,6 @@ export default ({ getService }: FtrProviderContext): void => {
208262
getService,
209263
expectedRule: {
210264
...NON_CUSTOMIZED_PREBUILT_RULE_TO_IMPORT,
211-
version: VERSION,
212265
immutable: true,
213266
rule_source: {
214267
type: 'external',

0 commit comments

Comments
 (0)