Propagate style changes to caches for unauthenticated requests

Closes #41, does it implementing the new afterStyleChange and
afterStyleDelete callbacks in Windshaft 0.4.10.

Adds automated testcases for the bug.
This commit is contained in:
Sandro Santilli
2012-08-07 16:11:49 +02:00
parent c0eaf826ab
commit 6a92fd3170
3 changed files with 72 additions and 1 deletions
+33
View File
@@ -25,6 +25,39 @@ var CartodbWindshaft = function(serverOptions) {
}
}
serverOptions.afterStyleChange = function(req, data, callback) {
if ( req.params.hasOwnProperty('dbuser') ) {
// also change the style of the anonim. request
var params = _.extend(req.params); // make a copy here
delete params.dbuser;
var style = req.body.style;
var that = this;
this.setStyle(params, style, function(err, data) {
if ( err ) callback(err, null);
else that.afterStateChange(req, data, callback);
});
} else {
console.log("WARNING: map style changed by unauthenticated request!");
this.afterStateChange(req, data, callback);
}
}
serverOptions.afterStyleDelete = function(req, data, callback) {
if ( req.params.hasOwnProperty('dbuser') ) {
// also change the style of the anonim. request
var params = _.extend(req.params); // make a copy here
delete params.dbuser;
var that = this;
this.delStyle(params, function(err, data) {
if ( err ) callback(err, null);
else that.afterStateChange(req, data, callback);
});
} else {
console.log("WARNING: map style deleted by unauthenticated request!");
this.afterStateChange(req, data, callback);
}
}
// boot
+1 -1
View File
@@ -23,7 +23,7 @@
"node-varnish": "0.1.1",
"underscore" : "1.1.x",
"grainstore" : "~0.3.0",
"windshaft" : "~0.4.9",
"windshaft" : "~0.4.10",
"step": "0.0.x",
"generic-pool": "1.0.x",
"redis": "0.6.7",
+38
View File
@@ -103,6 +103,44 @@ suite('server', function() {
});
});
// TODO: test that unauthenticated DELETE should fail
// See https://github.com/Vizzuality/cartodb-management/issues/155
test("delete'ing style returns 200 then getting returns default style", function(done){
// this is the default style
var style = '#my_table5 {marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}'
assert.response(server, {
url: '/tiles/my_table5/style?map_key=1234',
method: 'DELETE',
headers: {host: 'localhost'},
},{}, function(res) {
assert.equal(res.statusCode, 200, res.body);
// Retrive style with authenticated request
assert.response(server, {
headers: {host: 'localhost'},
url: '/tiles/my_table5/style?map_key=1234',
method: 'GET'
},{}, function(res) {
assert.equal(res.statusCode, 200, res.body);
assert.deepEqual(JSON.parse(res.body).style, style);
// Now retrive style with unauthenticated request
assert.response(server, {
headers: {host: 'localhost'},
url: '/tiles/my_table5/style',
method: 'GET'
}, {}, function(res) {
assert.equal(res.statusCode, 200, res.body);
assert.deepEqual(JSON.parse(res.body).style, style);
done();
});
});
});
});
test("get'ing blank infowindow returns blank", function(done){
assert.response(server, {