-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cases] Limit perPage param in findComments API #160042
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the Math.max
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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();
});
There was a problem hiding this 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!
There was a problem hiding this 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}.`; |
There was a problem hiding this comment.
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}.` |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
…ankisalvi/kibana into limit-perpage-find-comments
…ankisalvi/kibana into limit-perpage-find-comments
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
This PR limits
perPage
param to 100 infindComments
API.Checklist