Beispiel #1
0
 def _test_url(original_url, rewritten_url, env={}):
     self._set_env(env)
     request = QgsFcgiServerRequest()
     self.assertEqual(request.originalUrl().toString(), original_url)
     self.assertEqual(request.url().toString(), rewritten_url)
     # Check MAP
     if 'QUERY_STRING' in env:
         map = {k.upper(): v[0] for k, v in parse_qs(
             env['QUERY_STRING']).items()}['MAP']
     else:
         map = {k.upper(): v[0] for k, v in parse_qs(
             urlparse(env['REQUEST_URI']).query).items()}['MAP']
     self.assertEqual(request.parameter('MAP'), map)
Beispiel #2
0
 def test_fcgiRequestBody(self):
     """Test request body"""
     data = '<Literal>+1</Literal>'
     self._set_env({
         'SERVER_NAME': 'www.myserver.com',
         'SERVICE': 'WFS',
         'REQUEST_BODY': data,
         'CONTENT_LENGTH': str(len(data)),
         'REQUEST_METHOD': 'POST',
     })
     request = QgsFcgiServerRequest()
     response = QgsBufferServerResponse()
     self.server.handleRequest(request, response)
     self.assertEqual(request.parameter('REQUEST_BODY'),
                      '<Literal>+1</Literal>')
Beispiel #3
0
 def _test_url(url, env={}):
     for k in ('QUERY_STRING', 'REQUEST_URI', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME'):
         try:
             del os.environ[k]
         except KeyError:
             pass
         try:
             os.environ[k] = env[k]
         except KeyError:
             pass
     request = QgsFcgiServerRequest()
     self.assertEqual(request.url().toString(), url)
     # Check MAP
     if 'QUERY_STRING' in env:
         map = {k.upper(): v[0] for k, v in parse_qs(env['QUERY_STRING']).items()}['MAP']
     else:
         map = {k.upper(): v[0] for k, v in parse_qs(urlparse(env['REQUEST_URI']).query).items()}['MAP']
     self.assertEqual(request.parameter('MAP'), map)
Beispiel #4
0
        def _check_links(params, method='GET'):
            data = urlencode(params)
            if method == 'GET':
                env = {
                    'SERVER_NAME': 'www.myserver.com',
                    'REQUEST_URI': '/aproject/',
                    'QUERY_STRING': data,
                    'REQUEST_METHOD': 'GET',
                }
            else:
                env = {
                    'SERVER_NAME': 'www.myserver.com',
                    'REQUEST_URI': '/aproject/',
                    'REQUEST_BODY': data,
                    'CONTENT_LENGTH': str(len(data)),
                    'REQUEST_METHOD': 'POST',
                }

            self._set_env(env)
            request = QgsFcgiServerRequest()
            response = QgsBufferServerResponse()
            self.server.handleRequest(request, response)
            self.assertFalse(b'ServiceExceptionReport' in response.body())

            if method == 'POST':
                self.assertEqual(request.data(), data.encode('utf8'))
            else:
                original_url = request.originalUrl().toString()
                self.assertTrue(
                    original_url.startswith(
                        'http://www.myserver.com/aproject/'))
                self.assertEqual(
                    original_url.find(urlencode({'MAP': params['map']})), -1)

            exp = re.compile(r'href="([^"]+)"', re.DOTALL | re.MULTILINE)
            elems = exp.findall(bytes(response.body()).decode('utf8'))
            self.assertTrue(len(elems) > 0)
            for href in elems:
                self.assertTrue(
                    href.startswith('http://www.myserver.com/aproject/'))
                self.assertEqual(href.find(urlencode({'MAP': params['map']})),
                                 -1)
Beispiel #5
0
 def test_headers(self):
     """Tests that the headers are working in Fcgi mode"""
     for header, env, enum, value in (
         ("Host", "HTTP_HOST", QgsServerRequest.HOST, "example.com"),
         ("Forwarded", "HTTP_FORWARDED", QgsServerRequest.FORWARDED, "aaa"),
         ("X-Forwarded-For", "HTTP_X_FORWARDED_FOR",
          QgsServerRequest.X_FORWARDED_FOR, "bbb"),
         ("X-Forwarded-Host", "HTTP_X_FORWARDED_HOST",
          QgsServerRequest.X_FORWARDED_HOST, "ccc"),
         ("X-Forwarded-Proto", "HTTP_X_FORWARDED_PROTO",
          QgsServerRequest.X_FORWARDED_PROTO, "ddd"),
         ("X-Qgis-Service-Url", "HTTP_X_QGIS_SERVICE_URL",
          QgsServerRequest.X_QGIS_SERVICE_URL, "eee"),
         ("X-Qgis-Wms-Service-Url", "HTTP_X_QGIS_WMS_SERVICE_URL",
          QgsServerRequest.X_QGIS_WMS_SERVICE_URL, "fff"),
         ("X-Qgis-Wfs-Service-Url", "HTTP_X_QGIS_WFS_SERVICE_URL",
          QgsServerRequest.X_QGIS_WFS_SERVICE_URL, "ggg"),
         ("X-Qgis-Wcs-Service-Url", "HTTP_X_QGIS_WCS_SERVICE_URL",
          QgsServerRequest.X_QGIS_WCS_SERVICE_URL, "hhh"),
         ("X-Qgis-Wmts-Service-Url", "HTTP_X_QGIS_WMTS_SERVICE_URL",
          QgsServerRequest.X_QGIS_WMTS_SERVICE_URL, "iii"),
         ("Accept", "HTTP_ACCEPT", QgsServerRequest.ACCEPT, "jjj"),
         ("User-Agent", "HTTP_USER_AGENT", QgsServerRequest.USER_AGENT,
          "kkk"),
         ("Authorization", "HTTP_AUTHORIZATION",
          QgsServerRequest.AUTHORIZATION, "lll"),
     ):
         try:
             os.environ[env] = value
             request = QgsFcgiServerRequest()
             self.assertEquals(request.headers(), {header: value})
             request = QgsServerRequest(request)
             self.assertEquals(request.headers(), {header: value})
             self.assertEquals(request.header(enum), value)
         finally:
             del os.environ[env]