11
11
__date__ = '28/08/2015'
12
12
__copyright__ = 'Copyright 2015, The QGIS Project'
13
13
14
+ import os
14
15
import urllib .error
15
16
import urllib .parse
16
17
import urllib .request
@@ -45,11 +46,18 @@ def test_wfs_getcapabilities(self):
45
46
self .assertTrue (
46
47
str (response ).find ("<Name>Hello</Name>" ) != - 1 ,
47
48
"No Hello layer in WFS/GetCapabilities\n %s" % response )
49
+ self .assertFalse (
50
+ str (response ).find ("<Name>Hello_OnOff</Name>" ) != - 1 ,
51
+ "No Hello_OnOff layer in WFS/GetCapabilities\n %s" % response )
48
52
self .assertFalse (
49
53
str (response ).find ("<Name>Country</Name>" ) != - 1 ,
50
54
"Unexpected Country layer in WFS/GetCapabilities\n %s" % response )
51
55
52
56
def test_wfs_describefeaturetype_hello (self ):
57
+ """Tests WFS DescribeFeatureType Request on 'Hello' with access control
58
+ The restricted access to 'Hello' is the expression `$id = 1`
59
+ The field 'color' has restricted access
60
+ """
53
61
query_string = "&" .join (["%s=%s" % i for i in list ({
54
62
"MAP" : urllib .parse .quote (self .projectPath ),
55
63
"SERVICE" : "WFS" ,
@@ -69,6 +77,9 @@ def test_wfs_describefeaturetype_hello(self):
69
77
"No Hello layer in DescribeFeatureType\n %s" % response )
70
78
71
79
def test_wfs_describefeaturetype_country (self ):
80
+ """Tests WFS DescribeFeatureType Request on 'Country' with access control
81
+ The layer 'Country'has restricted access
82
+ """
72
83
query_string = "&" .join (["%s=%s" % i for i in list ({
73
84
"MAP" : urllib .parse .quote (self .projectPath ),
74
85
"SERVICE" : "WFS" ,
@@ -88,6 +99,49 @@ def test_wfs_describefeaturetype_country(self):
88
99
"Unexpected Country layer in DescribeFeatureType\n %s" % response )
89
100
90
101
def test_wfs_getfeature_hello (self ):
102
+ """Tests WFS GetFeature Request on 'Hello' with access control
103
+ The restricted access to 'Hello' is the expression `$id = 1`
104
+ The field 'color' has restricted access
105
+ """
106
+ data = """<?xml version="1.0" encoding="UTF-8"?>
107
+ <wfs:GetFeature {xml_ns}>
108
+ <wfs:Query typeName="Hello" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
109
+ </wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
110
+
111
+ response , headers = self ._post_fullaccess (data )
112
+ # The feature with `pk = 1` is in the response with the field 'color'
113
+ self .assertTrue (
114
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
115
+ "No result in GetFeature\n %s" % response )
116
+ self .assertTrue (
117
+ str (response ).find ("<qgs:color>red</qgs:color>" ) != - 1 , # spellok
118
+ "No color in result of GetFeature\n %s" % response )
119
+ # The feature with `pk = 2` is in the response (no filter, no access control)
120
+ self .assertTrue (
121
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
122
+ "Unexpected result in GetFeature\n %s" % response )
123
+
124
+ response , headers = self ._post_restricted (data )
125
+ # The feature with `pk = 1` is in the response without the field 'color'
126
+ self .assertTrue (
127
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
128
+ "No result in GetFeature\n %s" % response )
129
+ self .assertFalse (
130
+ str (response ).find ("<qgs:color>red</qgs:color>" ) != - 1 , # spellok
131
+ "Unexpected color in result of GetFeature\n %s" % response )
132
+ self .assertFalse (
133
+ str (response ).find ("<qgs:color>NULL</qgs:color>" ) != - 1 , # spellok
134
+ "Unexpected color NULL in result of GetFeature\n %s" % response )
135
+ # The feature with `pk = 2` is not in the response: access control
136
+ self .assertFalse (
137
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
138
+ "Unexpected result in GetFeature\n %s" % response )
139
+
140
+ def test_wfs_getfeature_ogc_filter_hello (self ):
141
+ """Tests WFS GetFeature Request on 'Hello' with OGC Filter `pkuid = 1` and access control
142
+ The restricted access to 'Hello' is the expression `$id = 1`
143
+ The field 'color' has restricted access
144
+ """
91
145
data = """<?xml version="1.0" encoding="UTF-8"?>
92
146
<wfs:GetFeature {xml_ns}>
93
147
<wfs:Query typeName="Hello" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
@@ -97,14 +151,20 @@ def test_wfs_getfeature_hello(self):
97
151
</ogc:PropertyIsEqualTo></ogc:Filter></wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
98
152
99
153
response , headers = self ._post_fullaccess (data )
154
+ # The feature with `pk = 1` is in the response with the field 'color'
100
155
self .assertTrue (
101
156
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
102
157
"No result in GetFeature\n %s" % response )
103
158
self .assertTrue (
104
159
str (response ).find ("<qgs:color>red</qgs:color>" ) != - 1 , # spellok
105
160
"No color in result of GetFeature\n %s" % response )
161
+ # The feature with `pk = 2` is not in the response
162
+ self .assertFalse (
163
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
164
+ "Unexpected result in GetFeature\n %s" % response )
106
165
107
166
response , headers = self ._post_restricted (data )
167
+ # The feature with `pk = 1` is in the response without the field 'color'
108
168
self .assertTrue (
109
169
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
110
170
"No result in GetFeature\n %s" % response )
@@ -114,8 +174,15 @@ def test_wfs_getfeature_hello(self):
114
174
self .assertFalse (
115
175
str (response ).find ("<qgs:color>NULL</qgs:color>" ) != - 1 , # spellok
116
176
"Unexpected color NULL in result of GetFeature\n %s" % response )
177
+ # The feature with `pk = 2` is still not in the response
178
+ self .assertFalse (
179
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
180
+ "Unexpected result in GetFeature\n %s" % response )
117
181
118
- def test_wfs_getfeature_hello2 (self ):
182
+ def test_wfs_getfeature_ogc_filter_hello2 (self ):
183
+ """Tests WFS GetFeature Request on 'Hello' with OGC Filter `pkuid = 2` and access control
184
+ The restricted access to 'Hello' is the expression `$id = 1`
185
+ """
119
186
data = """<?xml version="1.0" encoding="UTF-8"?>
120
187
<wfs:GetFeature {xml_ns}>
121
188
<wfs:Query typeName="Hello" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
@@ -125,22 +192,66 @@ def test_wfs_getfeature_hello2(self):
125
192
</ogc:PropertyIsEqualTo></ogc:Filter></wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
126
193
127
194
response , headers = self ._post_fullaccess (data )
195
+ # The feature with `pk = 2` is in the response
128
196
self .assertTrue (
129
197
str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
130
198
"No result in GetFeature\n %s" % response )
199
+ # The feature with `pk = 1` is not in the response
131
200
self .assertFalse (
132
201
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
133
202
"Unexpected result in GetFeature\n %s" % response )
134
203
135
204
response , headers = self ._post_restricted (data )
205
+ # The feature with `pk = 2` is not in the response
136
206
self .assertFalse (
137
207
str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
138
208
"Unexpected result in GetFeature\n %s" % response )
209
+ # The feature with `pk = 1` is still not in the response
139
210
self .assertFalse (
140
211
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
141
212
"Unexpected result in GetFeature\n %s" % response )
142
213
143
- def test_wfs_getfeature_filter (self ):
214
+ def test_wfs_getfeature_hello_filter (self ):
215
+ """Tests WFS GetFeature Request on 'Hello_Filter' with access control
216
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
217
+ """
218
+ data = """<?xml version="1.0" encoding="UTF-8"?>
219
+ <wfs:GetFeature {xml_ns}>
220
+ <wfs:Query typeName="Hello_Filter" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
221
+ </wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
222
+
223
+ response , headers = self ._post_fullaccess (data )
224
+ # The feature with `pk = 1` is in the response (no filter, no access control)
225
+ self .assertTrue (
226
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
227
+ "No result in GetFeature\n %s" % response )
228
+ # The feature with `pk = 6` is in the response (no filter, no access control)
229
+ self .assertTrue (
230
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
231
+ "Unexpected result in GetFeature\n %s" % response )
232
+ # The feature with `pk = 7` is in the response (no filter, no access control)
233
+ self .assertTrue (
234
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
235
+ "Unexpected result in GetFeature\n %s" % response )
236
+
237
+ response , headers = self ._post_restricted (data )
238
+ # The feature with `pk = 1` is not in the response: access control
239
+ self .assertFalse (
240
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
241
+ "Unexpected result in GetFeature\n %s" % response )
242
+ # The feature with `pk = 6` is in the response: access control
243
+ self .assertTrue (
244
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
245
+ "Unexpected result in GetFeature\n %s" % response )
246
+ # The feature with `pk = 7` is in the response: access control
247
+ self .assertTrue (
248
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
249
+ "Unexpected result in GetFeature\n %s" % response )
250
+
251
+ def test_wfs_getfeature_ogc_filter_hello_filter (self ):
252
+ """Tests WFS GetFeature Request on 'Hello_Filter' with OGC Filter `pkuid = 1` and access control
253
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
254
+ """
144
255
data = """<?xml version="1.0" encoding="UTF-8"?>
145
256
<wfs:GetFeature {xml_ns}>
146
257
<wfs:Query typeName="Hello_Filter" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
@@ -150,22 +261,29 @@ def test_wfs_getfeature_filter(self):
150
261
</ogc:PropertyIsEqualTo></ogc:Filter></wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
151
262
152
263
response , headers = self ._post_fullaccess (data )
264
+ # The feature with `pk = 1` is in the response
153
265
self .assertTrue (
154
266
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
155
267
"No result in GetFeature\n %s" % response )
268
+ # The feature with `pk = 6` is not in the response
156
269
self .assertFalse (
157
270
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
158
271
"Unexpected result in GetFeature\n %s" % response )
159
272
160
273
response , headers = self ._post_restricted (data )
274
+ # The feature with `pk = 1` is not in the response
161
275
self .assertFalse (
162
276
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
163
277
"Unexpected result in GetFeature\n %s" % response )
278
+ # The feature with `pk = 6` is still not in the response
164
279
self .assertFalse (
165
280
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
166
281
"Unexpected result in GetFeature\n %s" % response )
167
282
168
- def test_wfs_getfeature_filter2 (self ):
283
+ def test_wfs_getfeature_ogc_filter_hello_filter2 (self ):
284
+ """Tests WFS GetFeature Request on 'Hello_Filter' with OGC Filter `pkuid = 6` and access control
285
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
286
+ """
169
287
data = """<?xml version="1.0" encoding="UTF-8"?>
170
288
<wfs:GetFeature {xml_ns}>
171
289
<wfs:Query typeName="Hello_Filter" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
@@ -175,22 +293,66 @@ def test_wfs_getfeature_filter2(self):
175
293
</ogc:PropertyIsEqualTo></ogc:Filter></wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
176
294
177
295
response , headers = self ._post_fullaccess (data )
296
+ # The feature with `pk = 6` is in the response
178
297
self .assertTrue (
179
298
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
180
299
"No result in GetFeature\n %s" % response )
300
+ # The feature with `pk = 7` is not in the response
181
301
self .assertFalse (
182
302
str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
183
303
"Unexpected result in GetFeature\n %s" % response )
184
304
185
305
response , headers = self ._post_restricted (data )
306
+ # The feature with `pk = 6` is still in the response
186
307
self .assertTrue (
187
308
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
188
309
"No result in GetFeature\n %s" % response )
310
+ # The feature with `pk = 7` is still not in the response
189
311
self .assertFalse (
190
312
str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
191
313
"Unexpected result in GetFeature\n %s" % response )
192
314
193
- def test_wfs_getfeature_country (self ):
315
+ def test_wfs_getfeature_hello_onoff (self ):
316
+ """Tests WFS GetFeature Request on 'Hello_OnOff' with access control
317
+ The restricted access to 'Hello_OnOff is cannot be read
318
+ """
319
+ data = """<?xml version="1.0" encoding="UTF-8"?>
320
+ <wfs:GetFeature {xml_ns}>
321
+ <wfs:Query typeName="Hello_OnOff" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
322
+ </wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
323
+
324
+ response , headers = self ._post_fullaccess (data )
325
+ # Some qgs feature Hello_OnOff element
326
+ self .assertTrue (
327
+ str (response ).find ("<qgs:Hello_OnOff " ) != - 1 ,
328
+ "No result in GetFeature\n %s" % response )
329
+ # The feature with `pk = 1` is in the response
330
+ self .assertTrue (
331
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
332
+ "No result in GetFeature\n %s" % response )
333
+ # The feature with `pk = 6` is in the response
334
+ self .assertTrue (
335
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
336
+ "No result in GetFeature\n %s" % response )
337
+
338
+ response , headers = self ._post_restricted (data )
339
+ # The feature with `pk = 1` is not in the response
340
+ self .assertFalse (
341
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
342
+ "Unexpected result in GetFeature\n %s" % response )
343
+ # The feature with `pk = 6` is not in the response
344
+ self .assertFalse (
345
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
346
+ "Unexpected result in GetFeature\n %s" % response )
347
+ # No qgs feature Hello_OnOff element
348
+ self .assertFalse (
349
+ str (response ).find ("<qgs:Hello_OnOff " ) != - 1 ,
350
+ "Unexpected result in GetFeature\n %s" % response )
351
+
352
+ def test_wfs_getfeature_ogc_filter_hello_onoff (self ):
353
+ """Tests WFS GetFeature Request on 'Hello_OnOff' with OGC Filter `pkuid = 1` access control
354
+ The restricted access to 'Hello_OnOff is cannot be read
355
+ """
194
356
data = """<?xml version="1.0" encoding="UTF-8"?>
195
357
<wfs:GetFeature {xml_ns}>
196
358
<wfs:Query typeName="Hello_OnOff" srsName="EPSG:3857" xmlns:feature="http://www.qgis.org/gml">
@@ -200,14 +362,32 @@ def test_wfs_getfeature_country(self):
200
362
</ogc:PropertyIsEqualTo></ogc:Filter></wfs:Query></wfs:GetFeature>""" .format (xml_ns = XML_NS )
201
363
202
364
response , headers = self ._post_fullaccess (data )
365
+ # Some qgs feature Hello_OnOff element
366
+ self .assertTrue (
367
+ str (response ).find ("<qgs:Hello_OnOff " ) != - 1 ,
368
+ "No result in GetFeature\n %s" % response )
369
+ # The feature with `pk = 1` is in the response
203
370
self .assertTrue (
204
371
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
205
372
"No result in GetFeature\n %s" % response )
373
+ # The feature with `pk = 6` is not in the response
374
+ self .assertFalse (
375
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
376
+ "Unexpected result in GetFeature\n %s" % response )
206
377
207
378
response , headers = self ._post_restricted (data )
379
+ # The feature with `pk = 1` is not in the response
208
380
self .assertFalse (
209
381
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
210
- "Unexpected result in GetFeature\n %s" % response ) # spellok
382
+ "Unexpected result in GetFeature\n %s" % response )
383
+ # The feature with `pk = 6` is still not in the response
384
+ self .assertFalse (
385
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
386
+ "Unexpected result in GetFeature\n %s" % response )
387
+ # No qgs feature Hello_OnOff element
388
+ self .assertFalse (
389
+ str (response ).find ("<qgs:Hello_OnOff " ) != - 1 ,
390
+ "Unexpected result in GetFeature\n %s" % response )
211
391
212
392
# # Subset String # #
213
393
@@ -340,7 +520,13 @@ def test_wfs_getfeature_project_subsetstring3(self):
340
520
str (response ).find ("<qgs:pk>" ) != - 1 ,
341
521
"Project based layer subsetString not respected in GetFeature with restricted access\n %s" % response )
342
522
523
+ # # KVP request instead of XML request # #
524
+
343
525
def test_wfs_getfeature_exp_filter_hello (self ):
526
+ """Tests WFS GetFeature Request on 'Hello' with Expression Filter `pkuid = 1` and access control
527
+ The restricted access to 'Hello' is the expression `$id = 1`
528
+ The field 'color' has restricted access
529
+ """
344
530
query_string = "&" .join (["%s=%s" % i for i in list ({
345
531
"MAP" : urllib .parse .quote (self .projectPath ),
346
532
"SERVICE" : "WFS" ,
@@ -351,14 +537,20 @@ def test_wfs_getfeature_exp_filter_hello(self):
351
537
}.items ())])
352
538
353
539
response , headers = self ._get_fullaccess (query_string )
540
+ # The feature with `pk = 1` is in the response with the field 'color'
354
541
self .assertTrue (
355
542
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
356
543
"No result in GetFeature\n %s" % response )
357
544
self .assertTrue (
358
545
str (response ).find ("<qgs:color>red</qgs:color>" ) != - 1 , # spellok
359
546
"No color in result of GetFeature\n %s" % response )
547
+ # The feature with `pk = 2` is not in the response
548
+ self .assertFalse (
549
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
550
+ "Unexpected color in result of GetFeature\n %s" % response )
360
551
361
552
response , headers = self ._get_restricted (query_string )
553
+ # The feature with `pk = 1` is in the response without the field 'color'
362
554
self .assertTrue (
363
555
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
364
556
"No result in GetFeature\n %s" % response )
@@ -368,8 +560,15 @@ def test_wfs_getfeature_exp_filter_hello(self):
368
560
self .assertFalse (
369
561
str (response ).find ("<qgs:color>NULL</qgs:color>" ) != - 1 , # spellok
370
562
"Unexpected color NULL in result of GetFeature\n %s" % response )
563
+ # The feature with `pk = 2` is still not in the response
564
+ self .assertFalse (
565
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
566
+ "Unexpected color in result of GetFeature\n %s" % response )
371
567
372
568
def test_wfs_getfeature_exp_filter_hello2 (self ):
569
+ """Tests WFS GetFeature Request on 'Hello' with Expression Filter `pkuid = 2` and access control
570
+ The restricted access to 'Hello' is the expression `$id = 1`
571
+ """
373
572
query_string = "&" .join (["%s=%s" % i for i in list ({
374
573
"MAP" : urllib .parse .quote (self .projectPath ),
375
574
"SERVICE" : "WFS" ,
@@ -380,22 +579,36 @@ def test_wfs_getfeature_exp_filter_hello2(self):
380
579
}.items ())])
381
580
382
581
response , headers = self ._get_fullaccess (query_string )
582
+ # The feature with `pk = 2` is in the response
383
583
self .assertTrue (
384
584
str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
385
585
"No result in GetFeature\n %s" % response )
586
+ # The feature with `pk = 1` is not in the response
386
587
self .assertFalse (
387
588
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
388
589
"Unexpected result in GetFeature\n %s" % response )
389
590
390
591
response , headers = self ._get_restricted (query_string )
592
+ # The feature with `pk = 2` is not in the response
391
593
self .assertFalse (
392
594
str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
393
595
"Unexpected result in GetFeature\n %s" % response )
394
596
self .assertFalse (
395
597
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
396
598
"Unexpected result in GetFeature\n %s" % response )
599
+ # The feature with `pk = 1` is still not in the response
600
+ self .assertFalse (
601
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
602
+ "Unexpected result in GetFeature\n %s" % response )
603
+ # No qgs feature Hello element
604
+ self .assertFalse (
605
+ str (response ).find ("<qgs:Hello " ) != - 1 ,
606
+ "Unexpected result in GetFeature\n %s" % response )
397
607
398
608
def test_wfs_getfeature_exp_filter_hello_filter (self ):
609
+ """Tests WFS GetFeature Request on 'Hello_Filter' with Expression Filter `pkuid = 1` and access control
610
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
611
+ """
399
612
query_string = "&" .join (["%s=%s" % i for i in list ({
400
613
"MAP" : urllib .parse .quote (self .projectPath ),
401
614
"SERVICE" : "WFS" ,
@@ -406,22 +619,47 @@ def test_wfs_getfeature_exp_filter_hello_filter(self):
406
619
}.items ())])
407
620
408
621
response , headers = self ._get_fullaccess (query_string )
622
+ # The feature with `pk = 1` is in the response
409
623
self .assertTrue (
410
624
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
411
625
"No result in GetFeature\n %s" % response )
412
626
self .assertFalse (
413
627
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
414
628
"Unexpected result in GetFeature\n %s" % response )
629
+ # The feature with `pk = 6` is not in the response
630
+ self .assertFalse (
631
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
632
+ "Unexpected result in GetFeature\n %s" % response )
633
+ # The feature with `pk = 7` is not in the response
634
+ self .assertFalse (
635
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
636
+ "Unexpected result in GetFeature\n %s" % response )
415
637
416
638
response , headers = self ._get_restricted (query_string )
639
+ # The feature with `pk = 1` is not in the response
417
640
self .assertFalse (
418
641
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
419
642
"Unexpected result in GetFeature\n %s" % response )
420
643
self .assertFalse (
421
644
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
422
645
"Unexpected result in GetFeature\n %s" % response )
646
+ # The feature with `pk = 6` is still not in the response
647
+ self .assertFalse (
648
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
649
+ "Unexpected result in GetFeature\n %s" % response )
650
+ # The feature with `pk = 7` is still not in the response
651
+ self .assertFalse (
652
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
653
+ "Unexpected result in GetFeature\n %s" % response )
654
+ # No qgs feature Hello_Filter element
655
+ self .assertFalse (
656
+ str (response ).find ("<qgs:Hello_Filter " ) != - 1 ,
657
+ "Unexpected result in GetFeature\n %s" % response )
423
658
424
659
def test_wfs_getfeature_exp_filter_hello_filter2 (self ):
660
+ """Tests WFS GetFeature Request on 'Hello_Filter' with Expression Filter `pkuid = 6` and access control
661
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
662
+ """
425
663
query_string = "&" .join (["%s=%s" % i for i in list ({
426
664
"MAP" : urllib .parse .quote (self .projectPath ),
427
665
"SERVICE" : "WFS" ,
@@ -432,9 +670,15 @@ def test_wfs_getfeature_exp_filter_hello_filter2(self):
432
670
}.items ())])
433
671
434
672
response , headers = self ._get_fullaccess (query_string )
673
+ # The feature with `pk = 6` is in the response
435
674
self .assertTrue (
436
675
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
437
676
"No result in GetFeature\n %s" % response )
677
+ # The feature with `pk = 1` is not in the response
678
+ self .assertFalse (
679
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
680
+ "Unexpected result in GetFeature\n %s" % response )
681
+ # The feature with `pk = 7` is not in the response
438
682
self .assertFalse (
439
683
str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
440
684
"Unexpected result in GetFeature\n %s" % response )
@@ -443,11 +687,20 @@ def test_wfs_getfeature_exp_filter_hello_filter2(self):
443
687
self .assertTrue (
444
688
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
445
689
"No result in GetFeature\n %s" % response )
690
+ # The feature with `pk = 1` is still not in the response
691
+ self .assertFalse (
692
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
693
+ "Unexpected result in GetFeature\n %s" % response )
694
+ # The feature with `pk = 7` is not in the response
446
695
self .assertFalse (
447
696
str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
448
697
"Unexpected result in GetFeature\n %s" % response )
449
698
450
- def test_wfs_getfeature_featureid_hello_1 (self ):
699
+ def test_wfs_getfeature_featureid_hello (self ):
700
+ """Tests WFS GetFeature Request on 'Hello' with FeatureId `Hello.1` and access control
701
+ The restricted access to 'Hello' is the expression `$id = 1`
702
+ The field 'color' has restricted access
703
+ """
451
704
query_string = "&" .join (["%s=%s" % i for i in list ({
452
705
"MAP" : urllib .parse .quote (self .projectPath ),
453
706
"SERVICE" : "WFS" ,
@@ -458,14 +711,20 @@ def test_wfs_getfeature_featureid_hello_1(self):
458
711
}.items ())])
459
712
460
713
response , headers = self ._get_fullaccess (query_string )
714
+ # The feature with `pk = 1` is in the response with the field 'color'
461
715
self .assertTrue (
462
716
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
463
717
"No result in GetFeature\n %s" % response )
464
718
self .assertTrue (
465
719
str (response ).find ("<qgs:color>red</qgs:color>" ) != - 1 , # spellok
466
720
"No color in result of GetFeature\n %s" % response )
721
+ # The feature with `pk = 2` is not in the response
722
+ self .assertFalse (
723
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
724
+ "Unexpected result in GetFeature\n %s" % response )
467
725
468
726
response , headers = self ._get_restricted (query_string )
727
+ # The feature with `pk = 1` is in the response without the field 'color'
469
728
self .assertTrue (
470
729
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
471
730
"No result in GetFeature\n %s" % response )
@@ -475,8 +734,16 @@ def test_wfs_getfeature_featureid_hello_1(self):
475
734
self .assertFalse (
476
735
str (response ).find ("<qgs:color>NULL</qgs:color>" ) != - 1 , # spellok
477
736
"Unexpected color NULL in result of GetFeature\n %s" % response )
737
+ # The feature with `pk = 2` is still not in the response
738
+ self .assertFalse (
739
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
740
+ "Unexpected result in GetFeature\n %s" % response )
478
741
479
- def test_wfs_getfeature_featureid_hello_2 (self ):
742
+ def test_wfs_getfeature_featureid_hello2 (self ):
743
+ """Tests WFS GetFeature Request on 'Hello' with FeatureId `Hello.2` and access control
744
+ The restricted access to 'Hello' is the expression `$id = 1`
745
+ The field 'color' has restricted access
746
+ """
480
747
query_string = "&" .join (["%s=%s" % i for i in list ({
481
748
"MAP" : urllib .parse .quote (self .projectPath ),
482
749
"SERVICE" : "WFS" ,
@@ -487,22 +754,36 @@ def test_wfs_getfeature_featureid_hello_2(self):
487
754
}.items ())])
488
755
489
756
response , headers = self ._get_fullaccess (query_string )
757
+ # The feature with `pk = 2` is in the response
490
758
self .assertTrue (
491
759
str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
492
760
"No result in GetFeature\n %s" % response )
761
+ # The feature with `pk = 1` is not in the response
493
762
self .assertFalse (
494
763
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
495
764
"Unexpected result in GetFeature\n %s" % response )
496
765
497
766
response , headers = self ._get_restricted (query_string )
767
+ # The feature with `pk = 2` is not in the response
498
768
self .assertFalse (
499
769
str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
500
770
"Unexpected result in GetFeature\n %s" % response )
501
771
self .assertFalse (
502
772
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
503
773
"Unexpected result in GetFeature\n %s" % response )
774
+ # The feature with `pk = 1` is still not in the response
775
+ self .assertFalse (
776
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
777
+ "Unexpected result in GetFeature\n %s" % response )
778
+ # No qgs feature Hello element
779
+ self .assertFalse (
780
+ str (response ).find ("<qgs:Hello " ) != - 1 ,
781
+ "Unexpected result in GetFeature\n %s" % response )
504
782
505
783
def test_wfs_getfeature_featureid_hello_filter (self ):
784
+ """Tests WFS GetFeature Request on 'Hello_Filter' with FeatureId `Hello_Filter.1` and access control
785
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
786
+ """
506
787
query_string = "&" .join (["%s=%s" % i for i in list ({
507
788
"MAP" : urllib .parse .quote (self .projectPath ),
508
789
"SERVICE" : "WFS" ,
@@ -513,22 +794,47 @@ def test_wfs_getfeature_featureid_hello_filter(self):
513
794
}.items ())])
514
795
515
796
response , headers = self ._get_fullaccess (query_string )
797
+ # The feature with `pk = 1` is in the response
516
798
self .assertTrue (
517
799
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
518
800
"No result in GetFeature\n %s" % response )
519
801
self .assertFalse (
520
802
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
521
803
"Unexpected result in GetFeature\n %s" % response )
804
+ # The feature with `pk = 6` is not in the response
805
+ self .assertFalse (
806
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
807
+ "Unexpected result in GetFeature\n %s" % response )
808
+ # The feature with `pk = 7` is not in the response
809
+ self .assertFalse (
810
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
811
+ "Unexpected result in GetFeature\n %s" % response )
522
812
523
813
response , headers = self ._get_restricted (query_string )
814
+ # The feature with `pk = 1` is not in the response
524
815
self .assertFalse (
525
816
str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
526
817
"Unexpected result in GetFeature\n %s" % response )
527
818
self .assertFalse (
528
819
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
529
820
"Unexpected result in GetFeature\n %s" % response )
821
+ # The feature with `pk = 6` is still not in the response
822
+ self .assertFalse (
823
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
824
+ "Unexpected result in GetFeature\n %s" % response )
825
+ # The feature with `pk = 7` is still not in the response
826
+ self .assertFalse (
827
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
828
+ "Unexpected result in GetFeature\n %s" % response )
829
+ # No qgs feature Hello_Filter element
830
+ self .assertFalse (
831
+ str (response ).find ("<qgs:Hello_Filter " ) != - 1 ,
832
+ "Unexpected result in GetFeature\n %s" % response )
530
833
531
834
def test_wfs_getfeature_featureid_hello_filter2 (self ):
835
+ """Tests WFS GetFeature Request on 'Hello_Filter' with FeatureId `Hello_Filter.6` and access control
836
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
837
+ """
532
838
query_string = "&" .join (["%s=%s" % i for i in list ({
533
839
"MAP" : urllib .parse .quote (self .projectPath ),
534
840
"SERVICE" : "WFS" ,
@@ -539,17 +845,202 @@ def test_wfs_getfeature_featureid_hello_filter2(self):
539
845
}.items ())])
540
846
541
847
response , headers = self ._get_fullaccess (query_string )
848
+ # The feature with `pk = 6` is in the response
849
+ self .assertTrue (
850
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
851
+ "No result in GetFeature\n %s" % response )
852
+ # The feature with `pk = 1` is not in the response
853
+ self .assertFalse (
854
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
855
+ "Unexpected result in GetFeature\n %s" % response )
856
+ # The feature with `pk = 7` is not in the response
857
+ self .assertFalse (
858
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
859
+ "Unexpected result in GetFeature\n %s" % response )
860
+
861
+ response , headers = self ._get_restricted (query_string )
862
+ # The feature with `pk = 6` is in the response
863
+ self .assertTrue (
864
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
865
+ "No result in GetFeature\n %s" % response )
866
+ # The feature with `pk = 1` is not in the response
867
+ self .assertFalse (
868
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
869
+ "Unexpected result in GetFeature\n %s" % response )
870
+ # The feature with `pk = 7` is not in the response
871
+ self .assertFalse (
872
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
873
+ "Unexpected result in GetFeature\n %s" % response )
874
+
875
+ # # ESRI Shapefile datasource # #
876
+
877
+ def test_wfs_getfeature_shp_featureid_hello (self ):
878
+ """Tests WFS GetFeature Request on 'Hello' with FeatureId `Hello.1` and access control
879
+ The datasource is an ESRI Shapefile
880
+ The restricted access to 'Hello' is the expression `$id = 1`
881
+ The field 'color' has restricted access
882
+ """
883
+ query_string = "&" .join (["%s=%s" % i for i in list ({
884
+ "MAP" : urllib .parse .quote (os .path .join (self .tmp_path , 'project_shp.qgs' )),
885
+ "SERVICE" : "WFS" ,
886
+ "VERSION" : "1.0.0" ,
887
+ "REQUEST" : "GetFeature" ,
888
+ "TYPENAME" : "Hello" ,
889
+ "FEATUREID" : "Hello.1"
890
+ }.items ())])
891
+
892
+ response , headers = self ._get_fullaccess (query_string )
893
+ # The feature with `pk = 2` is in the response with the field 'color'
894
+ self .assertTrue (
895
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
896
+ "No result in GetFeature\n %s" % response )
897
+ self .assertTrue (
898
+ str (response ).find ("<qgs:color>blue</qgs:color>" ) != - 1 , # spellok
899
+ "No color in result of GetFeature\n %s" % response )
900
+ # The feature with `pk = 1` is not in the response
901
+ self .assertFalse (
902
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
903
+ "Unexpected result in GetFeature\n %s" % response )
904
+
905
+ response , headers = self ._get_restricted (query_string )
906
+ # The feature with `pk = 2` is in the response without the field 'color'
907
+ self .assertTrue (
908
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
909
+ "No result in GetFeature\n %s" % response )
910
+ self .assertFalse (
911
+ str (response ).find ("<qgs:color>blue</qgs:color>" ) != - 1 , # spellok
912
+ "Unexpected color in result of GetFeature\n %s" % response )
913
+ self .assertFalse (
914
+ str (response ).find ("<qgs:color>NULL</qgs:color>" ) != - 1 , # spellok
915
+ "Unexpected color NULL in result of GetFeature\n %s" % response )
916
+ # The feature with `pk = 1` is still not in the response
917
+ self .assertFalse (
918
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
919
+ "Unexpected result in GetFeature\n %s" % response )
920
+
921
+ def test_wfs_getfeature_shp_featureid_hello2 (self ):
922
+ """Tests WFS GetFeature Request on 'Hello' with FeatureId `Hello.0` and access control
923
+ The datasource is an ESRI Shapefile
924
+ The restricted access to 'Hello' is the expression `$id = 1`
925
+ The field 'color' has restricted access
926
+ """
927
+ query_string = "&" .join (["%s=%s" % i for i in list ({
928
+ "MAP" : urllib .parse .quote (os .path .join (self .tmp_path , 'project_shp.qgs' )),
929
+ "SERVICE" : "WFS" ,
930
+ "VERSION" : "1.0.0" ,
931
+ "REQUEST" : "GetFeature" ,
932
+ "TYPENAME" : "Hello" ,
933
+ "FEATUREID" : "Hello.0"
934
+ }.items ())])
935
+
936
+ response , headers = self ._get_fullaccess (query_string )
937
+ # The feature with `pk = 1` is in the response
938
+ self .assertTrue (
939
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
940
+ "No result in GetFeature\n %s" % response )
941
+ # The feature with `pk = 2` is not in the response
942
+ self .assertFalse (
943
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
944
+ "Unexpected result in GetFeature\n %s" % response )
945
+
946
+ response , headers = self ._get_restricted (query_string )
947
+ # The feature with `pk = 1` is not in the response
948
+ self .assertFalse (
949
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
950
+ "Unexpected result in GetFeature\n %s" % response )
951
+ # The feature with `pk = 2` is still not in the response
952
+ self .assertFalse (
953
+ str (response ).find ("<qgs:pk>2</qgs:pk>" ) != - 1 ,
954
+ "Unexpected result in GetFeature\n %s" % response )
955
+ # No qgs feature Hello_Filter element
956
+ self .assertFalse (
957
+ str (response ).find ("<qgs:Hello " ) != - 1 ,
958
+ "Unexpected result in GetFeature\n %s" % response )
959
+
960
+ def test_wfs_getfeature_shp_featureid_hello_filter (self ):
961
+ """Tests WFS GetFeature Request on 'Hello_Filter' with FeatureId `Hello_Filter.1` and access control
962
+ The datasource is an ESRI Shapefile
963
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
964
+ """
965
+ query_string = "&" .join (["%s=%s" % i for i in list ({
966
+ "MAP" : urllib .parse .quote (os .path .join (self .tmp_path , 'project_shp.qgs' )),
967
+ "SERVICE" : "WFS" ,
968
+ "VERSION" : "1.0.0" ,
969
+ "REQUEST" : "GetFeature" ,
970
+ "TYPENAME" : "Hello_Filter" ,
971
+ "FEATUREID" : "Hello_Filter.0"
972
+ }.items ())])
973
+
974
+ response , headers = self ._get_fullaccess (query_string )
975
+ # The feature with `pk = 1` is in the response
976
+ self .assertTrue (
977
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
978
+ "No result in GetFeature\n %s" % response )
979
+ # The feature with `pk = 6` is not in the response
980
+ self .assertFalse (
981
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
982
+ "Unexpected result in GetFeature\n %s" % response )
983
+ # The feature with `pk = 7` is not in the response
984
+ self .assertFalse (
985
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
986
+ "Unexpected result in GetFeature\n %s" % response )
987
+
988
+ response , headers = self ._get_restricted (query_string )
989
+ # The feature with `pk = 1` is not in the response
990
+ self .assertFalse (
991
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
992
+ "Unexpected result in GetFeature\n %s" % response )
993
+ # The feature with `pk = 6` is still not in the response
994
+ self .assertFalse (
995
+ str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
996
+ "Unexpected result in GetFeature\n %s" % response )
997
+ # The feature with `pk = 7` is still not in the response
998
+ self .assertFalse (
999
+ str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
1000
+ "Unexpected result in GetFeature\n %s" % response )
1001
+ # No qgs feature Hello_Filter element
1002
+ self .assertFalse (
1003
+ str (response ).find ("<qgs:Hello_Filter " ) != - 1 ,
1004
+ "Unexpected result in GetFeature\n %s" % response )
1005
+
1006
+ def test_wfs_getfeature_shp_featureid_hello_filter2 (self ):
1007
+ """Tests WFS GetFeature Request on 'Hello_Filter' with FeatureId `Hello_Filter.5` and access control
1008
+ The datasource is an ESRI Shapefile
1009
+ The restricted access to 'Hello_Filter is the expression `pkuid = 6 or pkuid = 7`
1010
+ """
1011
+ query_string = "&" .join (["%s=%s" % i for i in list ({
1012
+ "MAP" : urllib .parse .quote (os .path .join (self .tmp_path , 'project_shp.qgs' )),
1013
+ "SERVICE" : "WFS" ,
1014
+ "VERSION" : "1.0.0" ,
1015
+ "REQUEST" : "GetFeature" ,
1016
+ "TYPENAME" : "Hello_Filter" ,
1017
+ "FEATUREID" : "Hello_Filter.5"
1018
+ }.items ())])
1019
+
1020
+ response , headers = self ._get_fullaccess (query_string )
1021
+ # The feature with `pk = 6` is in the response
542
1022
self .assertTrue (
543
1023
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
544
1024
"No result in GetFeature\n %s" % response )
1025
+ # The feature with `pk = 1` is not in the response
1026
+ self .assertFalse (
1027
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
1028
+ "Unexpected result in GetFeature\n %s" % response )
1029
+ # The feature with `pk = 7` is not in the response
545
1030
self .assertFalse (
546
1031
str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
547
1032
"Unexpected result in GetFeature\n %s" % response )
548
1033
549
1034
response , headers = self ._get_restricted (query_string )
1035
+ # The feature with `pk = 6` is in the response
550
1036
self .assertTrue (
551
1037
str (response ).find ("<qgs:pk>6</qgs:pk>" ) != - 1 ,
552
1038
"No result in GetFeature\n %s" % response )
1039
+ # The feature with `pk = 1` is not in the response
1040
+ self .assertFalse (
1041
+ str (response ).find ("<qgs:pk>1</qgs:pk>" ) != - 1 ,
1042
+ "Unexpected result in GetFeature\n %s" % response )
1043
+ # The feature with `pk = 7` is not in the response
553
1044
self .assertFalse (
554
1045
str (response ).find ("<qgs:pk>7</qgs:pk>" ) != - 1 ,
555
1046
"Unexpected result in GetFeature\n %s" % response )
0 commit comments