From IRC: [14:08] <marcelr> Nice /api/v1/patrons?_page=1&_per_page=0 just returns me a 500 (ISE) [14:09] <marcelr> not tested yet :) [14:10] <marcelr> [ERROR] GET /api/v1/patrons: unhandled exception (Mojo::Exception)<<Illegal division by zero at /usr/share/koha/Koha/REST/Plugin/Pagination.pm line 106.>>
To prohibit _per_page=0 we could use OpenAPI 3.0 with not: const: 0
Sorry no quick simple solution found yet. Take a try!
Nice catch.
Created attachment 163342 [details] [review] Bug 35129: Regression tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 163343 [details] [review] Bug 35129: Return 400 if _per_page=0 passed This patch adds a safe guard for when consumers pass _per_page=0 to endpoints. This condition is checked for on a centralized place and avoid reaching the controller in such scenarios that would provoke a division by zero exception. To test: 1. Apply the regression tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/pagination.t => FAIL: We expect a 400, but get a 500 instead 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! No more explosions for this! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 163637 [details] [review] Bug 35129: Regression tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Created attachment 163638 [details] [review] Bug 35129: Return 400 if _per_page=0 passed This patch adds a safe guard for when consumers pass _per_page=0 to endpoints. This condition is checked for on a centralized place and avoid reaching the controller in such scenarios that would provoke a division by zero exception. To test: 1. Apply the regression tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/pagination.t => FAIL: We expect a 400, but get a 500 instead 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! No more explosions for this! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Created attachment 164222 [details] [review] Bug 35129: Regression tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 164223 [details] [review] Bug 35129: Return 400 if _per_page=0 passed This patch adds a safe guard for when consumers pass _per_page=0 to endpoints. This condition is checked for on a centralized place and avoid reaching the controller in such scenarios that would provoke a division by zero exception. To test: 1. Apply the regression tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/pagination.t => FAIL: We expect a 400, but get a 500 instead 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! No more explosions for this! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Pushed for 24.05! Well done everyone, thank you!
Pushed to 23.11.x for 23.11.06
Backported to 23.05.x for upcoming 23.05.12