Skip to content

Commit 1aeb2d1

Browse files
author
Jacek Kolezynski
authored
[9.0] [Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types (#232956) (#233589)
# Backport This will backport the following commits from `main` to `9.0`: - [[Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types (#232956)](#232956) <!--- Backport version: 10.0.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Jacek Kolezynski","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-08-29T22:42:47Z","message":"[Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types (#232956)\n\n**Resolves: #195921**\n\n## Summary\n\nI am modifying the skipped tests and unskipping them in MKI.\n\nThe first attempt of only relying on removing the call to\n`refreshSavedObjectIndices` improved the situation for\n`installPrebuiltRules` but another problem was that similar error with\nprivileges occurred for preparing the assets (reason under the hood\nbeing the same).\nThe failing periodic pipeline build:\nhttps://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-rule-management/builds/3265/steps/canvas\n\nThat is why I am replacing the logic of installing the rule for test.\nInstead of creating assets I am building a zip with our fake rules and\ncalling the `installFleetPackageByUpload` function, as we already do in\nother tests. This allows our test security_detection_engine package to\nbe installed the `official` way.\n**The successful periodic pipeline build**:\nhttps://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-rule-management/builds/3270/steps/canvas\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6cde3f7e92a299fa688f4586f9867711e60836e8","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","v9.0.0","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rule Management","Feature:Prebuilt Detection Rules","backport:version","v8.18.0","v9.1.0","v8.19.0","v9.2.0","v9.1.4"],"title":"[Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types","number":232956,"url":"https://github.com/elastic/kibana/pull/232956","mergeCommit":{"message":"[Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types (#232956)\n\n**Resolves: #195921**\n\n## Summary\n\nI am modifying the skipped tests and unskipping them in MKI.\n\nThe first attempt of only relying on removing the call to\n`refreshSavedObjectIndices` improved the situation for\n`installPrebuiltRules` but another problem was that similar error with\nprivileges occurred for preparing the assets (reason under the hood\nbeing the same).\nThe failing periodic pipeline build:\nhttps://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-rule-management/builds/3265/steps/canvas\n\nThat is why I am replacing the logic of installing the rule for test.\nInstead of creating assets I am building a zip with our fake rules and\ncalling the `installFleetPackageByUpload` function, as we already do in\nother tests. This allows our test security_detection_engine package to\nbe installed the `official` way.\n**The successful periodic pipeline build**:\nhttps://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-rule-management/builds/3270/steps/canvas\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6cde3f7e92a299fa688f4586f9867711e60836e8"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.19"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/233547","number":233547,"state":"MERGED","mergeCommit":{"sha":"4aad0e9405e290e8dc49e80b56e2a61b3577e05a","message":"[9.1] [Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types (#232956) (#233547)\n\n# Backport\n\nThis will backport the following commits from `main` to `9.1`:\n- [[Security Solution] Fix and unskip API integration tests for\npreventing non-customizable fields from updating for Prebuilt rule types\n(#232956)](https://github.com/elastic/kibana/pull/232956)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by: Jacek Kolezynski <[email protected]>"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/232956","number":232956,"mergeCommit":{"message":"[Security Solution] Fix and unskip API integration tests for preventing non-customizable fields from updating for Prebuilt rule types (#232956)\n\n**Resolves: #195921**\n\n## Summary\n\nI am modifying the skipped tests and unskipping them in MKI.\n\nThe first attempt of only relying on removing the call to\n`refreshSavedObjectIndices` improved the situation for\n`installPrebuiltRules` but another problem was that similar error with\nprivileges occurred for preparing the assets (reason under the hood\nbeing the same).\nThe failing periodic pipeline build:\nhttps://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-rule-management/builds/3265/steps/canvas\n\nThat is why I am replacing the logic of installing the rule for test.\nInstead of creating assets I am building a zip with our fake rules and\ncalling the `installFleetPackageByUpload` function, as we already do in\nother tests. This allows our test security_detection_engine package to\nbe installed the `official` way.\n**The successful periodic pipeline build**:\nhttps://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-rule-management/builds/3270/steps/canvas\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6cde3f7e92a299fa688f4586f9867711e60836e8"}}]}] BACKPORT-->
1 parent 73d5740 commit 1aeb2d1

File tree

7 files changed

+120
-60
lines changed

7 files changed

+120
-60
lines changed

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
1313
loadTestFile(require.resolve('./import_export'));
1414
loadTestFile(require.resolve('./install_prebuilt_rules'));
1515
loadTestFile(require.resolve('./prebuilt_rules_package'));
16+
loadTestFile(require.resolve('./non_customizable_fields'));
1617
loadTestFile(require.resolve('./status'));
1718
});
1819
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';
9+
10+
export default function ({ loadTestFile }: FtrProviderContext) {
11+
loadTestFile(require.resolve('./non_customizable_fields'));
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import expect from 'expect';
9+
10+
import { PREBUILT_RULES_PACKAGE_NAME } from '@kbn/security-solution-plugin/common/detection_engine/constants';
11+
import { deleteAllRules } from '../../../../../../../common/utils/security_solution';
12+
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';
13+
import {
14+
getCustomQueryRuleParams,
15+
createPrebuiltRulesPackage,
16+
installFleetPackageByUpload,
17+
installPrebuiltRules,
18+
} from '../../../../utils';
19+
import {
20+
MOCK_PKG_VERSION,
21+
PREBUILT_RULE_ASSET_A,
22+
PREBUILT_RULE_ASSET_B,
23+
PREBUILT_RULE_ID_A,
24+
} from '../configs/edge_cases/ess_air_gapped_with_bundled_packages.config';
25+
26+
export default ({ getService }: FtrProviderContext) => {
27+
const supertest = getService('supertest');
28+
const securitySolutionApi = getService('securitySolutionApi');
29+
const log = getService('log');
30+
const es = getService('es');
31+
32+
describe('@ess @serverless @serverlessQA modifying non-customizable fields', () => {
33+
describe('patch rules', () => {
34+
beforeEach(async () => {
35+
await deleteAllRules(supertest, log);
36+
});
37+
38+
it('throws an error if rule has external rule source and non-customizable fields are changed', async () => {
39+
const securityDetectionEnginePackageZip = createPrebuiltRulesPackage({
40+
packageName: PREBUILT_RULES_PACKAGE_NAME,
41+
packageSemver: MOCK_PKG_VERSION,
42+
prebuiltRuleAssets: [PREBUILT_RULE_ASSET_A, PREBUILT_RULE_ASSET_B],
43+
});
44+
45+
await installFleetPackageByUpload({
46+
getService,
47+
packageBuffer: securityDetectionEnginePackageZip.toBuffer(),
48+
});
49+
50+
await installPrebuiltRules(es, supertest);
51+
52+
const { body } = await securitySolutionApi
53+
.patchRule({
54+
body: {
55+
rule_id: PREBUILT_RULE_ID_A,
56+
author: ['new user'],
57+
},
58+
})
59+
.expect(400);
60+
61+
expect(body.message).toEqual('Cannot update "author" field for prebuilt rules');
62+
});
63+
});
64+
65+
describe('update rules', () => {
66+
afterEach(async () => {
67+
await deleteAllRules(supertest, log);
68+
});
69+
70+
it('throws an error if rule has external rule source and non-customizable fields are changed', async () => {
71+
const securityDetectionEnginePackageZip = createPrebuiltRulesPackage({
72+
packageName: PREBUILT_RULES_PACKAGE_NAME,
73+
packageSemver: MOCK_PKG_VERSION,
74+
prebuiltRuleAssets: [PREBUILT_RULE_ASSET_A, PREBUILT_RULE_ASSET_B],
75+
});
76+
77+
await installFleetPackageByUpload({
78+
getService,
79+
packageBuffer: securityDetectionEnginePackageZip.toBuffer(),
80+
});
81+
82+
await installPrebuiltRules(es, supertest);
83+
84+
const { body: existingRule } = await securitySolutionApi
85+
.readRule({
86+
query: { rule_id: PREBUILT_RULE_ID_A },
87+
})
88+
.expect(200);
89+
90+
const { body } = await securitySolutionApi
91+
.updateRule({
92+
body: getCustomQueryRuleParams({
93+
...existingRule,
94+
rule_id: PREBUILT_RULE_ID_A,
95+
id: undefined,
96+
license: 'new license',
97+
}),
98+
})
99+
.expect(400);
100+
101+
expect(body.message).toEqual('Cannot update "license" field for prebuilt rules');
102+
});
103+
});
104+
});
105+
};

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_patch/basic_license_essentials_tier/patch_rules.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ import expect from 'expect';
1010
import { createRule, deleteAllRules } from '../../../../../../common/utils/security_solution';
1111
import { FtrProviderContext } from '../../../../../ftr_provider_context';
1212
import {
13-
createHistoricalPrebuiltRuleAssetSavedObjects,
14-
createRuleAssetSavedObject,
15-
deleteAllPrebuiltRuleAssets,
1613
getCustomQueryRuleParams,
1714
getSimpleRule,
1815
getSimpleRuleOutput,
1916
getSimpleRuleOutputWithoutRuleId,
20-
installPrebuiltRules,
2117
removeServerGeneratedProperties,
2218
removeServerGeneratedPropertiesIncludingRuleId,
2319
updateUsername,
@@ -27,7 +23,6 @@ export default ({ getService }: FtrProviderContext) => {
2723
const supertest = getService('supertest');
2824
const securitySolutionApi = getService('securitySolutionApi');
2925
const log = getService('log');
30-
const es = getService('es');
3126
const utils = getService('securitySolutionUtils');
3227

3328
describe('@ess @serverless @serverlessQA patch_rules', () => {
@@ -232,26 +227,6 @@ export default ({ getService }: FtrProviderContext) => {
232227
});
233228
});
234229

235-
it('@skipInServerlessMKI throws an error if rule has external rule source and non-customizable fields are changed', async () => {
236-
await deleteAllPrebuiltRuleAssets(es, log);
237-
// Install base prebuilt detection rule
238-
await createHistoricalPrebuiltRuleAssetSavedObjects(es, [
239-
createRuleAssetSavedObject({ rule_id: 'rule-1', author: ['elastic'] }),
240-
]);
241-
await installPrebuiltRules(es, supertest);
242-
243-
const { body } = await securitySolutionApi
244-
.patchRule({
245-
body: {
246-
rule_id: 'rule-1',
247-
author: ['new user'],
248-
},
249-
})
250-
.expect(400);
251-
252-
expect(body.message).toEqual('Cannot update "author" field for prebuilt rules');
253-
});
254-
255230
describe('max signals', () => {
256231
it('does NOT patch a rule when max_signals is less than 1', async () => {
257232
await securitySolutionApi.createRule({

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_update/basic_license_essentials_tier/update_rules.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import {
1818
getSimpleMlRuleUpdate,
1919
getSimpleRule,
2020
updateUsername,
21-
createHistoricalPrebuiltRuleAssetSavedObjects,
22-
installPrebuiltRules,
23-
createRuleAssetSavedObject,
2421
} from '../../../utils';
2522
import {
2623
createAlertsIndex,
@@ -312,34 +309,6 @@ export default ({ getService }: FtrProviderContext) => {
312309
expect(updatedRuleResponse).toMatchObject(expectedRule);
313310
});
314311
});
315-
316-
// Unskip: https://github.com/elastic/kibana/issues/195921
317-
it('@skipInServerlessMKI throws an error if rule has external rule source and non-customizable fields are changed', async () => {
318-
// Install base prebuilt detection rule
319-
await createHistoricalPrebuiltRuleAssetSavedObjects(es, [
320-
createRuleAssetSavedObject({ rule_id: 'rule-1', license: 'elastic' }),
321-
]);
322-
await installPrebuiltRules(es, supertest);
323-
324-
const { body: existingRule } = await securitySolutionApi
325-
.readRule({
326-
query: { rule_id: 'rule-1' },
327-
})
328-
.expect(200);
329-
330-
const { body } = await securitySolutionApi
331-
.updateRule({
332-
body: getCustomQueryRuleParams({
333-
...existingRule,
334-
rule_id: 'rule-1',
335-
id: undefined,
336-
license: 'new license',
337-
}),
338-
})
339-
.expect(400);
340-
341-
expect(body.message).toEqual('Cannot update "license" field for prebuilt rules');
342-
});
343312
});
344313
});
345314
};

x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/install_fleet_package.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export const installFleetPackageByUpload = async ({
119119
},
120120
{
121121
retryCount: MAX_RETRIES,
122-
timeout: FLEET_RATE_LIMIT_TIMEOUT * 3,
122+
retryDelay: FLEET_RATE_LIMIT_TIMEOUT,
123+
timeout: FLEET_RATE_LIMIT_TIMEOUT * 2,
123124
}
124125
);
125126

x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/install_prebuilt_rules.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from '@kbn/security-solution-plugin/common/api/detection_engine/prebuilt_rules';
1313
import type { Client } from '@elastic/elasticsearch';
1414
import type SuperTest from 'supertest';
15-
import { refreshSavedObjectIndices } from '../../refresh_index';
1615

1716
/**
1817
* Installs available prebuilt rules in Kibana. Rules are
@@ -47,7 +46,5 @@ export const installPrebuiltRules = async (
4746
.send(payload)
4847
.expect(200);
4948

50-
await refreshSavedObjectIndices(es);
51-
5249
return response.body;
5350
};

0 commit comments

Comments
 (0)