Skip to content

Commit

Permalink
raise FilterError when invalid operator is used with bool value #308
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Feb 4, 2022
1 parent 6988a5a commit 184c894
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions datagateway_api/src/search_api/query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ def get_condition_values(conditions_dict):
value = list(conditions_dict[field].values())[0]
operation = list(conditions_dict[field].keys())[0]

if isinstance(value, bool) and operation not in ["eq", "neq"]:
raise FilterError(
"Bad Where filter: Invalid operator used with boolean value",
)

return field, value, operation

@staticmethod
Expand Down
4 changes: 4 additions & 0 deletions test/search_api/test_search_api_query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,10 @@ def test_valid_filter_input_with_all_filters(
},
id="Unsupported skip filter in scope of include filter",
),
pytest.param(
{"filter": {"where": {"isPublic": {"lt": True}}}},
id="Unsupported operator in where filter with boolean value",
),
],
)
def test_invalid_filter_input(self, test_request_filter):
Expand Down

0 comments on commit 184c894

Please sign in to comment.