Skip to content

Commit

Permalink
Merge pull request #5206 from rldhont/fix-getfeature-error-from-qgis-…
Browse files Browse the repository at this point in the history
…server

[Fix] WFS GetFeature request to QGIS Server returns error
  • Loading branch information
rldhont authored Jan 15, 2025
2 parents d833f6b + 62fd944 commit a308f29
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lizmap/modules/lizmap/controllers/service.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ protected function GetFeature($wfsRequest)
$this->setupBinaryResponse($rep, $result, 'qgis_server_wfs');

if ($result->code >= 400) {
$rep->content = $result->getBodyAsString();

return $rep;
}

Expand Down
1 change: 1 addition & 0 deletions lizmap/modules/lizmap/lib/Request/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ public static function getRemoteDataAsStream($url, $options = null)

$reqOptions = array(
'stream' => true,
'http_errors' => false,
);
$services = self::getServices();
if ($services->requestProxyEnabled && $services->requestProxyHost != '') {
Expand Down
11 changes: 6 additions & 5 deletions tests/end2end/cypress/integration/cmdline-wmts-ghaction.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { clearErrorsLog } from './../support/function.js'
describe('WMTS command line', function () {

it('wmts:capabilities success', function () {
Expand Down Expand Up @@ -210,7 +211,7 @@ describe('WMTS command line', function () {
})

// Clear errors
cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
clearErrorsLog()
})

it('wmts:cache:seed failed', function () {
Expand Down Expand Up @@ -274,29 +275,29 @@ describe('WMTS command line', function () {


// Clear errors
cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
clearErrorsLog()

cy.exec('./../lizmap-ctl console wmts:cache:seed -v -f --dry-run testsrepository cache unknown EPSG:3857 10 10', {failOnNonZeroExit: false})
.then((result) => {
expect(result.code).to.equal(1)
expect(result.stdout).to.contain('The layers \'unknown\' have not be found!')
})

cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
clearErrorsLog()
cy.exec('./../lizmap-ctl console wmts:cache:seed -v -f --dry-run testsrepository cache Quartiers unknown 10 10', {failOnNonZeroExit: false})
.then((result) => {
expect(result.code).to.equal(1)
expect(result.stdout).to.contain("The TileMatrixSet 'EPSG:3857'!\nThe TileMatrixSet 'unknown' has not be found!")
})

cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
clearErrorsLog()
cy.exec('./../lizmap-ctl console wmts:cache:seed -v -f --dry-run --bbox xmin,ymin,xmax,ymax testsrepository cache Quartiers EPSG:3857 10 10', {failOnNonZeroExit: false})
.then((result) => {
expect(result.code).to.equal(1)
expect(result.stdout).to.contain("The TileMatrixSet 'EPSG:3857'!\nThe optional bbox has to contain 4 numbers separated by comma!")
})

cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
clearErrorsLog()
cy.exec('./../lizmap-ctl console wmts:cache:seed -v -f --dry-run --bbox 417094.94691622,5398163.2080343 testsrepository cache Quartiers EPSG:3857 10 10', {failOnNonZeroExit: false})
.then((result) => {
expect(result.code).to.equal(1)
Expand Down
34 changes: 34 additions & 0 deletions tests/end2end/cypress/integration/requests-wfs-ghaction.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { clearErrorsLog, clearLizmapAdminLog } from './../support/function.js'
describe('Request service', function () {
it('WFS GetCapabilities', function () {
cy.request('/index.php/lizmap/service/?repository=testsrepository&project=selection&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetCapabilities')
Expand Down Expand Up @@ -1017,6 +1018,7 @@ describe('Request service', function () {
'FEATUREID': 'selection_polygon.1',
'BBOX': '160786,900949,186133,925344',
'OUTPUTFORMAT': 'GeoJSON',
'FORCE_QGIS': '1',
},
}).then((resp) => {
expect(resp.status).to.eq(200)
Expand Down Expand Up @@ -1220,6 +1222,38 @@ describe('Request service', function () {
})
})

it('WFS GetFeature FAILED && FORCE_QGIS', function () {
clearLizmapAdminLog()
cy.request({
method: 'POST',
url: '/index.php/lizmap/service/?repository=testsrepository&project=selection',
qs: {
'SERVICE': 'WFS',
'VERSION': '1.0.0',
'REQUEST': 'GetFeature',
'TYPENAME': 'selection_polygon',
'EXP_FILTER': '\'tref\'+pipe(2)',
'FORCE_QGIS': '1'
},
failOnStatusCode: false,
}).then((resp) => {
expect(resp.status).to.eq(400)
expect(resp.headers['content-type']).to.contain('text/xml')
expect(resp.body).to.contain('ServiceException')
expect(resp.body).to.contain('code="RequestNotWellFormed"')

// Check errors
cy.exec('./../lizmap-ctl docker-exec cat /srv/lzm/lizmap/var/log/lizmap-admin.log', {failOnNonZeroExit: false})
.then((result) => {
expect(result.code).to.eq(0)
expect(result.stdout).to.contain('An HTTP request ended with an error, please check the main error log.')
expect(result.stdout).to.contain('HTTP code 400')
clearLizmapAdminLog()
})
clearErrorsLog()
})
})

it('Version parameter is mandatory except for GetCapabilities request', function () {
cy.request({
method: 'POST',
Expand Down
20 changes: 20 additions & 0 deletions tests/end2end/cypress/support/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ export function arrayBufferToBase64(buffer) {
return window.btoa(binary);
};

export function rmErrorsLog() {
// Remove errors log
cy.exec('./../lizmap-ctl docker-exec rm -f /srv/lzm/lizmap/var/log/errors.log', {failOnNonZeroExit: false})
}

export function clearErrorsLog() {
// Clear errors log
cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
}

export function rmLizmapAdminLog() {
// Remove errors log
cy.exec('./../lizmap-ctl docker-exec rm -f /srv/lzm/lizmap/var/log/errors.log', {failOnNonZeroExit: false})
}

export function clearLizmapAdminLog() {
// Clear errors log
cy.exec('./../lizmap-ctl docker-exec truncate -s 0 /srv/lzm/lizmap/var/log/errors.log')
}

export function serverMetadata() {

return cy.request ({
Expand Down
3 changes: 2 additions & 1 deletion tests/end2end/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

// Import commands.js using ES2015 syntax:
import './commands'
import { rmErrorsLog } from './function'

beforeEach(function () {
// Clear errors
cy.exec('./../lizmap-ctl docker-exec rm -f /srv/lzm/lizmap/var/log/errors.log', {failOnNonZeroExit: false})
rmErrorsLog()
})

afterEach(function () {
Expand Down

0 comments on commit a308f29

Please sign in to comment.