Merge pull request #289 from CartoDB/issue-267

Call callback on invalid map store token for named maps
This commit is contained in:
Raul Ochoa 2015-04-22 18:38:58 +02:00
commit 62dbce4311
2 changed files with 68 additions and 2 deletions

View File

@ -400,7 +400,9 @@ module.exports = function(redisPool) {
}
mapStore.load(layergroup_id, function(err, mapConfig) {
assert.ifError(err);
if (err) {
return callback(err);
}
var authorized = me.templateMaps.isAuthorized(mapConfig.obj().template, auth_token);
@ -475,7 +477,9 @@ module.exports = function(redisPool) {
});
},
function checkSignAuthorized(err, signed_by){
assert.ifError(err);
if (err) {
return callback(err);
}
if ( ! signed_by ) {
// request not authorized by signer.

View File

@ -2045,6 +2045,68 @@ describe('template_api', function() {
);
});
describe('named map nonexistent tokens', function() {
var username = 'localhost';
var templateHash = 'deadbeef';
var nonexistentToken = 'wadus';
function request(token) {
return {
url: '/api/v1/map/' + token + '/all/0/0/0.png',
method: 'GET',
headers: {
host: username
},
encoding: 'binary'
};
}
var expectedResponse = {
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
status: 400
};
function checkTileFn(done) {
return function checkTile(res, err) {
if (err) {
return done(err);
}
assert.deepEqual(JSON.parse(res.body), {
error: "Invalid or nonexistent map configuration token '" + nonexistentToken + "'"
});
done();
};
}
it("returns an error for named map nonexistent tokens", function(done) {
var nonexistentNamedMapToken = username + '@' + templateHash + '@' + nonexistentToken;
assert.response(
server,
request(nonexistentNamedMapToken),
expectedResponse,
checkTileFn(done)
);
});
it("returns an error for named map nonexistent tokens without template hash", function(done) {
var nonexistentNamedMapToken = username + '@' + nonexistentToken;
assert.response(
server,
request(nonexistentNamedMapToken),
expectedResponse,
checkTileFn(done)
);
});
});
after(function(done) {
// This test will add map_style records, like