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

Extra params fixes #1667 #1673

Merged
merged 8 commits into from
Aug 19, 2024
Merged
8 changes: 6 additions & 2 deletions pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,12 @@ def get_collection_items(

LOGGER.debug('processing property parameters')
for k, v in request.params.items():
if k not in reserved_fieldnames and k in list(p.fields.keys()):
LOGGER.debug(f'Adding property filter {k}={v}')
if k not in reserved_fieldnames:
if k in list(p.fields.keys()):
LOGGER.debug(f'Adding property filter {k}={v}')
else:
LOGGER.debug(f'Adding additional property filter {k}={v}')

properties.append((k, v))

LOGGER.debug('processing sort parameter')
Expand Down
14 changes: 14 additions & 0 deletions pygeoapi/provider/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,19 @@ def query(

:returns: GeoJSON FeaturesCollection
"""
LOGGER.debug(f"properties contains: {properties}")

# NOTE: properties contains field keys plus extra params
# need to split them up here
filtered_properties = []
extra_params = {}
for (key, value) in properties:
if key in self.fields.keys():
filtered_properties.append((key, value))
else:
extra_params[key] = value

properties = filtered_properties

# Check mandatory filter properties
property_dict = dict(properties)
Expand Down Expand Up @@ -804,6 +817,7 @@ def query(
q,
language,
filterq,
extra_params=extra_params
)

# Clean up placeholders that aren't used by the
Expand Down
12 changes: 12 additions & 0 deletions tests/test_oracle_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def process_query(
q,
language,
filterq,
extra_params
):
sql = "ID = 10 AND :foo != :bar"
if extra_params.get("custom-auth") == "forbidden":
sql = f"{sql} AND 'auth' = 'you are not allowed'"

if sql_query.find(" WHERE ") == -1:
sql_query = sql_query.replace("#WHERE#", f" WHERE {sql}")
Expand Down Expand Up @@ -632,6 +635,15 @@ def test_query_mandatory_properties_must_be_specified(config):
p.query(properties=[("id", "123")])


def test_extra_params_are_passed_to_sql_manipulator(config_manipulator):
extra_params = [("custom-auth", "forbidden")]

p = OracleProvider(config_manipulator)
response = p.query(properties=extra_params)

assert not response['features']


@pytest.fixture()
def database_connection_pool(config_db_conn):
os.environ["ORACLE_POOL_MIN"] = "2" # noqa: F841
Expand Down
Loading