Skip to content

Commit

Permalink
Tests about comma separated list of groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Aug 14, 2024
1 parent ce6381e commit c0fd4d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lizmap_server/lizmap_accesscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def _filter_by_login(cfg_layer_login_filter: dict, groups: tuple, login: str) ->

# Since LWC 3.8, we allow to have a list of groups (or logins)
# separated by comma, with NO SPACES
# e.g. field "filter_fiel" can contain 'group_a,group_b,group_c'
# e.g. field "filter_field" can contain 'group_a,group_b,group_c'
# To use only pure SQL allowed by QGIS, we can use LIKE items
# For big dataset, a GIN index with pg_trgm must be used for the
# filter field to improve performance
Expand Down
24 changes: 19 additions & 5 deletions test/test_lizmap_accesscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
GOOGLE_KEY,
strict_tos_check_key,
)
from lizmap_server.lizmap_accesscontrol import LizmapAccessControlFilter

LOGGER = logging.getLogger('server')
PROJECT_FILE = "france_parts.qgs"
Expand Down Expand Up @@ -581,13 +582,26 @@ def test_tos_strict_layers_false(client):
assert "bing-satellite" not in content


def tet_tos_strict_layers_true(client):
def test_tos_strict_layers_true(client):
""" Test TOS layers not restricted. """
# TODO fixme
rv = _make_get_capabilities_tos_layers(client, True)
content = rv.content.decode('utf-8')
layers = rv.xpath('//wms:Layer')
assert len(layers) == 5
assert len(layers) == 2
assert "osm" in content
assert "google-satellite" in content
assert "bing-map" in content
assert "bing-satellite" in content
assert "google-satellite" not in content
assert "bing-map" not in content
assert "bing-satellite" not in content


def test_filter_by_login():
config = {
'filterPrivate': ['a', 'b'],
'filterAttribute': 'f',
}
output = LizmapAccessControlFilter._filter_by_login(config, ('grp_1', 'grp_2'), 'a')
assert (
"\"f\" = 'a' OR \"f\" LIKE 'a,%' OR \"f\" LIKE '%,a' OR \"f\" LIKE '%,a,%' OR \"f\" = 'all' "
"OR \"f\" LIKE 'all,%' OR \"f\" LIKE '%,all' OR \"f\" LIKE '%,all,%'"
) == output, output

0 comments on commit c0fd4d5

Please sign in to comment.