Skip to content

Commit

Permalink
fixes patch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Nov 13, 2024
1 parent 51ac51f commit 5da1389
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,36 @@ describe('applyRulePatch', () => {
})
).rejects.toThrowError('new_terms_fields: Expected array, received string');
});

test('should retain existing required_fields when not present in rule patch body', async () => {
const rulePatch = {
name: 'new name',
} as PatchRuleRequestBody;
const existingRule = {
...getRulesSchemaMock(),
required_fields: [
{
name: 'event.action',
type: 'keyword',
ecs: true,
},
],
};
const patchedRule = await applyRulePatch({
rulePatch,
existingRule,
prebuiltRuleAssetClient,
});
expect(patchedRule).toEqual(
expect.objectContaining({
required_fields: [
{
name: 'event.action',
type: 'keyword',
ecs: true,
},
],
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export const applyRulePatch = async ({
meta: rulePatch.meta ?? existingRule.meta,
max_signals: rulePatch.max_signals ?? existingRule.max_signals,
related_integrations: rulePatch.related_integrations ?? existingRule.related_integrations,
required_fields: addEcsToRequiredFields(rulePatch.required_fields),
required_fields: rulePatch.required_fields
? addEcsToRequiredFields(rulePatch.required_fields)
: existingRule.required_fields,
risk_score: rulePatch.risk_score ?? existingRule.risk_score,
risk_score_mapping: rulePatch.risk_score_mapping ?? existingRule.risk_score_mapping,
rule_name_override: rulePatch.rule_name_override ?? existingRule.rule_name_override,
Expand Down

0 comments on commit 5da1389

Please sign in to comment.