From 184c8944d97f9899ad2d632eda1118fde325ea97 Mon Sep 17 00:00:00 2001 From: Viktor Bozhinov Date: Fri, 4 Feb 2022 11:17:28 +0000 Subject: [PATCH] raise `FilterError` when invalid operator is used with bool value #308 --- datagateway_api/src/search_api/query_filter_factory.py | 5 +++++ test/search_api/test_search_api_query_filter_factory.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/datagateway_api/src/search_api/query_filter_factory.py b/datagateway_api/src/search_api/query_filter_factory.py index 1789bcab..a2fc246c 100644 --- a/datagateway_api/src/search_api/query_filter_factory.py +++ b/datagateway_api/src/search_api/query_filter_factory.py @@ -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 diff --git a/test/search_api/test_search_api_query_filter_factory.py b/test/search_api/test_search_api_query_filter_factory.py index 25a4b9e2..06262fc8 100644 --- a/test/search_api/test_search_api_query_filter_factory.py +++ b/test/search_api/test_search_api_query_filter_factory.py @@ -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):