diff --git a/lib/cartodb/api/auth_api.js b/lib/cartodb/api/auth_api.js index 43f19d4e..bacccda7 100644 --- a/lib/cartodb/api/auth_api.js +++ b/lib/cartodb/api/auth_api.js @@ -70,6 +70,10 @@ AuthApi.prototype.authorizedByAPIKey = function(user, res, callback) { this.metadataBackend.getApikey(user, apikeyToken, (err, apikey) => { if (err) { + if (err.message && -1 !== err.message.indexOf('name not found')) { + err.http_status = 404; + } + return callback(err); } @@ -100,7 +104,7 @@ AuthApi.prototype.authorizedByAPIKey = function(user, res, callback) { error.subtype = 'api-key-username-mismatch'; error.http_status = 403; - return callback(error); + return callback(error); } if (!apikey.grantsMaps) { @@ -137,8 +141,8 @@ AuthApi.prototype.authorize = function(req, res, callback) { if (err) { return callback(err); - } - + } + callback(null, true); }); } @@ -147,17 +151,17 @@ AuthApi.prototype.authorize = function(req, res, callback) { if (err) { return callback(err); } - + if (isAuthorizedBySigner) { return this.pgConnection.setDBAuth(user, res.locals, 'master', function (err) { req.profiler.done('setDBAuth'); - + if (err) { return callback(err); - } + } callback(null, true); - }); + }); } // if no signer name was given, use default api key @@ -170,7 +174,7 @@ AuthApi.prototype.authorize = function(req, res, callback) { } callback(null, true); - }); + }); } // if signer name was given, return no authorization diff --git a/lib/cartodb/backends/pg_connection.js b/lib/cartodb/backends/pg_connection.js index e4f9700e..71ec2928 100644 --- a/lib/cartodb/backends/pg_connection.js +++ b/lib/cartodb/backends/pg_connection.js @@ -22,6 +22,9 @@ PgConnection.prototype.setDBAuth = function(username, params, apikeyType, callba if (apikeyType === 'master') { this.metadataBackend.getMasterApikey(username, (err, apikey) => { if (err) { + if (err.message && -1 !== err.message.indexOf('name not found')) { + err.http_status = 404; + } return callback(err); } @@ -39,6 +42,9 @@ PgConnection.prototype.setDBAuth = function(username, params, apikeyType, callba } else if (apikeyType === 'regular') { //Actually it can be any type of api key this.metadataBackend.getApikey(username, params.api_key, (err, apikey) => { if (err) { + if (err.message && -1 !== err.message.indexOf('name not found')) { + err.http_status = 404; + } return callback(err); } @@ -64,11 +70,14 @@ PgConnection.prototype.setDBAuth = function(username, params, apikeyType, callba return this.setDBAuth(username, params, 'default', callback); } - return callback(); + return callback(); }); } else if (apikeyType === 'default') { this.metadataBackend.getApikey(username, 'default_public', (err, apikey) => { if (err) { + if (err.message && -1 !== err.message.indexOf('name not found')) { + err.http_status = 404; + } return callback(err); }