-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Guardrails: Limit bulk get cases and bulk get attachments (#1…
…61088) Connected to #146945 ## Summary | Description | Limit | Done? | Documented? | ------------- | ---- | :---: | ---- | | Total number of attachments returned by bulk get API | 100 | ✅ | No (internal) | | Total number of cases returned by bulk get API | 1000 | ✅ | No (internal) | - Replaced the code validation with schema validation. - BulkGet Cases - The minimum of cases that can be returned is now 1(was not validated before). - BulkGet Attachments - The maximum of attachments that can be returned is now 100(was **10000**). - The minimum of attachments that can be returned is now 1(was not validated before). - Updated unit and e2e tests. - The documentation was not updated because these are internal APIs. - Skipping the release notes because these are internal APIs. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [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
- Loading branch information
Showing
9 changed files
with
94 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/cases/server/client/attachments/bulk_get.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { MAX_BULK_GET_ATTACHMENTS } from '../../../common/constants'; | ||
import { createCasesClientMockArgs, createCasesClientMock } from '../mocks'; | ||
import { bulkGet } from './bulk_get'; | ||
|
||
describe('bulkGet', () => { | ||
describe('errors', () => { | ||
const casesClient = createCasesClientMock(); | ||
const clientArgs = createCasesClientMockArgs(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it(`throws when trying to fetch more than ${MAX_BULK_GET_ATTACHMENTS} attachments`, async () => { | ||
await expect( | ||
bulkGet( | ||
{ attachmentIDs: Array(MAX_BULK_GET_ATTACHMENTS + 1).fill('foobar'), caseID: '123' }, | ||
clientArgs, | ||
casesClient | ||
) | ||
).rejects.toThrow( | ||
`Error: The length of the field ids is too long. Array must be of length <= ${MAX_BULK_GET_ATTACHMENTS}.` | ||
); | ||
}); | ||
|
||
it('throws when trying to fetch zero attachments', async () => { | ||
await expect( | ||
bulkGet({ attachmentIDs: [], caseID: '123' }, clientArgs, casesClient) | ||
).rejects.toThrow( | ||
'Error: The length of the field ids is too short. Array must be of length >= 1.' | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters