Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Return 501 on 'OperationNotSupported' error
  • Loading branch information
dmarteau committed Apr 11, 2019
1 parent fdb82fc commit 9d5fa5b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/server/services/wcs/qgswcs.cpp
Expand Up @@ -74,7 +74,7 @@ namespace QgsWcs
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

if ( QSTR_COMPARE( req, "GetCapabilities" ) )
Expand All @@ -93,7 +93,7 @@ namespace QgsWcs
{
// Operation not supported
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wfs/qgswfs.cpp
Expand Up @@ -78,7 +78,7 @@ namespace QgsWfs
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

if ( QSTR_COMPARE( req, "GetCapabilities" ) )
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace QgsWfs
{
// Operation not supported
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/server/services/wms/qgswms.cpp
Expand Up @@ -90,8 +90,8 @@ namespace QgsWms
const QString req = parameters.request();
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
throw QgsServiceException( QgsServiceException::OGC_OPERATION_NOT_SUPPORTED,
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

if ( ( mVersion.compare( QLatin1String( "1.1.1" ) ) == 0 \
Expand Down Expand Up @@ -153,8 +153,8 @@ namespace QgsWms
else
{
// Operation not supported
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QString( "Request %1 is not supported" ).arg( req ) );
throw QgsServiceException( QgsServiceException::OGC_OPERATION_NOT_SUPPORTED,
QString( "Request %1 is not supported" ).arg( req ), 501 );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wmts/qgswmts.cpp
Expand Up @@ -72,7 +72,7 @@ namespace QgsWmts
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

if ( QSTR_COMPARE( req, "GetCapabilities" ) )
Expand All @@ -91,7 +91,7 @@ namespace QgsWmts
{
// Operation not supported
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/src/python/test_qgsserver.py
Expand Up @@ -262,6 +262,12 @@ def _execute_request_project(self, qs, project, requestMethod=QgsServerRequest.G
headers.append(("%s: %s" % (k, rh[k])).encode('utf-8'))
return b"\n".join(headers) + b"\n\n", bytes(response.body())

def _assert_status_code(self, status_code, qs, requestMethod=QgsServerRequest.GetMethod, data=None, project=None):
request = QgsBufferServerRequest(qs, requestMethod, {}, data)
response = QgsBufferServerResponse()
self.server.handleRequest(request, response, project)
assert response.statusCode() == status_code, "%s != %s" % (response.statusCode(), status_code)


class TestQgsServerTestBase(unittest.TestCase):

Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_qgsserver_wfs.py
Expand Up @@ -92,6 +92,10 @@ def wfs_request_compare(self,
query_string, request))
return header, body

def test_operation_not_supported(self):
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.1.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
self._assert_status_code(501, qs)

def test_project_wfs(self):
"""Test some WFS request"""
for request in ('GetCapabilities', 'DescribeFeatureType'):
Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -88,6 +88,10 @@ def test_getprojectsettings(self):
def test_getcontext(self):
self.wms_request_compare('GetContext')

def test_operation_not_supported(self):
qs = '?MAP=%s&SERVICE=WMS&VERSION=1.3.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
self._assert_status_code(501, qs)

def test_describelayer(self):
# Test DescribeLayer
self.wms_request_compare('DescribeLayer',
Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_qgsserver_wmts.py
Expand Up @@ -78,6 +78,10 @@ def wmts_request_compare(self, request, version='', extra_query_string='', refer

self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s" % (query_string, request))

def test_operation_not_supported(self):
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.0.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
self._assert_status_code(501, qs)

def test_project_wmts(self):
"""Test some WMTS request"""
for request in ('GetCapabilities',):
Expand Down

0 comments on commit 9d5fa5b

Please sign in to comment.