2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
var test_helper = require('../support/test-helper');
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
var assert = require('../support/assert');
|
2019-10-07 15:40:50 +08:00
|
|
|
var CartodbWindshaft = require(__dirname + '/../../lib/server');
|
2019-10-07 16:10:51 +08:00
|
|
|
var serverOptions = require(__dirname + '/../../lib/server-options');
|
2015-01-31 02:29:45 +08:00
|
|
|
|
2019-10-07 15:40:50 +08:00
|
|
|
var LayergroupToken = require('../../lib/models/layergroup-token');
|
2015-09-25 20:20:21 +08:00
|
|
|
|
2015-01-31 02:29:45 +08:00
|
|
|
var RedisPool = require('redis-mpool');
|
2019-10-07 16:50:14 +08:00
|
|
|
var TemplateMaps = require('../../lib/backends/template-maps');
|
2015-01-31 02:29:45 +08:00
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
var step = require('step');
|
2015-01-31 02:29:45 +08:00
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
describe('named_layers', function() {
|
2018-04-16 22:16:23 +08:00
|
|
|
var server;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
server = new CartodbWindshaft(serverOptions);
|
|
|
|
});
|
2018-04-16 20:09:24 +08:00
|
|
|
|
2015-01-31 02:29:45 +08:00
|
|
|
// configure redis pool instance to use in tests
|
2015-04-27 23:49:15 +08:00
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
var templateMaps = new TemplateMaps(redisPool, {
|
|
|
|
max_user_templates: global.environment.maxUserTemplates
|
|
|
|
});
|
|
|
|
|
|
|
|
var wadusLayer = {
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select 1 cartodb_id, null::geometry the_geom_webmercator',
|
|
|
|
cartocss: '#layer { marker-fill: <%= color %>; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var username = 'localhost';
|
|
|
|
|
|
|
|
var templateName = 'valid_template';
|
|
|
|
var template = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: templateName,
|
|
|
|
auth: {
|
|
|
|
method: 'open'
|
|
|
|
},
|
|
|
|
"placeholders": {
|
|
|
|
"color": {
|
|
|
|
"type": "css_color",
|
|
|
|
"default": "#cc3300"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
layers: [
|
2015-05-26 21:39:21 +08:00
|
|
|
wadusLayer,
|
2015-01-31 02:29:45 +08:00
|
|
|
wadusLayer
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var tokenAuthTemplateName = 'auth_valid_template';
|
|
|
|
var tokenAuthTemplate = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: tokenAuthTemplateName,
|
|
|
|
auth: {
|
|
|
|
method: 'token',
|
|
|
|
valid_tokens: ['valid1', 'valid2']
|
|
|
|
},
|
|
|
|
placeholders: {
|
|
|
|
color: {
|
|
|
|
"type": "css_color",
|
|
|
|
"default": "#cc3300"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
layers: [
|
|
|
|
wadusLayer
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var namedMapLayer = {
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: templateName,
|
|
|
|
config: {},
|
|
|
|
auth_tokens: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var nestedNamedMapTemplateName = 'nested_template';
|
|
|
|
var nestedNamedMapTemplate = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: nestedNamedMapTemplateName,
|
|
|
|
auth: {
|
|
|
|
method: 'open'
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
layers: [
|
|
|
|
namedMapLayer
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
var keysToDelete;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2015-09-26 00:22:45 +08:00
|
|
|
keysToDelete = {};
|
2015-09-25 20:20:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function(done) {
|
|
|
|
test_helper.deleteRedisKeys(keysToDelete, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function(done) {
|
2018-02-21 18:37:20 +08:00
|
|
|
global.environment.enabledFeatures.cdbQueryTablesFromPostgres = true;
|
2015-01-31 02:29:45 +08:00
|
|
|
templateMaps.addTemplate(username, nestedNamedMapTemplate, function(err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
templateMaps.addTemplate(username, tokenAuthTemplate, function(err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2015-02-04 18:30:36 +08:00
|
|
|
templateMaps.addTemplate(username, template, function(err) {
|
2015-02-05 02:01:14 +08:00
|
|
|
return done(err);
|
2015-02-04 18:30:36 +08:00
|
|
|
});
|
2015-01-31 02:29:45 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
afterEach(function(done) {
|
2018-02-21 18:37:20 +08:00
|
|
|
global.environment.enabledFeatures.cdbQueryTablesFromPostgres = false;
|
2015-09-25 20:20:21 +08:00
|
|
|
templateMaps.delTemplate(username, nestedNamedMapTemplateName, function(err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
templateMaps.delTemplate(username, tokenAuthTemplateName, function(err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
templateMaps.delTemplate(username, templateName, function(err) {
|
|
|
|
return done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should fail for non-existing template name', function(done) {
|
2015-01-31 02:29:45 +08:00
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: 'nonexistent'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-01-31 02:29:45 +08:00
|
|
|
function createLayergroup() {
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-01-31 02:29:45 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 400
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
2016-06-13 22:14:01 +08:00
|
|
|
assert.deepEqual(parsedBody.errors, ["Template 'nonexistent' of user 'localhost' not found"]);
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should return 403 if not properly authorized', function(done) {
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: tokenAuthTemplateName,
|
|
|
|
config: {},
|
|
|
|
auth_tokens: ['token1']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-01-31 02:29:45 +08:00
|
|
|
function createLayergroup() {
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-01-31 02:29:45 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 403
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
2016-06-13 22:14:01 +08:00
|
|
|
assert.deepEqual(parsedBody.errors, [ "Unauthorized 'auth_valid_template' template instantiation" ]);
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should return 200 and layergroup if properly authorized', function(done) {
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: tokenAuthTemplateName,
|
|
|
|
config: {},
|
|
|
|
auth_tokens: ['valid1']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-01-31 02:29:45 +08:00
|
|
|
function createLayergroup() {
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-01-31 02:29:45 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
|
|
|
assert.ok(parsedBody.layergroupid);
|
|
|
|
assert.ok(parsedBody.last_updated);
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
2015-09-26 00:22:45 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2015-09-25 20:20:21 +08:00
|
|
|
|
2015-01-31 02:29:45 +08:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should return 400 for nested named map layers', function(done) {
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: nestedNamedMapTemplateName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-01-31 02:29:45 +08:00
|
|
|
function createLayergroup() {
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-01-31 02:29:45 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 400
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
2016-06-13 22:14:01 +08:00
|
|
|
assert.deepEqual(parsedBody.errors, ['Nested named layers are not allowed' ]);
|
2015-01-31 02:29:45 +08:00
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should return 200 and layergroup with private tables', function(done) {
|
2015-02-02 21:38:26 +08:00
|
|
|
|
|
|
|
var privateTableTemplateName = 'private_table_template';
|
|
|
|
var privateTableTemplate = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: privateTableTemplateName,
|
|
|
|
auth: {
|
|
|
|
method: 'open'
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1',
|
|
|
|
cartocss: '#layer { marker-fill: #cc3300; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: privateTableTemplateName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-02-18 02:28:05 +08:00
|
|
|
function createTemplate() {
|
|
|
|
templateMaps.addTemplate(username, privateTableTemplate, this);
|
|
|
|
},
|
|
|
|
function createLayergroup(err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-02-18 02:28:05 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
|
|
|
assert.ok(parsedBody.layergroupid);
|
|
|
|
assert.ok(parsedBody.last_updated);
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
2015-09-26 00:22:45 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2015-09-25 20:20:21 +08:00
|
|
|
|
2015-02-18 02:28:05 +08:00
|
|
|
return parsedBody.layergroupid;
|
|
|
|
},
|
|
|
|
function requestTile(err, layergroupId) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map/' + layergroupId + '/0/0/0.png',
|
2015-02-18 02:28:05 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost'
|
|
|
|
},
|
|
|
|
encoding: 'binary'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'content-type': 'image/png'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function handleTileResponse(err, res) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
test_helper.checkCache(res);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
function deleteTemplate(err) {
|
|
|
|
var next = this;
|
2015-09-24 00:44:11 +08:00
|
|
|
templateMaps.delTemplate(username, privateTableTemplateName, function(/*delErr*/) {
|
2015-02-18 02:28:05 +08:00
|
|
|
// ignore deletion error
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should return 200 and layergroup with private tables and interactivity', function(done) {
|
2015-02-18 02:28:05 +08:00
|
|
|
|
|
|
|
var privateTableTemplateNameInteractivity = 'private_table_template_interactivity';
|
|
|
|
var privateTableTemplate = {
|
|
|
|
"version": "0.0.1",
|
|
|
|
"auth": {
|
|
|
|
"method": "open"
|
|
|
|
},
|
|
|
|
"name": privateTableTemplateNameInteractivity,
|
|
|
|
"layergroup": {
|
|
|
|
"layers": [
|
|
|
|
{
|
|
|
|
"type": "cartodb",
|
|
|
|
"options": {
|
|
|
|
"attributes": {
|
|
|
|
"columns": [
|
|
|
|
"name"
|
|
|
|
],
|
|
|
|
"id": "cartodb_id"
|
|
|
|
},
|
|
|
|
"cartocss": "#layer { marker-fill: #cc3300; }",
|
|
|
|
"cartocss_version": "2.3.0",
|
|
|
|
"interactivity": "cartodb_id",
|
|
|
|
"sql": "select * from test_table_private_1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: privateTableTemplateNameInteractivity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-02-02 21:38:26 +08:00
|
|
|
function createTemplate() {
|
|
|
|
templateMaps.addTemplate(username, privateTableTemplate, this);
|
|
|
|
},
|
|
|
|
function createLayergroup(err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-02-02 21:38:26 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
|
|
|
assert.ok(parsedBody.layergroupid);
|
|
|
|
assert.ok(parsedBody.last_updated);
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
2015-09-26 00:22:45 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2015-09-25 20:20:21 +08:00
|
|
|
|
2015-02-02 21:38:26 +08:00
|
|
|
return parsedBody.layergroupid;
|
|
|
|
},
|
|
|
|
function requestTile(err, layergroupId) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
2015-02-03 00:44:15 +08:00
|
|
|
var next = this;
|
2015-02-02 21:38:26 +08:00
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map/' + layergroupId + '/0/0/0.png',
|
2015-02-02 21:38:26 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost'
|
|
|
|
},
|
|
|
|
encoding: 'binary'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'content-type': 'image/png'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(res, err) {
|
2015-02-05 02:31:20 +08:00
|
|
|
next(err, res);
|
2015-02-02 21:38:26 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2015-02-05 02:31:20 +08:00
|
|
|
function handleTileResponse(err, res) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
2015-02-16 18:57:53 +08:00
|
|
|
test_helper.checkCache(res);
|
2015-02-05 02:31:20 +08:00
|
|
|
return true;
|
|
|
|
},
|
2015-02-02 21:38:26 +08:00
|
|
|
function deleteTemplate(err) {
|
|
|
|
var next = this;
|
2015-09-24 00:44:11 +08:00
|
|
|
templateMaps.delTemplate(username, privateTableTemplateNameInteractivity, function(/*delErr*/) {
|
2015-02-02 21:38:26 +08:00
|
|
|
// ignore deletion error
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
it('should return 403 when private table is accessed from non named layer', function(done) {
|
2015-02-04 18:30:36 +08:00
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1',
|
|
|
|
cartocss: '#layer { marker-fill: #cc3300; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: templateName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2015-04-27 23:49:15 +08:00
|
|
|
step(
|
2015-02-04 18:30:36 +08:00
|
|
|
function createLayergroup() {
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
2015-03-23 22:54:45 +08:00
|
|
|
url: '/api/v1/map',
|
2015-02-04 18:30:36 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 403
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
2018-03-20 18:33:31 +08:00
|
|
|
assert.ok(parsedBody.errors[0].match(/permission denied for .+?test_table_private_1/));
|
2015-02-04 18:30:36 +08:00
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-05-26 21:39:21 +08:00
|
|
|
it('should return metadata for named layers', function(done) {
|
|
|
|
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'plain',
|
|
|
|
options: {
|
|
|
|
color: '#fabada'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table',
|
|
|
|
cartocss: '#layer { marker-fill: #cc3300; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'named',
|
|
|
|
options: {
|
|
|
|
name: templateName
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'torque',
|
|
|
|
options: {
|
|
|
|
sql: "select * from test_table LIMIT 0",
|
|
|
|
cartocss: "Map { -torque-frame-count:1; -torque-resolution:1; " +
|
|
|
|
"-torque-aggregation-function:'count(*)'; -torque-time-attribute:'updated_at'; }"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
step(
|
|
|
|
function createLayergroup() {
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
|
|
|
url: '/api/v1/map',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
|
|
|
assert.ok(parsedBody.metadata);
|
|
|
|
assert.ok(parsedBody.metadata.layers);
|
|
|
|
assert.equal(parsedBody.metadata.layers.length, 5);
|
|
|
|
assert.equal(parsedBody.metadata.layers[0].type, 'plain');
|
|
|
|
assert.equal(parsedBody.metadata.layers[1].type, 'mapnik');
|
|
|
|
assert.equal(parsedBody.metadata.layers[2].type, 'mapnik');
|
|
|
|
assert.equal(parsedBody.metadata.layers[3].type, 'mapnik');
|
|
|
|
assert.equal(parsedBody.metadata.layers[4].type, 'torque');
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
2015-09-26 00:22:45 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2015-09-25 20:20:21 +08:00
|
|
|
|
2015-05-26 21:39:21 +08:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-09-24 00:44:11 +08:00
|
|
|
it('should work with named tiles', function(done) {
|
|
|
|
|
|
|
|
var namedTilesTemplateName = 'named_tiles_template';
|
|
|
|
var namedTilesTemplate = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: namedTilesTemplateName,
|
|
|
|
auth: {
|
|
|
|
method: 'open'
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
layers: [
|
|
|
|
namedMapLayer,
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1',
|
|
|
|
cartocss: '#layer { marker-fill: #cc3300; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
step(
|
|
|
|
function createTemplate() {
|
|
|
|
templateMaps.addTemplate(username, namedTilesTemplate, this);
|
|
|
|
},
|
|
|
|
function createLayergroup(err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
|
|
|
url: '/api/v1/map/named/' + namedTilesTemplateName + '?api_key=1234',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function checkLayergroup(err, response) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(response.body);
|
|
|
|
assert.ok(parsedBody.layergroupid);
|
|
|
|
assert.ok(parsedBody.last_updated);
|
|
|
|
|
|
|
|
assert.equal(parsedBody.metadata.layers[0].type, 'mapnik');
|
|
|
|
assert.equal(parsedBody.metadata.layers[1].type, 'mapnik');
|
|
|
|
|
2015-09-25 20:20:21 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
2015-09-26 00:22:45 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2015-09-25 20:20:21 +08:00
|
|
|
|
2015-09-24 00:44:11 +08:00
|
|
|
return parsedBody.layergroupid;
|
|
|
|
},
|
|
|
|
function requestTile(err, layergroupId) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var next = this;
|
|
|
|
assert.response(server,
|
|
|
|
{
|
|
|
|
url: '/api/v1/map/' + layergroupId + '/all/0/0/0.png',
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost'
|
|
|
|
},
|
|
|
|
encoding: 'binary'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'content-type': 'image/png'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(res, err) {
|
|
|
|
next(err, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function handleTileResponse(err, res) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
test_helper.checkCache(res);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
function deleteTemplate(err) {
|
|
|
|
var next = this;
|
|
|
|
templateMaps.delTemplate(username, namedTilesTemplateName, function(/*delErr*/) {
|
|
|
|
// ignore deletion error
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish(err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
2015-01-31 02:29:45 +08:00
|
|
|
});
|