Skip to content
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 @@ -234,6 +234,7 @@ export const importRulesRoute = (router: IRouter, config: LegacyServices['config
references,
note,
version,
lists,
anomalyThreshold,
machineLearningJobId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ describe('patch_rules_bulk', () => {
]);
});

test('allows ML Params to be patched', async () => {
const request = requestMock.create({
method: 'patch',
path: `${DETECTION_ENGINE_RULES_URL}/bulk_update`,
body: [
{
rule_id: 'my-rule-id',
anomaly_threshold: 4,
machine_learning_job_id: 'some_job_id',
},
],
});
await server.inject(request, context);

expect(clients.alertsClient.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
params: expect.objectContaining({
anomalyThreshold: 4,
machineLearningJobId: 'some_job_id',
}),
}),
})
);
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getPatchBulkRequest(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const patchRulesBulkRoute = (router: IRouter) => {
references,
note,
version,
anomaly_threshold: anomalyThreshold,
machine_learning_job_id: machineLearningJobId,
} = payloadRule;
const idOrRuleIdOrUnknown = id ?? ruleId ?? '(unknown id)';
try {
Expand Down Expand Up @@ -111,6 +113,8 @@ export const patchRulesBulkRoute = (router: IRouter) => {
references,
note,
version,
anomalyThreshold,
machineLearningJobId,
});
if (rule != null) {
const ruleStatuses = await savedObjectsClient.find<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ describe('patch_rules', () => {
status_code: 500,
});
});

test('allows ML Params to be patched', async () => {
const request = requestMock.create({
method: 'patch',
path: DETECTION_ENGINE_RULES_URL,
body: {
rule_id: 'my-rule-id',
anomaly_threshold: 4,
machine_learning_job_id: 'some_job_id',
},
});
await server.inject(request, context);

expect(clients.alertsClient.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
params: expect.objectContaining({
anomalyThreshold: 4,
machineLearningJobId: 'some_job_id',
}),
}),
})
);
});
});

describe('request validation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export const patchRulesRoute = (router: IRouter) => {
references,
note,
version,
anomaly_threshold: anomalyThreshold,
machine_learning_job_id: machineLearningJobId,
} = request.body;
const siemResponse = buildSiemResponse(response);

Expand Down Expand Up @@ -108,6 +110,8 @@ export const patchRulesRoute = (router: IRouter) => {
references,
note,
version,
anomalyThreshold,
machineLearningJobId,
});
if (rule != null) {
const ruleStatuses = await savedObjectsClient.find<
Expand Down