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 9bbd904
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 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
25 changes: 20 additions & 5 deletions test/test_lizmap_accesscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from qgis.core import QgsVectorLayer

from lizmap_server.lizmap_accesscontrol import LizmapAccessControlFilter
from lizmap_server.tos_definitions import (
BING_KEY,
GOOGLE_KEY,
Expand Down Expand Up @@ -581,13 +582,27 @@ 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():
""" Test about comma separated list of values with the current user."""
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
3 changes: 1 addition & 2 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import io
import json

from urllib3 import request
import xml.etree.ElementTree as ET

from typing import Dict, Union
Expand All @@ -10,6 +8,7 @@

from PIL import Image
from qgis.server import QgsBufferServerResponse
from urllib3 import request

__copyright__ = 'Copyright 2024, 3Liz'
__license__ = 'GPL version 3'
Expand Down

0 comments on commit 9bbd904

Please sign in to comment.