Skip to content

Commit 1a77095

Browse files
Changes out the default arrays and adds types (#93063)
## Summary Follow up from: #92928 Removes the default arrays and adds typing to the rule schema in order to see which ones require default arrays vs. which ones can/should be defaulted as `undefined`. Updates unit tests. ### Checklist - [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
1 parent f44916b commit 1a77095

3 files changed

Lines changed: 10 additions & 38 deletions

File tree

x-pack/plugins/security_solution/server/lib/detection_engine/signals/build_bulk_body.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ describe('buildBulkBody', () => {
131131
created_at: fakeSignalSourceHit.signal.rule?.created_at,
132132
updated_at: fakeSignalSourceHit.signal.rule?.updated_at,
133133
exceptions_list: getListArrayMock(),
134-
threat_filters: [],
135-
threat_index: [],
136-
threat_mapping: [],
137134
},
138135
depth: 1,
139136
},
@@ -256,9 +253,6 @@ describe('buildBulkBody', () => {
256253
created_at: fakeSignalSourceHit.signal.rule?.created_at,
257254
updated_at: fakeSignalSourceHit.signal.rule?.updated_at,
258255
exceptions_list: getListArrayMock(),
259-
threat_filters: [],
260-
threat_index: [],
261-
threat_mapping: [],
262256
},
263257
threshold_result: {
264258
terms: [
@@ -380,9 +374,6 @@ describe('buildBulkBody', () => {
380374
throttle: 'no_actions',
381375
threat: [],
382376
exceptions_list: getListArrayMock(),
383-
threat_filters: [],
384-
threat_index: [],
385-
threat_mapping: [],
386377
},
387378
depth: 1,
388379
},
@@ -494,9 +485,6 @@ describe('buildBulkBody', () => {
494485
updated_at: fakeSignalSourceHit.signal.rule?.updated_at,
495486
throttle: 'no_actions',
496487
exceptions_list: getListArrayMock(),
497-
threat_filters: [],
498-
threat_index: [],
499-
threat_mapping: [],
500488
},
501489
depth: 1,
502490
},
@@ -601,9 +589,6 @@ describe('buildBulkBody', () => {
601589
created_at: fakeSignalSourceHit.signal.rule?.created_at,
602590
throttle: 'no_actions',
603591
exceptions_list: getListArrayMock(),
604-
threat_filters: [],
605-
threat_index: [],
606-
threat_mapping: [],
607592
},
608593
depth: 1,
609594
},
@@ -707,9 +692,6 @@ describe('buildBulkBody', () => {
707692
created_at: fakeSignalSourceHit.signal.rule?.created_at,
708693
throttle: 'no_actions',
709694
exceptions_list: getListArrayMock(),
710-
threat_filters: [],
711-
threat_index: [],
712-
threat_mapping: [],
713695
},
714696
depth: 1,
715697
},
@@ -813,9 +795,6 @@ describe('buildBulkBody', () => {
813795
created_at: fakeSignalSourceHit.signal.rule?.created_at,
814796
throttle: 'no_actions',
815797
exceptions_list: getListArrayMock(),
816-
threat_filters: [],
817-
threat_index: [],
818-
threat_mapping: [],
819798
},
820799
depth: 1,
821800
},

x-pack/plugins/security_solution/server/lib/detection_engine/signals/build_rule.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ describe('buildRule', () => {
105105
],
106106
exceptions_list: getListArrayMock(),
107107
version: 1,
108-
threat_filters: [],
109-
threat_index: [],
110-
threat_mapping: [],
111108
};
112109
expect(rule).toEqual(expected);
113110
});
@@ -166,9 +163,6 @@ describe('buildRule', () => {
166163
created_at: rule.created_at,
167164
throttle: 'no_actions',
168165
exceptions_list: getListArrayMock(),
169-
threat_filters: [],
170-
threat_index: [],
171-
threat_mapping: [],
172166
};
173167
expect(rule).toEqual(expected);
174168
});
@@ -227,9 +221,6 @@ describe('buildRule', () => {
227221
created_at: rule.created_at,
228222
throttle: 'no_actions',
229223
exceptions_list: getListArrayMock(),
230-
threat_filters: [],
231-
threat_index: [],
232-
threat_mapping: [],
233224
};
234225
expect(rule).toEqual(expected);
235226
});
@@ -292,9 +283,6 @@ describe('buildRule', () => {
292283
throttle: 'no_actions',
293284
exceptions_list: getListArrayMock(),
294285
version: 1,
295-
threat_filters: [],
296-
threat_index: [],
297-
threat_mapping: [],
298286
};
299287
expect(rule).toEqual(expected);
300288
});

x-pack/plugins/security_solution/server/lib/detection_engine/signals/build_rule.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ export const buildRule = ({
6464
ruleNameMapping: ruleParams.ruleNameOverride,
6565
});
6666

67-
const meta = { ...ruleParams.meta, ...riskScoreMeta, ...severityMeta, ...ruleNameMeta };
67+
const meta: RulesSchema['meta'] = {
68+
...ruleParams.meta,
69+
...riskScoreMeta,
70+
...severityMeta,
71+
...ruleNameMeta,
72+
};
6873

69-
const rule = {
74+
const rule: RulesSchema = {
7075
id,
7176
rule_id: ruleParams.ruleId ?? '(unknown rule_id)',
7277
actions,
@@ -103,11 +108,11 @@ export const buildRule = ({
103108
created_by: createdBy,
104109
updated_by: updatedBy,
105110
threat: ruleParams.threat ?? [],
106-
threat_mapping: ruleParams.threatMapping ?? [],
107-
threat_filters: ruleParams.threatFilters ?? [],
111+
threat_mapping: ruleParams.threatMapping,
112+
threat_filters: ruleParams.threatFilters,
108113
threat_indicator_path: ruleParams.threatIndicatorPath,
109114
threat_query: ruleParams.threatQuery,
110-
threat_index: ruleParams.threatIndex ?? [],
115+
threat_index: ruleParams.threatIndex,
111116
threat_language: ruleParams.threatLanguage,
112117
timestamp_override: ruleParams.timestampOverride,
113118
throttle,

0 commit comments

Comments
 (0)