Skip to content

Commit

Permalink
Fix http status on database authentication errors (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli committed Nov 13, 2013
1 parent ebf8f85 commit 9278c16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/windshaft/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 9278c16

Please sign in to comment.