From 9278c1682df4d9a4ce17f3b942098cabfc9825d5 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 13 Nov 2013 13:00:56 +0100 Subject: [PATCH] Fix http status on database authentication errors (#94) --- NEWS.md | 1 + lib/windshaft/server.js | 9 ++++++++- test/acceptance/server.js | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index b77805cad..ef9e436d6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ Version 0.14.3-dev 2013-MM-DD - Return CORS headers when creating layergroups via GET (#92) + - Fix http status on database authentication error (#94) Version 0.14.2 2013-11-08 diff --git a/lib/windshaft/server.js b/lib/windshaft/server.js index 5d4b11e80..ef8730b86 100644 --- a/lib/windshaft/server.js +++ b/lib/windshaft/server.js @@ -445,8 +445,15 @@ console.log("getRenderer ERROR: "); console.dir(err); if ( -1 != errMsg.indexOf('permission denied') ) { statusCode = 401; } + else if ( -1 != errMsg.indexOf('authentication failed') ) { + statusCode = 401; + } else if ( -1 != errMsg.indexOf('does not exist') ) { - statusCode = 404; + if ( -1 != errMsg.indexOf(' role ') ) { + statusCode = 401; // role 'xxx' does not exist + } else { + statusCode = 404; + } } // Rewrite mapnik parsing errors to start with layer number diff --git a/test/acceptance/server.js b/test/acceptance/server.js index 55382cdfa..d76ab031d 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -479,7 +479,7 @@ suite('server', function() { method: 'GET' },{ }, function(res) { - assert.equal(res.statusCode, 404, res.statusCode + ( res.statusCode != 200 ? ( ": " + res.body ) : '' )); + assert.equal(res.statusCode, 401, res.statusCode + ( res.statusCode != 200 ? ( ": " + res.body ) : '' )); // TODO: also test that a new request with no overrideDBUser gets permission to access the tile ? done(); });