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] Add guardrails for add and update comment API #161200

Merged

Conversation

js-jankisalvi
Copy link
Contributor

@js-jankisalvi js-jankisalvi commented Jul 4, 2023

Connected to #146945

Summary

Description Limit Done? Documented?
Total number of comment characters 30.000 Yes
  • Tests.
  • Updated Documentation.

Checklist

Delete any items that are not applicable to this PR.

Release Notes

The total number of characters per comment is limited to 30000

@js-jankisalvi js-jankisalvi added release_note:breaking Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.10.0 labels Jul 4, 2023
@js-jankisalvi js-jankisalvi self-assigned this Jul 4, 2023
@js-jankisalvi js-jankisalvi requested review from a team as code owners July 4, 2023 16:03
@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 Add guardrails for add and update comment API [Cases] Add guardrails for add and update comment API Jul 4, 2023
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!

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

Nice work! Can you add a test in x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts?

x-pack/plugins/cases/server/client/attachments/add.test.ts Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Let's add some tests for the CommentRequestRt to verify the validation. In general, I think it is nice if we created a strong linked chain of tests. For example, we test the CommentRequestRt with all possible testing scenarios. Then we test the addComment and bulkCreate but there there is no need to check all possible testing scenarios (unless there is new logic on top of it). One is enough to ensure the integration between the function and the schema. The chain now is addComment -> CommentRequestRt. If the tests in CommentRequestRt pass we are sure that addComment will work correctly because we have at least one test that tests the integration between the two. Lastly, with integration tests, we check the integration between the addComment and the route.

This article explains the concept in detail: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#sociable-tests

cc @adcoelho

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we test the addComment and bulkCreate but there there is no need to check all possible testing scenarios (unless there is new logic on top of it).

I wondered about this but we need to guarantee somehow that (in this case) CommentRequestRt is being used by addComment and bulkCreate.

Is this what you mean with

because we have at least one test that tests the integration between the two.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh okay, so just checking if I understood it correctly,

  • all the tests of errors like long comment, empty string etc should be part of CommentRequestRt tests in x-pack/plugins/cases/common/api/cases/comment/index.test.ts
  • where as addComment, update and bulk create just tests the integration with CommentRequestRt with one test
  • and same with api integration tests to test route and post_comment, patch_comment, bulk_create_attachments integration with one test?

});

describe('actions', () => {
const updateActionComment = { ...actionComment, id: 'comment-id', version: 'WzAsMV0=' };
Copy link
Contributor

@adcoelho adcoelho Jul 5, 2023

Choose a reason for hiding this comment

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

what is the difference between updateComment and actionComment?

Edit: I know it is the type 😅 but more specifically, how are they different in practice?

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 think @cnasikas can answer it 😄

Copy link
Member

Choose a reason for hiding this comment

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

If a user isolates a host from the alerts flyout the security solution team adds a comment to a case + some information about the host etc. At the time we did not have the attachment framework so this became a core attachment type.

@js-jankisalvi js-jankisalvi enabled auto-merge (squash) July 5, 2023 15:31
@cnasikas
Copy link
Member

cnasikas commented Jul 6, 2023

@elasticmachine merge upstream

@js-jankisalvi js-jankisalvi merged commit 8543d5f into elastic:main Jul 6, 2023
@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 145.5KB 145.8KB +347.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 489 493 +4
total +6

History

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

cc @js-jankisalvi

@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 6, 2023
@js-jankisalvi js-jankisalvi deleted the guardrail-api-comment-characters branch February 19, 2024 11:52
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