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] Restrict the Find Comment API query params #156863

Merged
merged 27 commits into from
May 16, 2023

Conversation

adcoelho
Copy link
Contributor

@adcoelho adcoelho commented May 5, 2023

Fixes #155983

Summary

This PR changes the accepted params for the Find Comments API to be only perPage, page and sort_order.

@adcoelho adcoelho added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.9.0 labels May 5, 2023
@adcoelho adcoelho self-assigned this May 5, 2023
@adcoelho adcoelho force-pushed the limit-find-comments-api-params branch from e21af7b to 475c731 Compare May 8, 2023 10:58
@adcoelho adcoelho marked this pull request as ready for review May 9, 2023 08:52
@adcoelho adcoelho requested review from a team as code owners May 9, 2023 08:52
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

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.

Great job. I left some comments.

@adcoelho adcoelho enabled auto-merge (squash) May 16, 2023 14:42
@adcoelho
Copy link
Contributor Author

@elasticmachine merge upstream

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.

Docs LGTM

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.

Looking good, left a few comments. How about we switch the integration tests to use the helper functions that we have?

if (
queryParams?.page &&
queryParams?.perPage &&
queryParams?.page * queryParams?.perPage > MAX_DOCS_PER_PAGE
Copy link
Contributor

Choose a reason for hiding this comment

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

queryParams.page can be 0 right? If it is 0 and perPage is 1 million we'll still want to throw. Also if queryParams.page was 0 it is falsy right?

await supertest
.post(`${CASES_URL}/${postedCase.id}/comments`)
.post(INTERNAL_BULK_CREATE_ATTACHMENTS_URL.replace('{case_id}', postedCase.id))
Copy link
Contributor

Choose a reason for hiding this comment

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

.expect(200);

const { body: patchedCase } = await supertest
const { body: caseComments } = await supertest
Copy link
Contributor

Choose a reason for hiding this comment

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

});

it('unhappy path - 400s when query is bad', async () => {
it('unhappy path - 400s when total items invalid', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test when page is 0?

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

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 166.2KB 166.0KB -210.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 400 404 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 480 484 +4
total +6

History

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

cc @adcoelho

@adcoelho adcoelho merged commit 927743a into elastic:main May 16, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 16, 2023
jasonrhodes pushed a commit that referenced this pull request May 17, 2023
Fixes #155983

## Summary

This PR changes the accepted params for the Find Comments API to be only
`perPage`, `page` and `sort_order`.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: lcawl <lcawley@elastic.co>
adcoelho added a commit that referenced this pull request May 17, 2023
## Summary

[This PR was merged too
soon](#156863). (my bad, I pressed
merged automatically and some comments showed up afterwards).

I am addressing them now.

Basically:

1. Check for possible 0 as `page` query param in the `findComments` API.
2. Use the test utils in the `findComments` tests.

I also deleted a test that was duplicated and used the same utils in
every test not just the one connected to the PR comment.
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:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cases] Restrict the Find Comment API query params
7 participants