Skip to content
Permalink
Browse files

[Server][Feature][needs-docs] Enhancing WMTS GetTile parameters check…

… with tests
  • Loading branch information
rldhont committed Aug 24, 2018
1 parent ba24653 commit 6cb9997a0d183e4cbb7a9ae4451d4a9310e6e7fa
Showing with 94 additions and 15 deletions.
  1. +3 −15 src/server/services/wmts/qgswmtsutils.cpp
  2. +91 −0 tests/src/python/test_qgsserver_wmts.py
@@ -601,11 +601,7 @@ namespace QgsWmts
//difining TileMatrix idx
int tm_idx = params.tileMatrixAsInt();
//read TileMatrix
if ( tm_idx == -1 )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TileMatrix is mandatory" ) );
}
if ( tms.tileMatrixList.count() < tm_idx )
if ( tm_idx < 0 || tms.tileMatrixList.count() < tm_idx )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TileMatrix is unknown" ) );
}
@@ -614,23 +610,15 @@ namespace QgsWmts
//defining TileRow
int tr = params.tileRowAsInt();
//read TileRow
if ( tr == -1 )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TileRow is mandatory" ) );
}
if ( tm.row <= tr )
if ( tr < 0 || tm.row <= tr )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TileRow is unknown" ) );
}

//defining TileCol
int tc = params.tileColAsInt();
//read TileCol
if ( tc == -1 )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TileCol is mandatory" ) );
}
if ( tm.col <= tc )
if ( tc < 0 || tm.col <= tc )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "TileCol is unknown" ) );
}
@@ -190,6 +190,97 @@ def test_wmts_gettile(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMTS_GetTile_Hello_4326_0", 20000)

def test_wmts_gettile_invalid_parameters(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMTS",
"VERSION": "1.0.0",
"REQUEST": "GetTile",
"LAYER": "Hello",
"STYLE": "",
"TILEMATRIXSET": "EPSG:3857",
"TILEMATRIX": "0",
"TILEROW": "0",
"TILECOL": "FOO",
"FORMAT": "image/png"
}.items())])

r, h = self._result(self._execute_request(qs))
err = b"TILECOL (\'FOO\') cannot be converted into int" in r
self.assertTrue(err)

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMTS",
"VERSION": "1.0.0",
"REQUEST": "GetTile",
"LAYER": "Hello",
"STYLE": "",
"TILEMATRIXSET": "EPSG:3857",
"TILEMATRIX": "0",
"TILEROW": "0",
"TILECOL": "1",
"FORMAT": "image/png"
}.items())])

r, h = self._result(self._execute_request(qs))
err = b"TileCol is unknown" in r
self.assertTrue(err)

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMTS",
"VERSION": "1.0.0",
"REQUEST": "GetTile",
"LAYER": "Hello",
"STYLE": "",
"TILEMATRIXSET": "EPSG:3857",
"TILEMATRIX": "0",
"TILEROW": "0",
"TILECOL": "-1",
"FORMAT": "image/png"
}.items())])

r, h = self._result(self._execute_request(qs))
err = b"TileCol is unknown" in r
self.assertTrue(err)

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMTS",
"VERSION": "1.0.0",
"REQUEST": "GetTile",
"LAYER": "dem",
"STYLE": "",
"TILEMATRIXSET": "EPSG:3857",
"TILEMATRIX": "0",
"TILEROW": "0",
"TILECOL": "0",
"FORMAT": "image/png"
}.items())])

r, h = self._result(self._execute_request(qs))
err = b"Layer \'dem\' not found" in r
self.assertTrue(err)

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMTS",
"VERSION": "1.0.0",
"REQUEST": "GetTile",
"LAYER": "Hello",
"STYLE": "",
"TILEMATRIXSET": "EPSG:2154",
"TILEMATRIX": "0",
"TILEROW": "0",
"TILECOL": "0",
"FORMAT": "image/png"
}.items())])

r, h = self._result(self._execute_request(qs))
err = b"TileMatrixSet is unknown" in r
self.assertTrue(err)


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

0 comments on commit 6cb9997

Please sign in to comment.
You can’t perform that action at this time.