mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Catch malformed filter parameters
This commit is contained in:
committed by
Tobias Dillmann
parent
61a078ad2a
commit
b698ef9eb6
@@ -135,6 +135,10 @@ module API
|
||||
end
|
||||
|
||||
def filter_from_params(filter)
|
||||
unless filter.is_a?(Hash)
|
||||
raise JSON::ParserError, "Filter must be a JSON object, got #{filter.class}"
|
||||
end
|
||||
|
||||
attribute = filter.keys.first # there should only be one attribute per filter
|
||||
operator = filter[attribute]["operator"]
|
||||
values = Array(filter[attribute]["values"])
|
||||
|
||||
@@ -285,6 +285,24 @@ RSpec.describe API::V3::ParseQueryParamsService,
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-object filter element" do
|
||||
let(:params) do
|
||||
{ filters: JSON::dump([["status", "=", "not a hash"]]) }
|
||||
end
|
||||
|
||||
it "is not success" do
|
||||
expect(subject)
|
||||
.not_to be_success
|
||||
end
|
||||
|
||||
it "returns the error" do
|
||||
expect(subject.errors.messages[:base].length)
|
||||
.to be(1)
|
||||
expect(subject.errors.messages[:base][0])
|
||||
.to include("Filter must be a JSON object, got Array")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user