Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not echo query parameter values on exceptions (#1789) #1790

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pygeoapi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,8 @@ def get_format_exception(self, request) -> Tuple[dict, int, str]:
# Content-Language is in the system locale (ignore language settings)
headers = request.get_response_headers(SYSTEM_LOCALE,
**self.api_headers)
msg = f'Invalid format: {request.format}'
msg = 'Invalid format requested'
LOGGER.error(f'{msg}: {request.format}')
return self.get_exception(
HTTPStatus.BAD_REQUEST, headers,
request.format, 'InvalidParameterValue', msg)
Expand Down
11 changes: 7 additions & 4 deletions pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ def get_collection_items(
geometry_column_name=provider_def.get('geom_field'),
)
except Exception:
msg = f'Bad CQL string : {cql_text}'
msg = 'Bad CQL text'
LOGGER.error(f'{msg}: {cql_text}')
return api.get_exception(
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidParameterValue', msg)
Expand Down Expand Up @@ -849,7 +850,7 @@ def post_collection_items(
if (request_headers.get(
'Content-Type') or request_headers.get(
'content-type')) != 'application/query-cql-json':
msg = ('Invalid body content-type')
msg = 'Invalid body content-type'
return api.get_exception(
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidHeaderValue', msg)
Expand Down Expand Up @@ -885,7 +886,8 @@ def post_collection_items(
geometry_column_name=provider_def.get('geom_field')
)
except Exception:
msg = f'Bad CQL string : {data}'
msg = 'Bad CQL text'
LOGGER.error(f'{msg}: {data}')
return api.get_exception(
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidParameterValue', msg)
Expand All @@ -894,7 +896,8 @@ def post_collection_items(
try:
filter_ = CQLModel.parse_raw(data)
except Exception:
msg = f'Bad CQL string : {data}'
msg = 'Bad CQL text'
LOGGER.error(f'{msg}: {data}')
return api.get_exception(
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidParameterValue', msg)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ def test_api(config, api_, openapi):
assert rsp_headers['Content-Language'] == 'en-US'
assert code == HTTPStatus.BAD_REQUEST

response = json.loads(response)
assert response['description'] == 'Invalid format requested'

assert api_.get_collections_url() == 'http://localhost:5000/collections'


Expand Down
4 changes: 2 additions & 2 deletions tests/test_postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def test_get_collection_items_postgresql_cql_bad_cql(pg_api_, bad_cql):
assert code == HTTPStatus.BAD_REQUEST
error_response = json.loads(response)
assert error_response['code'] == 'InvalidParameterValue'
assert error_response['description'] == f'Bad CQL string : {bad_cql}'
assert error_response['description'] == 'Bad CQL text'


def test_post_collection_items_postgresql_cql(pg_api_):
Expand Down Expand Up @@ -642,7 +642,7 @@ def test_post_collection_items_postgresql_cql_bad_cql(pg_api_, bad_cql):
assert code == HTTPStatus.BAD_REQUEST
error_response = json.loads(response)
assert error_response['code'] == 'InvalidParameterValue'
assert error_response['description'].startswith('Bad CQL string')
assert error_response['description'] == 'Bad CQL text'


def test_get_collection_items_postgresql_crs(pg_api_):
Expand Down
Loading