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] Limit perPage param in findComments API #160042

Merged
merged 12 commits into from
Jun 21, 2023

Conversation

js-jankisalvi
Copy link
Contributor

Summary

This PR limits perPage param to 100 in findComments API.

Checklist

@js-jankisalvi js-jankisalvi 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 Jun 20, 2023
@js-jankisalvi js-jankisalvi requested a review from a team as a code owner June 20, 2023 15:19
@js-jankisalvi js-jankisalvi self-assigned this Jun 20, 2023
@js-jankisalvi js-jankisalvi requested a review from a team as a code owner June 20, 2023 15:19
@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] limit perPage param in findComments API [Cases] Limit perPage param in findComments API Jun 20, 2023
@@ -51,7 +51,13 @@ export const validateFindCommentsPagination = (params?: FindCommentsQueryParams)
const pageAsNumber = params.page ?? 0;
const perPageAsNumber = params.perPage ?? 0;

if (Math.max(pageAsNumber, perPageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE) {
if (Math.max(perPageAsNumber, 0) > MAX_COMMENTS_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.

why the Math.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.

just in case params.perPage is negative

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm if params.perPage was negative and we didn't have the Math.max it'd still return false right? Do we need the Math.max? If so could you add a test case for a negative value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed Math.max as in both case it will return false


const ERROR_MSG =
'The number of documents is too high. Paginating through more than 10,000 documents is not possible.';

const ERROR_MSG_PER_PAGE = `Too many comments perPage provided, The maximum allowed perPage is ${MAX_COMMENTS_PER_PAGE}.`;

describe('validators', () => {
describe('validateFindCommentsPagination', () => {
it('does not throw if only page is undefined', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: A basic happy path is missing where both are defined and valid.

it('does not throw if page and perPage are defined and valid', () => {
  expect(() => validateFindCommentsPagination({ page: 2, perPage: 100 })).not.toThrowError();
});

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.

API docs LGTM, thanks!

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.

Left some minor comments.


const ERROR_MSG =
'The number of documents is too high. Paginating through more than 10,000 documents is not possible.';

const ERROR_MSG_PER_PAGE = `Too many comments perPage provided, The maximum allowed perPage is ${MAX_COMMENTS_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.

How about: The provided perPage value was too high. The maximum allowed perPage value is ${...}.

if (Math.max(pageAsNumber, perPageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE) {
if (Math.max(perPageAsNumber, 0) > MAX_COMMENTS_PER_PAGE) {
throw Boom.badRequest(
`Too many comments perPage provided, The maximum allowed perPage is ${MAX_COMMENTS_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.

Same suggestions as before about the wording.

@@ -51,7 +51,13 @@ export const validateFindCommentsPagination = (params?: FindCommentsQueryParams)
const pageAsNumber = params.page ?? 0;
const perPageAsNumber = params.perPage ?? 0;

if (Math.max(pageAsNumber, perPageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE) {
if (Math.max(perPageAsNumber, 0) > MAX_COMMENTS_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.

hmm if params.perPage was negative and we didn't have the Math.max it'd still return false right? Do we need the Math.max? If so could you add a test case for a negative value.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 13 15 +2
securitySolution 411 415 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 14 16 +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

@js-jankisalvi js-jankisalvi merged commit de3f8fc into elastic:main Jun 21, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 21, 2023
@js-jankisalvi js-jankisalvi deleted the limit-perpage-find-comments 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: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.

7 participants