Skip to content

Commit

Permalink
[Server][Feature][needs-docs] Enhancing WMTS GetTile parameters check…
Browse files Browse the repository at this point in the history
… with tests
  • Loading branch information
rldhont committed Aug 24, 2018
1 parent ba24653 commit 6cb9997
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/server/services/wmts/qgswmtsutils.cpp
Expand Up @@ -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" ) );
}
Expand All @@ -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" ) );
}
Expand Down
91 changes: 91 additions & 0 deletions tests/src/python/test_qgsserver_wmts.py
Expand Up @@ -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.