Skip to content

Commit

Permalink
Ensure limit 0 searches return 400 (#296)
Browse files Browse the repository at this point in the history
* Ensure limit 0 searches return 400

* Update changelog
  • Loading branch information
moradology authored Nov 24, 2021
1 parent 3219b65 commit cad5e5c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Fixed

* The minimum `limit` value for searches is now 1 ([#296](https://github.com/stac-utils/stac-fastapi/pull/296))
* Links stored with Collections and Items (e.g. license links) are now returned with those STAC objects ([#282](https://github.com/stac-utils/stac-fastapi/pull/282))

## [2.2.0]
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/stac_fastapi/pgstac/types/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PgstacSearch(Search):
token: Optional[str] = None
datetime: Optional[str] = None
sortby: Any
limit: Optional[conint(ge=0, le=10000)] = 10
limit: Optional[conint(gt=0, le=10000)] = 10

@root_validator(pre=True)
def validate_query_fields(cls, values: Dict) -> Dict:
Expand Down
7 changes: 7 additions & 0 deletions stac_fastapi/pgstac/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ async def test_app_query_extension_limit_1(
assert len(resp_json["features"]) == 1


@pytest.mark.asyncio
async def test_app_query_extension_limit_eq0(app_client):
params = {"limit": 0}
resp = await app_client.post("/search", json=params)
assert resp.status_code == 400


@pytest.mark.asyncio
async def test_app_query_extension_limit_lt0(
load_test_data, app_client, load_test_collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SQLAlchemySTACSearch(Search):
# Override query extension with supported operators
query: Optional[Dict[Queryables, Dict[Operator, Any]]]
token: Optional[str] = None
limit: Optional[conint(ge=0, le=10000)] = 10
limit: Optional[conint(gt=0, le=10000)] = 10

@root_validator(pre=True)
def validate_query_fields(cls, values: Dict) -> Dict:
Expand Down
6 changes: 6 additions & 0 deletions stac_fastapi/sqlalchemy/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def test_app_query_extension_gte(load_test_data, app_client, postgres_transactio
assert len(resp_json["features"]) == 1


def test_app_query_extension_limit_eq0(app_client):
params = {"limit": 0}
resp = app_client.post("/search", json=params)
assert resp.status_code == 400


def test_app_query_extension_limit_lt0(
load_test_data, app_client, postgres_transactions
):
Expand Down

0 comments on commit cad5e5c

Please sign in to comment.