Skip to content

Commit 6cb9997

Browse files
committedAug 24, 2018
[Server][Feature][needs-docs] Enhancing WMTS GetTile parameters check with tests
1 parent ba24653 commit 6cb9997

File tree

2 files changed

+94
-15
lines changed

2 files changed

+94
-15
lines changed
 

‎src/server/services/wmts/qgswmtsutils.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,7 @@ namespace QgsWmts
601601
//difining TileMatrix idx
602602
int tm_idx = params.tileMatrixAsInt();
603603
//read TileMatrix
604-
if ( tm_idx == -1 )
605-
{
606-
throw QgsRequestNotWellFormedException( QStringLiteral( "TileMatrix is mandatory" ) );
607-
}
608-
if ( tms.tileMatrixList.count() < tm_idx )
604+
if ( tm_idx < 0 || tms.tileMatrixList.count() < tm_idx )
609605
{
610606
throw QgsRequestNotWellFormedException( QStringLiteral( "TileMatrix is unknown" ) );
611607
}
@@ -614,23 +610,15 @@ namespace QgsWmts
614610
//defining TileRow
615611
int tr = params.tileRowAsInt();
616612
//read TileRow
617-
if ( tr == -1 )
618-
{
619-
throw QgsRequestNotWellFormedException( QStringLiteral( "TileRow is mandatory" ) );
620-
}
621-
if ( tm.row <= tr )
613+
if ( tr < 0 || tm.row <= tr )
622614
{
623615
throw QgsRequestNotWellFormedException( QStringLiteral( "TileRow is unknown" ) );
624616
}
625617

626618
//defining TileCol
627619
int tc = params.tileColAsInt();
628620
//read TileCol
629-
if ( tc == -1 )
630-
{
631-
throw QgsRequestNotWellFormedException( QStringLiteral( "TileCol is mandatory" ) );
632-
}
633-
if ( tm.col <= tc )
621+
if ( tc < 0 || tm.col <= tc )
634622
{
635623
throw QgsRequestNotWellFormedException( QStringLiteral( "TileCol is unknown" ) );
636624
}

‎tests/src/python/test_qgsserver_wmts.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,97 @@ def test_wmts_gettile(self):
190190
r, h = self._result(self._execute_request(qs))
191191
self._img_diff_error(r, h, "WMTS_GetTile_Hello_4326_0", 20000)
192192

193+
def test_wmts_gettile_invalid_parameters(self):
194+
qs = "?" + "&".join(["%s=%s" % i for i in list({
195+
"MAP": urllib.parse.quote(self.projectGroupsPath),
196+
"SERVICE": "WMTS",
197+
"VERSION": "1.0.0",
198+
"REQUEST": "GetTile",
199+
"LAYER": "Hello",
200+
"STYLE": "",
201+
"TILEMATRIXSET": "EPSG:3857",
202+
"TILEMATRIX": "0",
203+
"TILEROW": "0",
204+
"TILECOL": "FOO",
205+
"FORMAT": "image/png"
206+
}.items())])
207+
208+
r, h = self._result(self._execute_request(qs))
209+
err = b"TILECOL (\'FOO\') cannot be converted into int" in r
210+
self.assertTrue(err)
211+
212+
qs = "?" + "&".join(["%s=%s" % i for i in list({
213+
"MAP": urllib.parse.quote(self.projectGroupsPath),
214+
"SERVICE": "WMTS",
215+
"VERSION": "1.0.0",
216+
"REQUEST": "GetTile",
217+
"LAYER": "Hello",
218+
"STYLE": "",
219+
"TILEMATRIXSET": "EPSG:3857",
220+
"TILEMATRIX": "0",
221+
"TILEROW": "0",
222+
"TILECOL": "1",
223+
"FORMAT": "image/png"
224+
}.items())])
225+
226+
r, h = self._result(self._execute_request(qs))
227+
err = b"TileCol is unknown" in r
228+
self.assertTrue(err)
229+
230+
qs = "?" + "&".join(["%s=%s" % i for i in list({
231+
"MAP": urllib.parse.quote(self.projectGroupsPath),
232+
"SERVICE": "WMTS",
233+
"VERSION": "1.0.0",
234+
"REQUEST": "GetTile",
235+
"LAYER": "Hello",
236+
"STYLE": "",
237+
"TILEMATRIXSET": "EPSG:3857",
238+
"TILEMATRIX": "0",
239+
"TILEROW": "0",
240+
"TILECOL": "-1",
241+
"FORMAT": "image/png"
242+
}.items())])
243+
244+
r, h = self._result(self._execute_request(qs))
245+
err = b"TileCol is unknown" in r
246+
self.assertTrue(err)
247+
248+
qs = "?" + "&".join(["%s=%s" % i for i in list({
249+
"MAP": urllib.parse.quote(self.projectGroupsPath),
250+
"SERVICE": "WMTS",
251+
"VERSION": "1.0.0",
252+
"REQUEST": "GetTile",
253+
"LAYER": "dem",
254+
"STYLE": "",
255+
"TILEMATRIXSET": "EPSG:3857",
256+
"TILEMATRIX": "0",
257+
"TILEROW": "0",
258+
"TILECOL": "0",
259+
"FORMAT": "image/png"
260+
}.items())])
261+
262+
r, h = self._result(self._execute_request(qs))
263+
err = b"Layer \'dem\' not found" in r
264+
self.assertTrue(err)
265+
266+
qs = "?" + "&".join(["%s=%s" % i for i in list({
267+
"MAP": urllib.parse.quote(self.projectGroupsPath),
268+
"SERVICE": "WMTS",
269+
"VERSION": "1.0.0",
270+
"REQUEST": "GetTile",
271+
"LAYER": "Hello",
272+
"STYLE": "",
273+
"TILEMATRIXSET": "EPSG:2154",
274+
"TILEMATRIX": "0",
275+
"TILEROW": "0",
276+
"TILECOL": "0",
277+
"FORMAT": "image/png"
278+
}.items())])
279+
280+
r, h = self._result(self._execute_request(qs))
281+
err = b"TileMatrixSet is unknown" in r
282+
self.assertTrue(err)
283+
193284

194285
if __name__ == '__main__':
195286
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.