Skip to content

Commit

Permalink
Changes out the default arrays and adds types (elastic#93063) (elasti…
Browse files Browse the repository at this point in the history
…c#93089)

## Summary

Follow up from: 
elastic#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

Co-authored-by: Frank Hassanabad <[email protected]>
  • Loading branch information
kibanamachine and FrankHassanabad authored Mar 1, 2021
1 parent cc74c89 commit 74a834b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ describe('buildBulkBody', () => {
created_at: fakeSignalSourceHit.signal.rule?.created_at,
updated_at: fakeSignalSourceHit.signal.rule?.updated_at,
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
depth: 1,
},
Expand Down Expand Up @@ -256,9 +253,6 @@ describe('buildBulkBody', () => {
created_at: fakeSignalSourceHit.signal.rule?.created_at,
updated_at: fakeSignalSourceHit.signal.rule?.updated_at,
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
threshold_result: {
terms: [
Expand Down Expand Up @@ -380,9 +374,6 @@ describe('buildBulkBody', () => {
throttle: 'no_actions',
threat: [],
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
depth: 1,
},
Expand Down Expand Up @@ -494,9 +485,6 @@ describe('buildBulkBody', () => {
updated_at: fakeSignalSourceHit.signal.rule?.updated_at,
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
depth: 1,
},
Expand Down Expand Up @@ -601,9 +589,6 @@ describe('buildBulkBody', () => {
created_at: fakeSignalSourceHit.signal.rule?.created_at,
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
depth: 1,
},
Expand Down Expand Up @@ -707,9 +692,6 @@ describe('buildBulkBody', () => {
created_at: fakeSignalSourceHit.signal.rule?.created_at,
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
depth: 1,
},
Expand Down Expand Up @@ -813,9 +795,6 @@ describe('buildBulkBody', () => {
created_at: fakeSignalSourceHit.signal.rule?.created_at,
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
},
depth: 1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ describe('buildRule', () => {
],
exceptions_list: getListArrayMock(),
version: 1,
threat_filters: [],
threat_index: [],
threat_mapping: [],
};
expect(rule).toEqual(expected);
});
Expand Down Expand Up @@ -166,9 +163,6 @@ describe('buildRule', () => {
created_at: rule.created_at,
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
};
expect(rule).toEqual(expected);
});
Expand Down Expand Up @@ -227,9 +221,6 @@ describe('buildRule', () => {
created_at: rule.created_at,
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
threat_filters: [],
threat_index: [],
threat_mapping: [],
};
expect(rule).toEqual(expected);
});
Expand Down Expand Up @@ -292,9 +283,6 @@ describe('buildRule', () => {
throttle: 'no_actions',
exceptions_list: getListArrayMock(),
version: 1,
threat_filters: [],
threat_index: [],
threat_mapping: [],
};
expect(rule).toEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ export const buildRule = ({
ruleNameMapping: ruleParams.ruleNameOverride,
});

const meta = { ...ruleParams.meta, ...riskScoreMeta, ...severityMeta, ...ruleNameMeta };
const meta: RulesSchema['meta'] = {
...ruleParams.meta,
...riskScoreMeta,
...severityMeta,
...ruleNameMeta,
};

const rule = {
const rule: RulesSchema = {
id,
rule_id: ruleParams.ruleId ?? '(unknown rule_id)',
actions,
Expand Down Expand Up @@ -103,11 +108,11 @@ export const buildRule = ({
created_by: createdBy,
updated_by: updatedBy,
threat: ruleParams.threat ?? [],
threat_mapping: ruleParams.threatMapping ?? [],
threat_filters: ruleParams.threatFilters ?? [],
threat_mapping: ruleParams.threatMapping,
threat_filters: ruleParams.threatFilters,
threat_indicator_path: ruleParams.threatIndicatorPath,
threat_query: ruleParams.threatQuery,
threat_index: ruleParams.threatIndex ?? [],
threat_index: ruleParams.threatIndex,
threat_language: ruleParams.threatLanguage,
timestamp_override: ruleParams.timestampOverride,
throttle,
Expand Down

0 comments on commit 74a834b

Please sign in to comment.