From bf340e684af8bf1d63442c8f81c6054e36bed3da Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 11 Nov 2013 15:56:58 +0100 Subject: [PATCH] Tweak error messages on missing redis variables, update tests --- lib/cartodb/carto_data.js | 21 ++++++++++----------- test/acceptance/server.js | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/cartodb/carto_data.js b/lib/cartodb/carto_data.js index ead03b3a..538dd6f4 100644 --- a/lib/cartodb/carto_data.js +++ b/lib/cartodb/carto_data.js @@ -26,6 +26,9 @@ module.exports = function() { tagged_mapview_key: "user:<%= username %>:mapviews:stat_tag:<%= stat_tag %>" }; + me.userFromHostname = function(hostname) { + return hostname.split('.')[0]; + } /** * Get the database name for this particular subdomain/username @@ -35,22 +38,18 @@ module.exports = function() { */ me.getDatabase = function(req, callback) { // strip subdomain from header host - var username = req.headers.host.split('.')[0] + var username = me.userFromHostname(req.headers.host); var redisKey = _.template(this.user_key, {username: username}); this.retrieve(this.user_metadata_db, redisKey, 'database_name', function(err, dbname) { if ( err ) callback(err, null); else if ( dbname === null ) { - callback(new Error("missing " + username + "'s dbname in redis (try CARTODB/script/restore_redis)"), null); + callback(new Error("missing " + username + "'s database_name in redis (try CARTODB/script/restore_redis)"), null); } else callback(err, dbname); }); }; - me.userFromHostname = function(hostname) { - return hostname.split('.')[0]; - } - /** * Increment mapview count for a user * @@ -88,13 +87,13 @@ module.exports = function() { */ me.getId= function(req, callback) { // strip subdomain from header host - var username = req.headers.host.split('.')[0]; + var username = me.userFromHostname(req.headers.host); var redisKey = _.template(this.user_key, {username: username}); this.retrieve(this.user_metadata_db, redisKey, 'id', function(err, dbname) { if ( err ) callback(err, null); else if ( dbname === null ) { - callback(new Error("missing " + username + "'s dbuser in redis (try CARTODB/script/restore_redis)"), null); + callback(new Error("missing " + username + "'s id in redis (try CARTODB/script/restore_redis)"), null); } else callback(err, dbname); }); @@ -108,13 +107,13 @@ module.exports = function() { */ me.getDatabaseHost= function(req, callback) { // strip subdomain from header host - var username = req.headers.host.split('.')[0]; + var username = me.userFromHostname(req.headers.host); var redisKey = _.template(this.user_key, {username: username}); this.retrieve(this.user_metadata_db, redisKey, 'database_host', function(err, dbname) { if ( err ) callback(err, null); else if ( dbname === null ) { - callback(new Error("missing " + username + "'s dbuser in redis (try CARTODB/script/restore_redis)"), null); + callback(new Error("missing " + username + "'s database_host in redis (try CARTODB/script/restore_redis)"), null); } else callback(err, dbname); }); @@ -128,7 +127,7 @@ module.exports = function() { */ me.checkMapKey = function(req, callback) { // strip subdomain from header host - var username = req.headers.host.split('.')[0]; + var username = me.userFromHostname(req.headers.host); var redisKey = "rails:users:" + username; this.retrieve(this.user_metadata_db, redisKey, "map_key", function(err, val) { var valid = 0; diff --git a/test/acceptance/server.js b/test/acceptance/server.js index fdfa2c50..465d6774 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -140,7 +140,7 @@ suite('server', function() { // FIXME: should be 401 Unauthorized assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.deepEqual(JSON.parse(res.body), - {error:"missing unknown_user's dbname in redis (try CARTODB/script/restore_redis)"}); + {error:"missing unknown_user's database_name in redis (try CARTODB/script/restore_redis)"}); done(); }); }); @@ -493,7 +493,7 @@ suite('server', function() { // FIXME: should be 401 Unauthorized assert.equal(res.statusCode, 500, res.statusCode + ': ' + res.body); assert.deepEqual(JSON.parse(res.body), - {error:"missing unknown_user's dbname in redis (try CARTODB/script/restore_redis)"}); + {error:"missing unknown_user's database_name in redis (try CARTODB/script/restore_redis)"}); done(); }); }); @@ -576,7 +576,7 @@ suite('server', function() { // FIXME: should be 401 Unauthorized assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.deepEqual(JSON.parse(res.body), - {error:"missing unknown_user's dbname in redis (try CARTODB/script/restore_redis)"}); + {error:"missing unknown_user's database_name in redis (try CARTODB/script/restore_redis)"}); done(); }); }); @@ -727,7 +727,7 @@ suite('server', function() { // FIXME: should be 401 Unauthorized assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.deepEqual(JSON.parse(res.body), - {error:"missing unknown_user's dbname in redis (try CARTODB/script/restore_redis)"}); + {error:"missing unknown_user's database_name in redis (try CARTODB/script/restore_redis)"}); done(); }); });