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

[Cases] Delete Cases API Guardrails #160846

Merged
merged 4 commits into from
Jun 30, 2023

Conversation

adcoelho
Copy link
Contributor

@adcoelho adcoelho commented Jun 29, 2023

Connected to #146945

Summary

Description Limit Done? Documented?
Total number of cases to be deleted 100 Yes
  • Used schema validation.
  • Updated documentation.
  • Added jest and e2e tests.

Checklist

Delete any items that are not applicable to this PR.

Release notes

The Delete cases API now limits the number of cases to be deleted to 100.

@adcoelho adcoelho changed the title Limit number of case ids in delete cases api. [Cases] Delete Cases API Guardrails Jun 29, 2023
@adcoelho adcoelho self-assigned this Jun 29, 2023
@adcoelho adcoelho added Feature:CI Continuous integration Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.10.0 release_note:breaking and removed Feature:CI Continuous integration labels Jun 29, 2023
@adcoelho adcoelho marked this pull request as ready for review June 29, 2023 12:00
@adcoelho adcoelho requested review from a team as code owners June 29, 2023 12:00
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

@@ -106,6 +106,7 @@ export const MAX_CONCURRENT_SEARCHES = 10 as const;
export const MAX_BULK_GET_CASES = 1000 as const;
export const MAX_COMMENTS_PER_PAGE = 100 as const;
export const MAX_CATEGORY_FILTER_LENGTH = 100 as const;
export const MAX_DELETE_IDS_LENGTH = 100 as const;
Copy link
Member

@cnasikas cnasikas Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: I think we should move it to Validation section below.

@@ -95,6 +95,22 @@ describe('delete', () => {
});
});
});

describe('errors', () => {
it(`throws 400 when trying to delete more than ${MAX_DELETE_IDS_LENGTH} files at a time`, async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be testing the MAX_DELETE_IDS_LENGTH, right?

Copy link
Contributor Author

@adcoelho adcoelho Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, do you mean the test name? I left files there by mistake 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for some reason I thought the MAX_DELETE_IDS_LENGTH was only for the files.

@@ -26,7 +28,10 @@ import { createFileEntities, deleteFiles } from '../files';
/**
* Deletes the specified cases and their attachments.
*/
export async function deleteCases(ids: string[], clientArgs: CasesClientArgs): Promise<void> {
export async function deleteCases(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we also define a params schema in x-pack/plugins/cases/server/routes/api/cases/delete_cases.ts. Can you also put the validation there? (using the @kbn/schema)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  params: {
    query: schema.object({
      ids: schema.arrayOf(schema.string()),
    }),
  }

What do you mean with

(using the @kbn/schema)

?

I am not familiar with this '@kbn/config-schema';. I see some routes use it for the parameters(not all though) is it used for validation anywhere, how does it work?

I guess I can just replace this with the limitedArraySchema definition I created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discuss it offline and we decided that we are going to remove the schema defined in all cases routes and rely only on the validation inside the cases client.

Copy link
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OAS LGTM, thanks!

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cases 143.3KB 143.3KB +61.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 413 417 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 492 496 +4
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @adcoelho

@adcoelho adcoelho merged commit b12238b into elastic:main Jun 30, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Cases Cases feature release_note:breaking Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants