Skip to content

Commit 7087ac9

Browse files
Gustrymdouchin
authored andcommitted
Tests about comma separated list of groups
1 parent 4df1334 commit 7087ac9

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

lizmap_server/lizmap_accesscontrol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def _filter_by_login(cfg_layer_login_filter: dict, groups: tuple, login: str) ->
420420

421421
# Since LWC 3.8, we allow to have a list of groups (or logins)
422422
# separated by comma, with NO SPACES
423-
# e.g. field "filter_fiel" can contain 'group_a,group_b,group_c'
423+
# e.g. field "filter_field" can contain 'group_a,group_b,group_c'
424424
# To use only pure SQL allowed by QGIS, we can use LIKE items
425425
# For big dataset, a GIN index with pg_trgm must be used for the
426426
# filter field to improve performance

test/test_lizmap_accesscontrol.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from qgis.core import QgsVectorLayer
1313

14+
from lizmap_server.lizmap_accesscontrol import LizmapAccessControlFilter
1415
from lizmap_server.tos_definitions import (
1516
BING_KEY,
1617
GOOGLE_KEY,
@@ -581,13 +582,27 @@ def test_tos_strict_layers_false(client):
581582
assert "bing-satellite" not in content
582583

583584

584-
def tet_tos_strict_layers_true(client):
585+
def test_tos_strict_layers_true(client):
585586
""" Test TOS layers not restricted. """
587+
# TODO fixme
586588
rv = _make_get_capabilities_tos_layers(client, True)
587589
content = rv.content.decode('utf-8')
588590
layers = rv.xpath('//wms:Layer')
589-
assert len(layers) == 5
591+
assert len(layers) == 2
590592
assert "osm" in content
591-
assert "google-satellite" in content
592-
assert "bing-map" in content
593-
assert "bing-satellite" in content
593+
assert "google-satellite" not in content
594+
assert "bing-map" not in content
595+
assert "bing-satellite" not in content
596+
597+
598+
def test_filter_by_login():
599+
""" Test about comma separated list of values with the current user."""
600+
config = {
601+
'filterPrivate': ['a', 'b'],
602+
'filterAttribute': 'f',
603+
}
604+
output = LizmapAccessControlFilter._filter_by_login(config, ('grp_1', 'grp_2'), 'a')
605+
assert (
606+
"\"f\" = 'a' OR \"f\" LIKE 'a,%' OR \"f\" LIKE '%,a' OR \"f\" LIKE '%,a,%' OR \"f\" = 'all' "
607+
"OR \"f\" LIKE 'all,%' OR \"f\" LIKE '%,all' OR \"f\" LIKE '%,all,%'"
608+
) == output, output

test/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import io
22
import json
3-
4-
from urllib3 import request
53
import xml.etree.ElementTree as ET
64

75
from typing import Dict, Union
@@ -10,6 +8,7 @@
108

119
from PIL import Image
1210
from qgis.server import QgsBufferServerResponse
11+
from urllib3 import request
1312

1413
__copyright__ = 'Copyright 2024, 3Liz'
1514
__license__ = 'GPL version 3'

0 commit comments

Comments
 (0)