|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsServer. |
| 3 | +
|
| 4 | +.. note:: This program is free software; you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation; either version 2 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +""" |
| 9 | +__author__ = 'Stephane Brunner' |
| 10 | +__date__ = '28/08/2015' |
| 11 | +__copyright__ = 'Copyright 2015, The QGIS Project' |
| 12 | +# This will get replaced with a git SHA1 when you do a git archive |
| 13 | +__revision__ = '$Format:%H$' |
| 14 | + |
| 15 | +print('CTEST_FULL_OUTPUT') |
| 16 | + |
| 17 | +import qgis # NOQA |
| 18 | + |
| 19 | +import os |
| 20 | +from shutil import copyfile |
| 21 | +from math import sqrt |
| 22 | +from qgis.testing import unittest |
| 23 | +from utilities import unitTestDataPath |
| 24 | +from osgeo import gdal |
| 25 | +from osgeo.gdalconst import GA_ReadOnly |
| 26 | +from qgis.server import QgsServer, QgsAccessControlFilter, QgsServerRequest, QgsBufferServerRequest, QgsBufferServerResponse |
| 27 | +from qgis.core import QgsRenderChecker, QgsApplication |
| 28 | +from qgis.PyQt.QtCore import QSize |
| 29 | +import tempfile |
| 30 | +import urllib.request |
| 31 | +import urllib.parse |
| 32 | +import urllib.error |
| 33 | +import base64 |
| 34 | +from test_qgsserver_accesscontrol import TestQgsServerAccessControl |
| 35 | + |
| 36 | + |
| 37 | +class TestQgsServerAccessControlWMSGetlegendgraphic(TestQgsServerAccessControl): |
| 38 | + |
| 39 | + def test_wms_getlegendgraphic_hello(self): |
| 40 | + query_string = "&".join(["%s=%s" % i for i in list({ |
| 41 | + "MAP": urllib.parse.quote(self.projectPath), |
| 42 | + "SERVICE": "WMS", |
| 43 | + "VERSION": "1.1.1", |
| 44 | + "REQUEST": "GetLegendGraphic", |
| 45 | + "LAYERS": "Hello", |
| 46 | + "FORMAT": "image/png" |
| 47 | + }.items())]) |
| 48 | + |
| 49 | + response, headers = self._get_fullaccess(query_string) |
| 50 | + self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Hello", 250, QSize(10, 10)) |
| 51 | + |
| 52 | + response, headers = self._get_restricted(query_string) |
| 53 | + self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Hello", 250, QSize(10, 10)) |
| 54 | + |
| 55 | + def test_wms_getlegendgraphic_country(self): |
| 56 | + query_string = "&".join(["%s=%s" % i for i in list({ |
| 57 | + "MAP": urllib.parse.quote(self.projectPath), |
| 58 | + "SERVICE": "WMS", |
| 59 | + "VERSION": "1.1.1", |
| 60 | + "REQUEST": "GetLegendGraphic", |
| 61 | + "LAYERS": "Country", |
| 62 | + "FORMAT": "image/png" |
| 63 | + }.items())]) |
| 64 | + |
| 65 | + response, headers = self._get_fullaccess(query_string) |
| 66 | + self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Country", 250, QSize(10, 10)) |
| 67 | + |
| 68 | + response, headers = self._get_restricted(query_string) |
| 69 | + self.assertEqual( |
| 70 | + headers.get("Content-Type"), "text/xml; charset=utf-8", |
| 71 | + "Content type for GetMap is wrong: %s" % headers.get("Content-Type")) |
| 72 | + self.assertTrue( |
| 73 | + str(response).find('<ServiceException code="Security">') != -1, |
| 74 | + "Not allowed GetLegendGraphic" |
| 75 | + ) |
| 76 | + |
| 77 | + def test_wms_getlegendgraphic_country_grp(self): |
| 78 | + query_string = "&".join(["%s=%s" % i for i in list({ |
| 79 | + "MAP": urllib.parse.quote(self.projectPath), |
| 80 | + "SERVICE": "WMS", |
| 81 | + "VERSION": "1.1.1", |
| 82 | + "REQUEST": "GetLegendGraphic", |
| 83 | + "LAYERS": "Country_grp", |
| 84 | + "FORMAT": "image/png" |
| 85 | + }.items())]) |
| 86 | + |
| 87 | + response, headers = self._get_fullaccess(query_string) |
| 88 | + self._img_diff_error(response, headers, "WMS_GetLegendGraphic_Country", 250, QSize(10, 10)) |
| 89 | + |
| 90 | + response, headers = self._get_restricted(query_string) |
| 91 | + self.assertEqual( |
| 92 | + headers.get("Content-Type"), "text/xml; charset=utf-8", |
| 93 | + "Content type for GetMap is wrong: %s" % headers.get("Content-Type")) |
| 94 | + self.assertTrue( |
| 95 | + str(response).find('<ServiceException code="Security">') != -1, |
| 96 | + "Not allowed GetLegendGraphic" |
| 97 | + ) |
| 98 | + |
| 99 | +if __name__ == "__main__": |
| 100 | + unittest.main() |
0 commit comments