diff --git a/CHANGELOG.md b/CHANGELOG.md index 24a3009ec..a75f1897e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The types of changes are: ### Fixed * Distinguish whether webhook has been visited and no fields were found, versus never visited [#1339](https://github.com/ethyca/fidesops/pull/1339) * Fix Redis Cache Early Expiration in Tests [#1358](https://github.com/ethyca/fidesops/pull/1358) +* Limit values for the offset pagination strategy are now cast to integers before use [#1364](https://github.com/ethyca/fidesops/pull/1364) ### Added diff --git a/src/fidesops/ops/service/pagination/pagination_strategy_offset.py b/src/fidesops/ops/service/pagination/pagination_strategy_offset.py index 1ebf8b15d..1c9e09ac1 100644 --- a/src/fidesops/ops/service/pagination/pagination_strategy_offset.py +++ b/src/fidesops/ops/service/pagination/pagination_strategy_offset.py @@ -53,6 +53,12 @@ def get_next_request( raise FidesopsException( f"Unable to find value for 'limit' with the connector_param reference '{self.limit.connector_param}'" ) + try: + limit = int(limit) + except ValueError: + raise FidesopsException( + f"The value '{limit}' of the '{self.limit.connector_param}' connector_param could not be cast to an int" + ) param_value += self.increment_by if param_value > limit: return None diff --git a/tests/ops/service/pagination/test_pagination_strategy_offset.py b/tests/ops/service/pagination/test_pagination_strategy_offset.py index de925d516..6bf7d33cc 100644 --- a/tests/ops/service/pagination/test_pagination_strategy_offset.py +++ b/tests/ops/service/pagination/test_pagination_strategy_offset.py @@ -69,6 +69,54 @@ def test_offset_with_connector_param_reference(response_with_body): ) +def test_offset_with_parsable_string_connector_param_reference(response_with_body): + config = OffsetPaginationConfiguration( + incremental_param="page", + increment_by=1, + limit={"connector_param": "limit"}, + ) + connector_params = {"limit": "10"} + request_params: SaaSRequestParams = SaaSRequestParams( + method=HTTPMethod.GET, + path="/conversations", + query_params={"page": 1}, + ) + + paginator = OffsetPaginationStrategy(config) + next_request: Optional[SaaSRequestParams] = paginator.get_next_request( + request_params, connector_params, response_with_body, "conversations" + ) + assert next_request == SaaSRequestParams( + method=HTTPMethod.GET, + path="/conversations", + query_params={"page": 2}, + ) + + +def test_offset_with_unparsable_string_connector_param_reference(response_with_body): + config = OffsetPaginationConfiguration( + incremental_param="page", + increment_by=1, + limit={"connector_param": "limit"}, + ) + connector_params = {"limit": "ten"} + request_params: SaaSRequestParams = SaaSRequestParams( + method=HTTPMethod.GET, + path="/conversations", + query_params={"page": 1}, + ) + + paginator = OffsetPaginationStrategy(config) + with pytest.raises(FidesopsException) as exc: + next_request: Optional[SaaSRequestParams] = paginator.get_next_request( + request_params, connector_params, response_with_body, "conversations" + ) + assert ( + f"The value 'ten' of the 'limit' connector_param could not be cast to an int" + == str(exc.value) + ) + + def test_offset_with_connector_param_reference_not_found(response_with_body): config = OffsetPaginationConfiguration( incremental_param="page",