Skip to content

Commit

Permalink
Fixes #37587 - ensure page and per_page are integers (#11124)
Browse files Browse the repository at this point in the history
* Fixes #37587 - ensure page and per_page are integers

(cherry picked from commit baa0512)
  • Loading branch information
jeremylenz authored and chris1984 committed Sep 11, 2024
1 parent 3bc7814 commit 71e0c6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def scoped_search(query, default_sort_by, default_sort_order, options = {})
else
query = query.paginate(paginate_options)
end
page = params[:page] || 1
per_page = params[:per_page] || Setting[:entries_per_page]
page = metadata_page # from Foreman Api::V2::BaseController
per_page = metadata_per_page
query = (total.zero? || subtotal.zero?) ? blank_query : query

if options[:csv]
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/api/v2/api_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ def test_scoped_search_full_results_false
assert_equal(2, response[:results].length)
end

def test_scoped_search_casts_to_integer
params = { full_result: 'false', page: '1', per_page: '2' }
@controller.stubs(:params).returns(params)

response = @controller.scoped_search(@query, @default_sort[0], @default_sort[1], @options)
refute_empty response[:results], "results"
assert_nil response[:error], "error"
assert_equal 1, response[:page], "page"
assert_kind_of(Integer, response[:page])
assert_equal 2, response[:per_page], "per page"
assert_kind_of(Integer, response[:per_page])
assert_equal(2, response[:results].length)
end

def test_scoped_search_no_results
params = { :search => "asdfasdf" }
@controller.stubs(:params).returns(params)
Expand Down

0 comments on commit 71e0c6b

Please sign in to comment.