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] Create and update case API guardrails for title, description, category, tags #160844

Merged
merged 15 commits into from
Jun 30, 2023

Conversation

js-jankisalvi
Copy link
Contributor

@js-jankisalvi js-jankisalvi commented Jun 29, 2023

Connected to #146945

Summary

Description Limit Done? Documented?
Total number of description characters 30.000 Yes
Total number of tags per case 200 Yes
Total number of characters per tag 256 Yes
  • Used schema validation.
  • Updated documentation.
  • Added jest and integration tests.

Note: In this PR, maximum length of title (160 characters) and maximum length of category field (50 characters) validations are also moved to schema validation.

Checklist

Release notes

The Create Case and Update Case APIs put the following limits:

  • Total number of characters per title: 160
  • Total number of characters per description: 30K
  • Total number of tags per case: 200
  • Total number of characters per tag: 256
  • Total number of characters per category: 50

@js-jankisalvi js-jankisalvi self-assigned this Jun 29, 2023
@js-jankisalvi js-jankisalvi added release_note:breaking Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.10.0 labels Jun 29, 2023
@js-jankisalvi js-jankisalvi marked this pull request as ready for review June 29, 2023 10:55
@js-jankisalvi js-jankisalvi requested review from a team as code owners June 29, 2023 10:55
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@js-jankisalvi js-jankisalvi changed the title [Cases] Add schema validation for title, description, category, tags while create and update case [Cases] Create and update case API guardrails for title, description, category, tags Jun 29, 2023
});
});

it(`does not throw error when tags array is empty`, async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should throw for scenarios like this.

Calling patch without any params is allowed but we might as well notify the caller that something is probably wrong. @cnasikas ?

Copy link
Member

Choose a reason for hiding this comment

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

We should let users put an empty array of tags as is the only way to remove all tags from a case. Same when creating a case.

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Great work, left a few questions.

rt.string.is,
(input, context) =>
either.chain(rt.string.validate(input, context), (s) => {
if (s.trim().length < min) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm do we want spaces to count as valid characters towards the min and max?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming here that start and end of string spaces are unnecessary and should be removed before checking the length. But I am open if we want to keep it.

Copy link
Member

@cnasikas cnasikas Jun 30, 2023

Choose a reason for hiding this comment

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

I think it all depends on what we persist in ES. If we persist the spaces (which I think we are), then we should not trim. Or the other way around, if we think that we should trim (probably yes because we should not allow a title of only spaces), then we should trim before persisting it to ES. I lean towards trimming it to not allow titles with only empty spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense to me to trim for validation as well as before persisting to ES.

Copy link
Member

@cnasikas cnasikas Jun 30, 2023

Choose a reason for hiding this comment

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

Ok, let's leave the trimming but let's be consistent (not on this PR). In the UI for example no error is being shown in the case view page when you add an empty string to the title. In the backend, we do not trim before saving.

x-pack/plugins/cases/common/schema/index.ts Outdated Show resolved Hide resolved
x-pack/plugins/cases/server/client/cases/create.test.ts Outdated Show resolved Hide resolved
rt.string.is,
(input, context) =>
either.chain(rt.string.validate(input, context), (s) => {
if (s.trim().length === 0 && s.trim().length < min) {
Copy link
Member

Choose a reason for hiding this comment

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

As we trim a lot in this function I think it is better if we put it on a variable. For example, const trimedString = s.trim()

@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.4KB 144.1KB +730.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 @js-jankisalvi

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 changes LGTM, thanks!

@js-jankisalvi js-jankisalvi merged commit 9ef13cd into elastic:main Jun 30, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 30, 2023
@js-jankisalvi js-jankisalvi deleted the guardrails-cases-api branch October 6, 2023 07:38
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.

8 participants