From e337aadc256a94213f14de3efdd0de049daa2462 Mon Sep 17 00:00:00 2001 From: index-git Date: Sat, 16 Sep 2023 12:00:07 +0200 Subject: [PATCH] Test metadata comparison with X-Forwarded-Prefix header --- CHANGELOG.md | 2 +- doc/client-proxy.md | 2 ++ tests/asserts/final/publication/metadata.py | 29 +++++++++++++++++-- .../layer_by_used_servers_test.py | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b415a7f42..68e0cb309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - [#765](https://github.com/LayerManager/layman/issues/765) Remove `authn.txt` files from workspace directories. The same information as in `authn.txt` files is saved in prime DB schema. - [#868](https://github.com/LayerManager/layman/issues/868) Fill table `map_layer` with relations between maps and [internal layers](doc/models.md#internal-map-layer) (layers published on this Layman instance). Relations to [external layers](doc/models.md#internal-map-layer) (layers of other servers) are not imported into the table. ### Changes -- [#868](https://github.com/LayerManager/layman/issues/868) Endpoints [GET Publications](doc/rest.md#get-publications), [GET Layers](doc/rest.md#get-layers), [GET Workspace Layers](doc/rest.md#get-workspace-layers), [GET Maps](doc/rest.md#get-maps), [GET Workspace Maps](doc/rest.md#get-workspace-maps), [GET Workspace Layer](doc/rest.md#get-workspace-layer), [GET Workspace Map](doc/rest.md#get-workspace-map), [POST Workspace Layers](doc/rest.md#post-workspace-layers), [DELETE Workspace Layer](doc/rest.md#delete-workspace-layer), [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps), [POST Workspace Maps](doc/rest.md#post-workspace-maps), [PATCH Workspace Layer](doc/rest.md#patch-workspace-layer), [PATCH Workspace Map](doc/rest.md#patch-workspace-map) and [WMS/WFS endpoints](doc/endpoints.md) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response. +- [#868](https://github.com/LayerManager/layman/issues/868) Endpoints [GET Publications](doc/rest.md#get-publications), [GET Layers](doc/rest.md#get-layers), [GET Workspace Layers](doc/rest.md#get-workspace-layers), [GET Maps](doc/rest.md#get-maps), [GET Workspace Maps](doc/rest.md#get-workspace-maps), [GET Workspace Layer](doc/rest.md#get-workspace-layer), [GET Workspace Map](doc/rest.md#get-workspace-map), [POST Workspace Layers](doc/rest.md#post-workspace-layers), [DELETE Workspace Layer](doc/rest.md#delete-workspace-layer), [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps), [POST Workspace Maps](doc/rest.md#post-workspace-maps), [PATCH Workspace Layer](doc/rest.md#patch-workspace-layer), [PATCH Workspace Map](doc/rest.md#patch-workspace-map) and [WMS/WFS endpoints](doc/endpoints.md) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response. Header does not affect response of [GET Workspace Layer Metadata Comparison](doc/rest.md#get-workspace-layer-metadata-comparison). - [#868](https://github.com/LayerManager/layman/issues/868) Relations between map and [internal layers](doc/models.md#internal-map-layer) are updated in `map_layer` table when calling [POST Workspace Maps](doc/rest.md#post-workspace-maps), [PATCH Workspace Map](doc/rest.md#patch-workspace-map), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), and [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps). - [#880](https://github.com/LayerManager/layman/issues/880) Use Docker Compose v2 (`docker compose`) in Makefile without `compatibility` flag and remove `Makefile_docker-compose_v1` file. Docker containers are named according to Docker Compose v2 and may have different name after upgrade. - [#765](https://github.com/LayerManager/layman/issues/765) Stop saving OAuth2 claims in filesystem, use prime DB schema only. diff --git a/doc/client-proxy.md b/doc/client-proxy.md index efc217ce6..f28339646 100644 --- a/doc/client-proxy.md +++ b/doc/client-proxy.md @@ -94,3 +94,5 @@ Currently, value of `X-Forwarded-Prefix` affects following URLs: * all legend URLs * [WFS endpoints](endpoints.md#web-feature-service) * all operations URLs + +Value of `X-Forwarded-Prefix` does not affects response values of [GET Workspace Layer Metadata Comparison](rest.md#get-workspace-layer-metadata-comparison). diff --git a/tests/asserts/final/publication/metadata.py b/tests/asserts/final/publication/metadata.py index 1f0f6bd22..a14164e03 100644 --- a/tests/asserts/final/publication/metadata.py +++ b/tests/asserts/final/publication/metadata.py @@ -53,7 +53,7 @@ def expected_values_in_micka_metadata(workspace, publ_type, name, expected_value ) -def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_values=None, actor_name=None): +def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_values=None, actor_name=None, headers=None): exp_values = exp_values or {} actor_name = actor_name or settings.ANONYM_USER md_props = { @@ -62,7 +62,8 @@ def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_v }[publ_type] with app.app_context(): resp_json = process_client.get_workspace_publication_metadata_comparison(publ_type, workspace, name, - actor_name=actor_name) + actor_name=actor_name, + headers=headers) assert md_props.issubset(set(resp_json['metadata_properties'].keys())) for key, value in resp_json['metadata_properties'].items(): assert value['equal_or_null'] is True, f'key={key}, value={value}' @@ -80,3 +81,27 @@ def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_v for key, value in exp_values.items(): assert exp_metadata[key] == value, f"Template value differ from expected value, key={key}" expected_values_in_micka_metadata(workspace, publ_type, name, exp_metadata) + + +def correct_layer_comparison_response_with_x_forwarded_prefix_header(workspace, name, *, actor_name=None, headers=None): + proxy_prefix = '/layman-proxy' + headers = headers or {} + actor_name = actor_name or settings.ANONYM_USER + md_props = LAYER_METADATA_PROPERTIES + headers_with_header = {**headers, + 'X-Forwarded-Prefix': proxy_prefix, + } + with app.app_context(): + resp_json_with_proxy = process_client.get_workspace_publication_metadata_comparison(process_client.LAYER_TYPE, workspace, name, + actor_name=actor_name, + headers=headers_with_header) + resp_json_without_proxy = process_client.get_workspace_publication_metadata_comparison(process_client.LAYER_TYPE, workspace, + name, + actor_name=actor_name, + headers=headers) + assert md_props.issubset(set(resp_json_with_proxy['metadata_properties'].keys())) + for key, value in resp_json_with_proxy['metadata_properties'].items(): + assert value['equal_or_null'] is True, f'key={key}, value={value}' + assert value['equal'] is True, f'key={key}, value={value}' + + assert resp_json_with_proxy == resp_json_without_proxy diff --git a/tests/dynamic_data/publications/layer_by_used_servers/layer_by_used_servers_test.py b/tests/dynamic_data/publications/layer_by_used_servers/layer_by_used_servers_test.py index 9d9f781ef..931cdf659 100644 --- a/tests/dynamic_data/publications/layer_by_used_servers/layer_by_used_servers_test.py +++ b/tests/dynamic_data/publications/layer_by_used_servers/layer_by_used_servers_test.py @@ -78,3 +78,4 @@ def test_layer(layer, params, rest_args, rest_method, parametrization): asserts_publ.geoserver_proxy.is_complete_in_workspace_wms(layer.workspace, layer.type, layer.name, version='1.1.1') asserts_publ.geoserver_proxy.wms_legend_url_with_x_forwarded_prefix(layer.workspace, layer.type, layer.name, ) + asserts_publ.metadata.correct_layer_comparison_response_with_x_forwarded_prefix_header(layer.workspace, layer.name, )