Skip to content

Commit ac67832

Browse files
do not allow empty ids or querys
1 parent 6b751c1 commit ac67832

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

x-pack/platform/plugins/shared/rule_registry/server/alert_data_client/alerts_client.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,32 @@ describe('AlertsClient', () => {
942942
expect(esClientMock.mget).not.toHaveBeenCalled();
943943
expect(esClientMock.bulk).not.toHaveBeenCalled();
944944
});
945+
946+
it('should throw error when ids is empty', async () => {
947+
await expect(
948+
alertsClient.bulkUpdate({
949+
ids: [],
950+
index: '.alerts-security.alerts-default',
951+
addTags: ['urgent', 'production'],
952+
})
953+
).rejects.toMatchInlineSnapshot(`[Error: no ids or query were provided for updating]`);
954+
955+
expect(esClientMock.mget).not.toHaveBeenCalled();
956+
expect(esClientMock.bulk).not.toHaveBeenCalled();
957+
});
958+
959+
it('should throw error when query is empty', async () => {
960+
await expect(
961+
alertsClient.bulkUpdate({
962+
query: '',
963+
index: '.alerts-security.alerts-default',
964+
addTags: ['urgent', 'production'],
965+
})
966+
).rejects.toMatchInlineSnapshot(`[Error: no ids or query were provided for updating]`);
967+
968+
expect(esClientMock.mget).not.toHaveBeenCalled();
969+
expect(esClientMock.bulk).not.toHaveBeenCalled();
970+
});
945971
});
946972

947973
describe('bulkUpdate edge cases', () => {

x-pack/platform/plugins/shared/rule_registry/server/alert_data_client/alerts_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ export class AlertsClient {
830830
};
831831

832832
// rejects at the route level if more than 1000 id's are passed in
833-
if (ids != null) {
833+
if (ids && ids.length > 0) {
834834
const alerts = ids.map((id) => ({ id, index }));
835835
const mgetRes = await this.ensureAllAlertsAuthorized({
836836
alerts,
@@ -863,7 +863,7 @@ export class AlertsClient {
863863
body: bulkUpdateRequest,
864864
});
865865
return bulkUpdateResponse;
866-
} else if (query != null) {
866+
} else if (query) {
867867
try {
868868
// execute search after with query + authorization filter
869869
// audit results of that query

0 commit comments

Comments
 (0)