Skip to content

Commit

Permalink
Test X-Forwarded-Proto and -Host in WFS/WMS endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Sep 26, 2023
1 parent 0ba1fd0 commit e445895
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions tests/asserts/final/publication/geoserver_proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from layman import app, settings, util as layman_util
from layman.layer.geoserver import util as gs_util
from layman.util import XForwardedClass
from test_tools import util as test_util, process_client, geoserver_client
from . import geoserver_util

Expand Down Expand Up @@ -37,20 +38,20 @@ def workspace_wfs_2_0_0_capabilities_available_if_vector(workspace, publ_type, n
assert wfs_layer.metadataUrls[0]['url'].startswith('http://localhost:3080/record/xml/m-')


def wms_legend_url_with_x_forwarded_prefix(workspace, publ_type, name, headers=None):
def wms_legend_url_with_x_forwarded_headers(workspace, publ_type, name, headers=None):
assert publ_type == process_client.LAYER_TYPE
proxy_prefix = '/layman-proxy'
x_forwarded_items = XForwardedClass(proto='https', host='abc.cz', prefix='/layman-proxy')
headers = headers or {}

for input_workspace, key in [(workspace + settings.LAYMAN_GS_WMS_WORKSPACE_POSTFIX, name),
('', f'{workspace + settings.LAYMAN_GS_WMS_WORKSPACE_POSTFIX}:{name}'), ]:
for version in ['1.3.0', '1.1.1']:
wms_inst = geoserver_client.get_wms_capabilities(input_workspace,
headers={'X-Forwarded-Prefix': proxy_prefix,
headers={**x_forwarded_items.headers,
'X-Forwarded-Path': '/some-other-proxy',
**headers,
},
version=version,
)
for style_content in wms_inst.contents[key].styles.values():
assert style_content['legend'].startswith(f'http://localhost:8000{proxy_prefix}/geoserver/')
assert style_content['legend'].startswith(f'https://abc.cz/layman-proxy/geoserver/')
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ 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.geoserver_proxy.wms_legend_url_with_x_forwarded_headers(layer.workspace, layer.type, layer.name, )
asserts_publ.metadata.correct_comparison_response_with_x_forwarded_prefix_header(layer.workspace, layer.type, layer.name, )
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from layman.util import XForwardedClass
from test_tools import geoserver_client

PROXY_PREFIX = '/layman-proxy'
headers = {'X-Forwarded-Prefix': PROXY_PREFIX,
X_FORWARDED_ITEMS = XForwardedClass(proto='https', host='abc.cz', prefix='/layman-proxy')
headers = {**X_FORWARDED_ITEMS.headers,
'X-Forwarded-Path': '/some-other-proxy',
}

Expand All @@ -17,7 +18,7 @@ def test_wms_get_capabilities(version):
version=version,
headers=headers,
)
assert all(m.get('url').startswith(f'http://localhost:8000{PROXY_PREFIX}/geoserver/')
assert all(m.get('url').startswith(f'https://abc.cz/layman-proxy/geoserver/')
for operation in ['GetCapabilities', 'GetMap', 'GetFeatureInfo']
for m in wms_inst.getOperationByName(operation).methods
), f"{wms_inst.getServiceXML()}"
Expand All @@ -33,7 +34,7 @@ def test_wfs_get_capabilities(version):
version=version,
headers=headers,
)
assert all(m.get('url').startswith(f'http://localhost:8000{PROXY_PREFIX}/geoserver/')
assert all(m.get('url').startswith(f'https://abc.cz/layman-proxy/geoserver/')
for operation in ['GetCapabilities', 'DescribeFeatureType', 'GetFeature']
for m in wfs_inst.getOperationByName(operation).methods
), f"{getattr(wfs_inst, '_capabilities')}"

0 comments on commit e445895

Please sign in to comment.