Skip to content

Commit 22245cb

Browse files
author
Jacek Kolezynski
authored
[9.0] [Security Solution] Fix flaky test for delete rules bulk legacy and unskip it (#214724) (#214983)
# Backport This will backport the following commits from `main` to `9.0`: - [[Security Solution] Fix flaky test for delete rules bulk legacy and unskip it (#214724)](#214724) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Jacek Kolezynski","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-03-18T14:01:53Z","message":"[Security Solution] Fix flaky test for delete rules bulk legacy and unskip it (#214724)\n\n**Resolves: #214633**\n\n## Summary\n\nI am fixing a flaky test in the `delete_rules_bulk_legacy.ts` file\nintroduced in the #213244.\n\nAlso, in two other files I am changing using expect from kbn to jest.","sha":"237d4f5c14f787dedf2cb6a346bc1cf8fc835a40","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections and Resp","Team: SecuritySolution","Feature:Rule Management","Team:Detection Rule Management","backport:version","9.1 candidate","v9.1.0"],"title":"[Security Solution] Fix flaky test for delete rules bulk legacy and unskip it","number":214724,"url":"https://github.com/elastic/kibana/pull/214724","mergeCommit":{"message":"[Security Solution] Fix flaky test for delete rules bulk legacy and unskip it (#214724)\n\n**Resolves: #214633**\n\n## Summary\n\nI am fixing a flaky test in the `delete_rules_bulk_legacy.ts` file\nintroduced in the #213244.\n\nAlso, in two other files I am changing using expect from kbn to jest.","sha":"237d4f5c14f787dedf2cb6a346bc1cf8fc835a40"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214724","number":214724,"mergeCommit":{"message":"[Security Solution] Fix flaky test for delete rules bulk legacy and unskip it (#214724)\n\n**Resolves: #214633**\n\n## Summary\n\nI am fixing a flaky test in the `delete_rules_bulk_legacy.ts` file\nintroduced in the #213244.\n\nAlso, in two other files I am changing using expect from kbn to jest.","sha":"237d4f5c14f787dedf2cb6a346bc1cf8fc835a40"}}]}] BACKPORT-->
1 parent 7a764ba commit 22245cb

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_delete/basic_license_essentials_tier/delete_rules_bulk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import expect from '@kbn/expect';
8+
import expect from 'expect';
99

1010
import { FtrProviderContext } from '../../../../../ftr_provider_context';
1111
import {
@@ -58,7 +58,7 @@ export default ({ getService }: FtrProviderContext): void => {
5858
await utils.getUsername()
5959
);
6060

61-
expect(bodyToCompare).to.eql(expectedRule);
61+
expect(bodyToCompare).toEqual(expectedRule);
6262
});
6363

6464
it('should return an error if the id does not exist when trying to delete an id', async () => {
@@ -69,7 +69,7 @@ export default ({ getService }: FtrProviderContext): void => {
6969
})
7070
.expect(500);
7171

72-
expect(body).to.eql({
72+
expect(body).toEqual({
7373
statusCode: 500,
7474
error: 'Internal Server Error',
7575
message: 'Bulk edit failed',

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_delete/trial_license_complete_tier/delete_rules_bulk.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import expect from '@kbn/expect';
8+
import expect from 'expect';
99
import { Rule } from '@kbn/alerting-plugin/common';
1010
import { BaseRuleParams } from '@kbn/security-solution-plugin/server/lib/detection_engine/rule_schema';
1111
import { RuleResponse } from '@kbn/security-solution-plugin/common/api/detection_engine';
@@ -63,7 +63,7 @@ export default ({ getService }: FtrProviderContext): void => {
6363
await utils.getUsername()
6464
);
6565

66-
expect(bodyToCompare).to.eql(expectedRule);
66+
expect(bodyToCompare).toEqual(expectedRule);
6767
});
6868

6969
it('should return an error if the id does not exist when trying to delete an id', async () => {
@@ -74,7 +74,7 @@ export default ({ getService }: FtrProviderContext): void => {
7474
})
7575
.expect(500);
7676

77-
expect(body).to.eql({
77+
expect(body).toEqual({
7878
statusCode: 500,
7979
error: 'Internal Server Error',
8080
message: 'Bulk edit failed',
@@ -144,14 +144,14 @@ export default ({ getService }: FtrProviderContext): void => {
144144
})
145145
.expect(200);
146146

147-
expect(body.success).to.be(true);
148-
expect(body.rules_count).to.be(2);
147+
expect(body.success).toBe(true);
148+
expect(body.rules_count).toBe(2);
149149

150150
const investigationFields = body.attributes.results.deleted
151151
.map((rule: RuleResponse) => rule.investigation_fields)
152152
.sort();
153153

154-
expect(investigationFields).to.eql([
154+
expect(investigationFields).toEqual([
155155
{ field_names: ['client.address', 'agent.name'] },
156156
undefined,
157157
]);

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_delete/trial_license_complete_tier/delete_rules_bulk_legacy.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* 2.0.
66
*/
77

8-
import expect from '@kbn/expect';
8+
import expect from 'expect';
99
import { BASE_ALERTING_API_PATH } from '@kbn/alerting-plugin/common';
10+
import { RuleResponse } from '@kbn/security-solution-plugin/common/api/detection_engine';
1011
import {
1112
createLegacyRuleAction,
1213
getSimpleRule,
@@ -28,8 +29,7 @@ export default ({ getService }: FtrProviderContext): void => {
2829
const log = getService('log');
2930
const es = getService('es');
3031

31-
// Failing: See https://github.com/elastic/kibana/issues/214633
32-
describe.skip('@ess delete_rules_bulk_legacy', () => {
32+
describe('@ess delete_rules_bulk_legacy', () => {
3333
describe('deleting rules bulk using bulk_action endpoint', () => {
3434
beforeEach(async () => {
3535
await createAlertsIndex(supertest, log);
@@ -68,9 +68,9 @@ export default ({ getService }: FtrProviderContext): void => {
6868
})
6969
.expect(200);
7070

71-
expect(body.attributes.results.deleted.length).to.eql(1);
71+
expect(body.attributes.results.deleted.length).toEqual(1);
7272
// ensure that its actions equal what we expect
73-
expect(body.attributes.results.deleted[0].actions).to.eql([
73+
expect(body.attributes.results.deleted[0].actions).toEqual([
7474
{
7575
id: hookAction.id,
7676
action_type_id: hookAction.connector_type_id,
@@ -120,33 +120,31 @@ export default ({ getService }: FtrProviderContext): void => {
120120
.expect(200);
121121

122122
// ensure we only get two bodies back
123-
expect(body.attributes.results.deleted.length).to.eql(2);
123+
expect(body.attributes.results.deleted.length).toEqual(2);
124+
125+
const actions = body.attributes.results.deleted.map(
126+
(rule: RuleResponse) => rule.actions[0]
127+
);
124128

125129
// ensure that its actions equal what we expect for both responses
126-
expect(body.attributes.results.deleted[0].actions).to.eql([
127-
{
128-
id: hookAction1.id,
129-
action_type_id: hookAction1.connector_type_id,
130-
group: 'default',
131-
params: {
132-
message:
133-
'Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts',
134-
},
135-
frequency: { summary: true, throttle: '1h', notifyWhen: 'onThrottleInterval' },
130+
expect(actions).toContainEqual({
131+
id: hookAction1.id,
132+
action_type_id: hookAction1.connector_type_id,
133+
group: 'default',
134+
params: {
135+
message: 'Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts',
136136
},
137-
]);
138-
expect(body.attributes.results.deleted[1].actions).to.eql([
139-
{
140-
id: hookAction2.id,
141-
action_type_id: hookAction2.connector_type_id,
142-
group: 'default',
143-
params: {
144-
message:
145-
'Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts',
146-
},
147-
frequency: { summary: true, throttle: '1h', notifyWhen: 'onThrottleInterval' },
137+
frequency: { summary: true, throttle: '1h', notifyWhen: 'onThrottleInterval' },
138+
});
139+
expect(actions).toContainEqual({
140+
id: hookAction2.id,
141+
action_type_id: hookAction2.connector_type_id,
142+
group: 'default',
143+
params: {
144+
message: 'Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts',
148145
},
149-
]);
146+
frequency: { summary: true, throttle: '1h', notifyWhen: 'onThrottleInterval' },
147+
});
150148
});
151149

152150
/**
@@ -168,8 +166,8 @@ export default ({ getService }: FtrProviderContext): void => {
168166

169167
// check for legacy sidecar action
170168
const sidecarActionsResults = await getLegacyActionSO(es);
171-
expect(sidecarActionsResults.hits.hits.length).to.eql(1);
172-
expect(sidecarActionsResults.hits.hits[0]?._source?.references[0].id).to.eql(
169+
expect(sidecarActionsResults.hits.hits.length).toEqual(1);
170+
expect(sidecarActionsResults.hits.hits[0]?._source?.references[0].id).toEqual(
173171
createRuleBody.id
174172
);
175173

@@ -199,11 +197,11 @@ export default ({ getService }: FtrProviderContext): void => {
199197
.send();
200198

201199
// Expect that we have exactly 0 legacy rules after the deletion
202-
expect(bodyAfterDelete.total).to.eql(0);
200+
expect(bodyAfterDelete.total).toEqual(0);
203201

204202
// legacy sidecar action should be gone
205203
const sidecarActionsPostResults = await getLegacyActionSO(es);
206-
expect(sidecarActionsPostResults.hits.hits.length).to.eql(0);
204+
expect(sidecarActionsPostResults.hits.hits.length).toEqual(0);
207205
});
208206
});
209207
});

0 commit comments

Comments
 (0)