Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to update threat_indicator_path for prebuilt rule #116583

Merged
merged 6 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ export const importRulesRoute = (
threshold,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const patchRulesBulkRoute = (
threshold,
threat_filters: threatFilters,
threat_index: threatIndex,
threat_indicator_path: threatIndicatorPath,
threat_query: threatQuery,
threat_mapping: threatMapping,
threat_language: threatLanguage,
Expand Down Expand Up @@ -178,6 +179,7 @@ export const patchRulesBulkRoute = (
threshold,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const patchRulesRoute = (
threshold,
threat_filters: threatFilters,
threat_index: threatIndex,
threat_indicator_path: threatIndicatorPath,
threat_query: threatQuery,
threat_mapping: threatMapping,
threat_language: threatLanguage,
Expand Down Expand Up @@ -179,6 +180,7 @@ export const patchRulesRoute = (
threshold,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const getPatchRulesOptionsMock = (isRuleRegistryEnabled: boolean): PatchR
threshold: undefined,
threatFilters: undefined,
threatIndex: undefined,
threatIndicatorPath: undefined,
threatQuery: undefined,
threatMapping: undefined,
threatLanguage: undefined,
Expand Down Expand Up @@ -103,6 +104,7 @@ export const getPatchMlRulesOptionsMock = (isRuleRegistryEnabled: boolean): Patc
threshold: undefined,
threatFilters: undefined,
threatIndex: undefined,
threatIndicatorPath: undefined,
threatQuery: undefined,
threatMapping: undefined,
threatLanguage: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const patchRules = async ({
threshold,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down Expand Up @@ -123,6 +124,7 @@ export const patchRules = async ({
threshold,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down Expand Up @@ -170,6 +172,7 @@ export const patchRules = async ({
threshold: threshold ? normalizeThresholdObject(threshold) : undefined,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export interface PatchRulesOptions {
threshold: ThresholdOrUndefined;
threatFilters: ThreatFiltersOrUndefined;
threatIndex: ThreatIndexOrUndefined;
threatIndicatorPath: ThreatIndicatorPathOrUndefined;
threatQuery: ThreatQueryOrUndefined;
threatMapping: ThreatMappingOrUndefined;
threatLanguage: ThreatLanguageOrUndefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,42 @@ describe.each([
})
);
});

it('should update threat match rules', async () => {
const updatedThreatParams = {
threat_index: ['test-index'],
threat_indicator_path: 'test.path',
threat_query: 'threat:*',
};
const prepackagedRule = getAddPrepackagedRulesSchemaDecodedMock();
rulesClient.find.mockResolvedValue(getFindResultWithSingleHit(isRuleRegistryEnabled));

await updatePrepackagedRules(
rulesClient,
savedObjectsClient,
'default',
ruleStatusClient,
[{ ...prepackagedRule, ...updatedThreatParams }],
'output-index',
isRuleRegistryEnabled
);

expect(patchRules).toHaveBeenCalledWith(
expect.objectContaining({
threatIndicatorPath: 'test.path',
})
);

expect(patchRules).toHaveBeenCalledWith(
expect.objectContaining({
threatIndex: ['test-index'],
})
);

expect(patchRules).toHaveBeenCalledWith(
expect.objectContaining({
threatQuery: 'threat:*',
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const createPromises = (
threshold,
threat_filters: threatFilters,
threat_index: threatIndex,
threat_indicator_path: threatIndicatorPath,
threat_query: threatQuery,
threat_mapping: threatMapping,
threat_language: threatLanguage,
Expand Down Expand Up @@ -195,6 +196,7 @@ export const createPromises = (
threshold,
threatFilters,
threatIndex,
threatIndicatorPath,
threatQuery,
threatMapping,
threatLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('utils', () => {
threshold: undefined,
threatFilters: undefined,
threatIndex: undefined,
threatIndicatorPath: undefined,
threatQuery: undefined,
threatMapping: undefined,
threatLanguage: undefined,
Expand Down Expand Up @@ -126,6 +127,7 @@ describe('utils', () => {
threshold: undefined,
threatFilters: undefined,
threatIndex: undefined,
threatIndicatorPath: undefined,
threatQuery: undefined,
threatMapping: undefined,
threatLanguage: undefined,
Expand Down Expand Up @@ -177,6 +179,7 @@ describe('utils', () => {
threshold: undefined,
threatFilters: undefined,
threatIndex: undefined,
threatIndicatorPath: undefined,
threatQuery: undefined,
threatMapping: undefined,
threatLanguage: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
ItemsPerSearchOrUndefined,
ThreatFiltersOrUndefined,
ThreatIndexOrUndefined,
ThreatIndicatorPathOrUndefined,
ThreatLanguageOrUndefined,
ThreatMappingOrUndefined,
ThreatQueryOrUndefined,
Expand Down Expand Up @@ -113,6 +114,7 @@ export interface UpdateProperties {
threshold: ThresholdOrUndefined;
threatFilters: ThreatFiltersOrUndefined;
threatIndex: ThreatIndexOrUndefined;
threatIndicatorPath: ThreatIndicatorPathOrUndefined;
threatQuery: ThreatQueryOrUndefined;
threatMapping: ThreatMappingOrUndefined;
threatLanguage: ThreatLanguageOrUndefined;
Expand Down