2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-23 00:22:33 +08:00
|
|
|
var path = require('path');
|
2019-10-22 01:07:24 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var _ = require('underscore');
|
|
|
|
var redis = require('redis');
|
|
|
|
var step = require('step');
|
|
|
|
var strftime = require('strftime');
|
2019-11-06 23:44:17 +08:00
|
|
|
var redisStatsDb = 5;
|
2013-02-25 22:08:28 +08:00
|
|
|
|
2020-04-04 23:34:22 +08:00
|
|
|
const mapnik = require('@carto/mapnik');
|
2016-12-20 00:29:24 +08:00
|
|
|
var semver = require('semver');
|
|
|
|
|
2019-10-07 16:55:26 +08:00
|
|
|
var helper = require('../support/test-helper');
|
2019-10-07 15:40:50 +08:00
|
|
|
var LayergroupToken = require('../../lib/models/layergroup-token');
|
2013-02-25 22:08:28 +08:00
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var windshaftFixtures = path.join(__dirname, '/../../node_modules/windshaft/test/fixtures');
|
2013-02-25 22:08:28 +08:00
|
|
|
|
2014-08-04 07:30:24 +08:00
|
|
|
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 20;
|
|
|
|
var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25;
|
|
|
|
|
2019-10-07 15:40:50 +08:00
|
|
|
var CartodbWindshaft = require('../../lib/server');
|
2019-10-07 16:10:51 +08:00
|
|
|
var serverOptions = require('../../lib/server-options');
|
2013-02-25 22:08:28 +08:00
|
|
|
|
2019-09-13 22:32:37 +08:00
|
|
|
var QueryTables = require('cartodb-query-tables').queryTables;
|
2015-07-13 22:54:08 +08:00
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
['/api/v1/map', '/user/localhost/api/v1/map'].forEach(function (layergroupUrl) {
|
|
|
|
var suiteName = 'multilayer:postgres=layergroupUrl=' + layergroupUrl;
|
2019-10-22 01:07:24 +08:00
|
|
|
describe(suiteName, function () {
|
|
|
|
var server;
|
2014-08-07 03:48:08 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
before(function () {
|
|
|
|
server = new CartodbWindshaft(serverOptions);
|
|
|
|
server.setMaxListeners(0);
|
|
|
|
});
|
2015-09-25 20:07:12 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var keysToDelete;
|
2015-09-25 20:07:12 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
beforeEach(function () {
|
|
|
|
keysToDelete = {};
|
|
|
|
});
|
2015-09-25 20:07:12 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
|
|
|
helper.deleteRedisKeys(keysToDelete, done);
|
|
|
|
});
|
2015-03-23 21:44:42 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var cdbQueryTablesFromPostgresEnabledValue = true;
|
2013-02-25 22:08:28 +08:00
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedLastUpdatedEpoch = 1234567890123; // this is hard-coded into SQLAPIEmu
|
|
|
|
var expectedLastUpdated = new Date(expectedLastUpdatedEpoch).toISOString();
|
2014-02-21 01:03:43 +08:00
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var testUser = _.template(global.environment.postgres_auth_user, { user_id: 1 });
|
|
|
|
var testDatabase = testUser + '_db';
|
2013-02-25 22:08:28 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('layergroup with 2 layers, each with its style', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' +
|
2015-03-30 18:13:59 +08:00
|
|
|
' from test_table limit 2',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.0.1',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, -5e6, 0) as the_geom_webmercator' +
|
2015-03-30 18:13:59 +08:00
|
|
|
' from test_table limit 2 offset 2',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { marker-fill:blue; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.0.2',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = parsedBody.layergroupid;
|
2019-10-22 01:07:24 +08:00
|
|
|
next(null, res);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTile (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check Cache-Control
|
|
|
|
var cc = res.headers['cache-control'];
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc, 'public,max-age=31536000'); // 1 year
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check X-Cache-Channel
|
|
|
|
cc = res.headers['x-cache-channel'];
|
|
|
|
assert.ok(cc);
|
2019-11-06 23:44:17 +08:00
|
|
|
var dbname = testDatabase;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
2019-10-22 01:07:24 +08:00
|
|
|
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
|
|
|
var jsonquery = cc.substring(dbname.length + 1);
|
|
|
|
var sentquery = JSON.parse(jsonquery);
|
|
|
|
var expectedQuery = [
|
|
|
|
layergroup.layers[0].options.sql, ';',
|
|
|
|
layergroup.layers[1].options.sql
|
|
|
|
].join('');
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(sentquery.q, 'WITH querytables AS ( SELECT * FROM CDB_QueryTables($windshaft$' +
|
2015-03-30 18:13:59 +08:00
|
|
|
expectedQuery +
|
|
|
|
'$windshaft$) as tablenames )' +
|
|
|
|
' SELECT (SELECT tablenames FROM querytables), EXTRACT(EPOCH FROM max(updated_at)) as max' +
|
|
|
|
' FROM CDB_TableMetadata m' +
|
|
|
|
' WHERE m.tabname = any ((SELECT tablenames from querytables)::regclass[])');
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.imageBufferIsSimilarToFile(res.body, 'test/fixtures/test_table_0_0_0_multilayer1.png',
|
|
|
|
IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL, function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/170
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTileNoSignature (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/localhost@' + expectedToken + ':cb0/0/0/0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403, res.statusCode + ':' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
var msg = parsed.errors[0];
|
|
|
|
assert.ok(msg.match(/permission denied/i), msg);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGridLayer0 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/0/0/0/0.grid.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(res.body, 'test/fixtures/test_table_0_0_0_multilayer1.layer0.grid.json', 2,
|
|
|
|
function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGridLayer1 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/1/0/0/0.grid.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(res.body, 'test/fixtures/test_table_0_0_0_multilayer1.layer1.grid.json', 2,
|
|
|
|
function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish (err) {
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
2016-02-22 22:31:01 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('server-metadata', function () {
|
|
|
|
var serverMetadata;
|
|
|
|
beforeEach(function () {
|
|
|
|
serverMetadata = global.environment.serverMetadata;
|
|
|
|
global.environment.serverMetadata = { cdn_url: { http: 'test', https: 'tests' } };
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
global.environment.serverMetadata = serverMetadata;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should include serverMedata in the response', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' +
|
2016-02-22 22:31:01 +08:00
|
|
|
' from test_table limit 2',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doCreateGet () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' }
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doCheckCreate (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2016-02-22 22:31:01 +08:00
|
|
|
});
|
2014-03-06 22:19:12 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('get creation requests has cache', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, the_geom_webmercator from test_table',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.0.1',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, the_geom_webmercator from test_table_2',
|
|
|
|
cartocss: '#layer { marker-fill:blue; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.0.2',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken;
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doCreateGet () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' }
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doCheckCreate (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = parsedBody.layergroupid.split(':')[0];
|
2019-10-22 01:07:24 +08:00
|
|
|
helper.checkCache(res);
|
|
|
|
helper.checkSurrogateKey(res, new QueryTables.QueryMetadata([
|
|
|
|
{ dbname: 'test_windshaft_cartodb_user_1_db', table_name: 'test_table', schema_name: 'public' },
|
|
|
|
{ dbname: 'test_windshaft_cartodb_user_1_db', table_name: 'test_table_2', schema_name: 'public' }
|
|
|
|
]).key().join(' '));
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-03-04 17:46:15 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('get creation has no cache if sql is bogus', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select bogus(0,0) as the_geom_webmercator',
|
|
|
|
cartocss: '#layer { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' }
|
|
|
|
}, {}, function (res) {
|
2019-10-22 02:05:51 +08:00
|
|
|
assert.notStrictEqual(res.statusCode, 200);
|
2019-10-22 01:07:24 +08:00
|
|
|
helper.checkNoCache(res);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-24 19:13:00 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('get creation has no cache if cartocss is not valid', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' +
|
2015-03-30 18:13:59 +08:00
|
|
|
' from test_table limit 2',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { invalid-rule:red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' }
|
|
|
|
}, {}, function (res) {
|
2019-10-22 02:05:51 +08:00
|
|
|
assert.notStrictEqual(res.statusCode, 200);
|
2019-10-22 01:07:24 +08:00
|
|
|
helper.checkNoCache(res);
|
|
|
|
done();
|
|
|
|
});
|
2014-06-24 19:13:00 +08:00
|
|
|
});
|
2013-03-28 19:48:00 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('layergroup can hold substitution tokens', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select 1 as cartodb_id, ST_Buffer(!bbox!, -32*greatest(!pixel_width!,!pixel_height!))' +
|
2015-03-30 18:13:59 +08:00
|
|
|
' as the_geom_webmercator from test_table limit 1',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { polygon-fill:red; }',
|
|
|
|
cartocss_version: '2.0.1',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken; // = "6d8e4ad5458e2d25cf0eef38e38717a6";
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
|
|
|
if (expectedToken) {
|
|
|
|
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
2019-10-22 01:07:24 +08:00
|
|
|
} else {
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = parsedBody.layergroupid.split(':')[0];
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
next(null, res);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTile1 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb10/1/0/0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check X-Cache-Channel
|
|
|
|
var cc = res.headers['x-cache-channel'];
|
|
|
|
assert.ok(cc);
|
2019-11-06 23:44:17 +08:00
|
|
|
var dbname = testDatabase;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
2019-10-22 01:07:24 +08:00
|
|
|
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
|
|
|
var jsonquery = cc.substring(dbname.length + 1);
|
|
|
|
var sentquery = JSON.parse(jsonquery);
|
|
|
|
var expectedQuery = layergroup.layers[0].options.sql
|
|
|
|
.replace(/!bbox!/g, 'ST_MakeEnvelope(0,0,0,0)')
|
|
|
|
.replace(/!pixel_width!/g, '1')
|
|
|
|
.replace(/!pixel_height!/g, '1');
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(sentquery.q, 'WITH querytables AS ( SELECT * FROM CDB_QueryTables($windshaft$' +
|
2015-03-30 18:13:59 +08:00
|
|
|
expectedQuery +
|
|
|
|
'$windshaft$) as tablenames )' +
|
|
|
|
' SELECT (SELECT tablenames FROM querytables), EXTRACT(EPOCH FROM max(updated_at)) as max' +
|
|
|
|
' FROM CDB_TableMetadata m' +
|
|
|
|
' WHERE m.tabname = any ((SELECT tablenames from querytables)::regclass[])');
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var referenceImagePath = 'test/fixtures/test_multilayer_bbox.png';
|
|
|
|
assert.imageBufferIsSimilarToFile(res.body, referenceImagePath, IMAGE_EQUALS_TOLERANCE_PER_MIL,
|
|
|
|
function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTile4 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb11/4/0/0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check X-Cache-Channel
|
|
|
|
var cc = res.headers['x-cache-channel'];
|
|
|
|
assert.ok(cc);
|
2019-11-06 23:44:17 +08:00
|
|
|
var dbname = testDatabase;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
2019-10-22 01:07:24 +08:00
|
|
|
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
|
|
|
var jsonquery = cc.substring(dbname.length + 1);
|
|
|
|
var sentquery = JSON.parse(jsonquery);
|
|
|
|
var expectedQuery = layergroup.layers[0].options.sql
|
|
|
|
.replace('!bbox!', 'ST_MakeEnvelope(0,0,0,0)')
|
|
|
|
.replace('!pixel_width!', '1')
|
|
|
|
.replace('!pixel_height!', '1');
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(sentquery.q, 'WITH querytables AS ( SELECT * FROM CDB_QueryTables($windshaft$' +
|
2015-03-30 18:13:59 +08:00
|
|
|
expectedQuery +
|
|
|
|
'$windshaft$) as tablenames )' +
|
|
|
|
' SELECT (SELECT tablenames FROM querytables), EXTRACT(EPOCH FROM max(updated_at)) as max' +
|
|
|
|
' FROM CDB_TableMetadata m' +
|
|
|
|
' WHERE m.tabname = any ((SELECT tablenames from querytables)::regclass[])');
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var referenceImagePath = 'test/fixtures/test_multilayer_bbox.png';
|
|
|
|
assert.imageBufferIsSimilarToFile(res.body, referenceImagePath, IMAGE_EQUALS_TOLERANCE_PER_MIL,
|
|
|
|
function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGrid1 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/0/1/0/0.grid.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(res.body, 'test/fixtures/test_multilayer_bbox.grid.json', 2,
|
|
|
|
function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGrid4 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/0/4/0/0.grid.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(res.body, 'test/fixtures/test_multilayer_bbox.grid.json', 2, next);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish (err) {
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2013-04-12 23:28:34 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('layergroup creation raises mapviews counter', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
stat_tag: 'random_tag',
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select 1 as cartodb_id, !pixel_height! as h,' +
|
2015-03-30 18:13:59 +08:00
|
|
|
' ST_Buffer(!bbox!, -32*greatest(!pixel_width!,!pixel_height!)) as the_geom_webmercator',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { polygon-fill:red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
var statskey = 'user:localhost:mapviews';
|
2019-11-06 23:44:17 +08:00
|
|
|
var redisStatsClient = redis.createClient(global.environment.redis.port);
|
|
|
|
var expectedToken; // will be set on first post and checked on second
|
2019-10-22 01:07:24 +08:00
|
|
|
var now = strftime('%Y%m%d', new Date());
|
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function cleanStats () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
2019-11-06 23:44:17 +08:00
|
|
|
redisStatsClient.select(redisStatsDb, function (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
if (err) {
|
|
|
|
next(err);
|
|
|
|
} else {
|
2019-11-06 23:44:17 +08:00
|
|
|
redisStatsClient.del(statskey + ':global', next);
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost1 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = JSON.parse(res.body).layergroupid;
|
|
|
|
redisStatsClient.zscore(statskey + ':global', now, next);
|
2019-10-22 01:07:24 +08:00
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkGlobalStats1 (err, val) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(val, '1', 'Expected score of ' + now + ' in ' + statskey + ':global to be 1, got ' + val);
|
2019-11-06 23:44:17 +08:00
|
|
|
redisStatsClient.zscore(statskey + ':stat_tag:random_tag', now, this);
|
2019-10-22 01:07:24 +08:00
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkTagStats1DoPost2 (err, val) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(val, '1', 'Expected score of ' + now + ' in ' + statskey + ':stat_tag:' + layergroup.stat_tag +
|
2019-10-22 01:07:24 +08:00
|
|
|
' to be 1, got ' + val);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(JSON.parse(res.body).layergroupid, expectedToken);
|
|
|
|
redisStatsClient.zscore(statskey + ':global', now, next);
|
2019-10-22 01:07:24 +08:00
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkGlobalStats2 (err, val) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(val, '2', 'Expected score of ' + now + ' in ' + statskey + ':global to be 2, got ' + val);
|
2019-11-06 23:44:17 +08:00
|
|
|
redisStatsClient.zscore(statskey + ':stat_tag:' + layergroup.stat_tag, now, this);
|
2019-10-22 01:07:24 +08:00
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkTagStats2 (err, val) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(val, '2', 'Expected score of ' + now + ' in ' + statskey + ':stat_tag:' + layergroup.stat_tag +
|
2019-10-22 01:07:24 +08:00
|
|
|
' to be 2, got ' + val);
|
|
|
|
return 1;
|
|
|
|
},
|
|
|
|
function finish (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
// strip epoch
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = expectedToken.split(':')[0];
|
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
keysToDelete[statskey + ':stat_tag:' + layergroup.stat_tag] = 5;
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2013-03-28 19:48:00 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('layergroup creation fails if CartoCSS is bogus', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
stat_tag: 'random_tag',
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select 1 as cartodb_id, !pixel_height! as h,' +
|
2015-03-30 18:13:59 +08:00
|
|
|
'ST_Buffer(!bbox!, -32*greatest(!pixel_width!,!pixel_height!)) as the_geom_webmercator',
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { polygon-fit:red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 400, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
assert.ok(parsed.errors[0].match(/^style0/));
|
|
|
|
assert.ok(parsed.errors[0].match(/Unrecognized rule: polygon-fit/));
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-06-10 17:53:28 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// Also tests that server doesn't crash:
|
|
|
|
// see http://github.com/CartoDB/Windshaft-cartodb/issues/109
|
|
|
|
it('layergroup creation fails if sql is bogus', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
stat_tag: 'random_tag',
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select bogus(0,0) as the_geom_webmercator',
|
|
|
|
cartocss: '#layer { polygon-fill:red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
var msg = parsed.errors[0];
|
|
|
|
assert.ok(msg.match(/bogus.*exist/), msg);
|
|
|
|
helper.checkNoCache(res);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-01-15 18:53:19 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('layergroup with 2 private-table layers', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1 where cartodb_id=1',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.1.0',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1 where cartodb_id=2',
|
|
|
|
cartocss: '#layer { marker-fill:blue; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.1.0',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken; // = "b4ed64d93a411a59f330ab3d798e4009";
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
|
|
|
if (expectedToken) {
|
|
|
|
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
2019-10-22 01:07:24 +08:00
|
|
|
} else {
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = parsedBody.layergroupid.split(':')[0];
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
next(null, res);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTile (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check X-Cache-Channel
|
|
|
|
var cc = res.headers['x-cache-channel'];
|
|
|
|
assert.ok(cc);
|
2019-11-06 23:44:17 +08:00
|
|
|
var dbname = testDatabase;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
2019-10-22 01:07:24 +08:00
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGridLayer0 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/0/0/0/0.grid.json?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGridLayer1 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/1/0/0/0.grid.json?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2019-10-22 01:07:24 +08:00
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTileUnauth (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2019-10-22 01:07:24 +08:00
|
|
|
var re = new RegExp('permission denied');
|
|
|
|
assert.ok(res.body.match(re), 'No "permission denied" error: ' + res.body);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGridLayer0Unauth (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/0/0/0/0.grid.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2019-10-22 01:07:24 +08:00
|
|
|
var re = new RegExp('permission denied');
|
|
|
|
assert.ok(res.body.match(re), 'No "permission denied" error: ' + res.body);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetGridLayer1Unauth (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + '/1/0/0/0.grid.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
headers: { host: 'localhost' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2019-10-22 01:07:24 +08:00
|
|
|
var re = new RegExp('permission denied');
|
|
|
|
assert.ok(res.body.match(re), 'No "permission denied" error: ' + res.body);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish (err) {
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2014-02-19 01:33:00 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2013-06-17 23:24:09 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/152
|
|
|
|
it('x-cache-channel still works for GETs after tiler restart', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table where cartodb_id=1',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.1.0',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken; // = "b4ed64d93a411a59f330ab3d798e4009";
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkPost (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
|
|
|
if (expectedToken) {
|
|
|
|
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
2019-10-22 01:07:24 +08:00
|
|
|
} else {
|
2019-11-06 23:44:17 +08:00
|
|
|
expectedToken = parsedBody.layergroupid.split(':')[0];
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGet0 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doCheck0 (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check X-Cache-Channel
|
|
|
|
var cc = res.headers['x-cache-channel'];
|
|
|
|
assert.ok(cc, 'Missing X-Cache-Channel');
|
2019-11-06 23:44:17 +08:00
|
|
|
var dbname = testDatabase;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
2019-10-22 01:07:24 +08:00
|
|
|
return null;
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doRestartServer (err/*, res */) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
// hack simulating restart...
|
|
|
|
server = new CartodbWindshaft(serverOptions);
|
|
|
|
return null;
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGet1 (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?map_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doCheck1 (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
// Check X-Cache-Channel
|
|
|
|
var cc = res.headers['x-cache-channel'];
|
|
|
|
assert.ok(cc, 'Missing X-Cache-Channel on restart');
|
2019-11-06 23:44:17 +08:00
|
|
|
var dbname = testDatabase;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
2019-10-22 01:07:24 +08:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish (err) {
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2013-09-12 23:32:10 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2013-10-03 23:01:12 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// https://github.com/cartodb/Windshaft-cartodb/issues/81
|
|
|
|
it('invalid text-name in CartoCSS', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.1',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: "select 1 as cartodb_id, 'SRID=3857;POINT(0 0)'::geometry as the_geom_webmercator",
|
|
|
|
cartocss: '#sample { text-name: cartodb_id; text-face-name: "Dejagnu"; }',
|
|
|
|
cartocss_version: '2.1.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2013-11-08 19:34:34 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(parsed.errors.length, 1);
|
2019-10-22 01:07:24 +08:00
|
|
|
var errmsg = parsed.errors[0];
|
|
|
|
assert.ok(errmsg.match(/text-face-name.*Dejagnu/), parsed.errors.toString());
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-11-29 01:47:45 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('quotes CartoCSS', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.1',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: "select 'single''quote' as n, 'SRID=3857;POINT(0 0)'::geometry as the_geom_webmercator",
|
|
|
|
cartocss: '#s [n="single\'quote" ] { marker-fill:red; }',
|
|
|
|
cartocss_version: '2.1.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: "select 'double\"quote' as n, 'SRID=3857;POINT(2 0)'::geometry as the_geom_webmercator",
|
|
|
|
cartocss: '#s [n="double\\"quote" ] { marker-fill:red; }',
|
|
|
|
cartocss_version: '2.1.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(JSON.parse(res.body).layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
done();
|
|
|
|
});
|
2016-12-20 00:29:24 +08:00
|
|
|
});
|
2013-11-29 20:14:43 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/87
|
|
|
|
it('exponential notation in CartoCSS filter values', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.1',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: "select .4 as n, 'SRID=3857;POINT(0 0)'::geometry as the_geom_webmercator",
|
|
|
|
cartocss: '#s [n<=.2e-2] { marker-fill:red; }',
|
|
|
|
cartocss_version: '2.1.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(JSON.parse(res.body).layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-09-26 00:17:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/93
|
|
|
|
if (semver.satisfies(mapnik.versions.mapnik, '2.3.x')) {
|
|
|
|
it('accepts unused directives', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: "select 'SRID=3857;POINT(0 0)'::geometry as the_geom_webmercator",
|
|
|
|
cartocss: '#layer { point-transform:"scale(20)"; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
if (expectedToken) {
|
|
|
|
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
|
2019-10-22 01:07:24 +08:00
|
|
|
} else {
|
2019-11-06 23:44:17 +08:00
|
|
|
var tokenComponents = parsedBody.layergroupid.split(':');
|
|
|
|
expectedToken = tokenComponents[0];
|
|
|
|
expectedLastUpdatedEpoch = tokenComponents[1];
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
next(null, res);
|
|
|
|
});
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTile (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'image/png');
|
2019-11-06 23:44:17 +08:00
|
|
|
assert.imageBufferIsSimilarToFile(res.body, windshaftFixtures + '/test_default_mapnik_point.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
IMAGE_EQUALS_TOLERANCE_PER_MIL, function (err/*, similarity */) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function finish (err) {
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-01-17 00:20:30 +08:00
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/91
|
|
|
|
// and https://github.com/CartoDB/Windshaft-cartodb/issues/38
|
|
|
|
it('tiles for private tables can be fetched with api_key', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1 LIMIT 0',
|
|
|
|
cartocss: '#layer { marker-fill:red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?api_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res) { next(null, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkResult (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
if (expectedToken) {
|
|
|
|
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
|
2019-10-22 01:07:24 +08:00
|
|
|
} else {
|
2019-11-06 23:44:17 +08:00
|
|
|
var tokenComponents = parsedBody.layergroupid.split(':');
|
|
|
|
expectedToken = tokenComponents[0];
|
|
|
|
expectedLastUpdatedEpoch = tokenComponents[1];
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
next(null, res);
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function doGetTile (err) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?api_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' },
|
|
|
|
encoding: 'binary'
|
|
|
|
}, {}, function (res) { next(null, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkGetTile (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2019-10-22 01:07:24 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2017-11-29 20:12:09 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
// SQL strings can be of arbitrary length, when using POST
|
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/111
|
|
|
|
it('sql string can be very long', function (done) {
|
2019-11-06 23:44:17 +08:00
|
|
|
var longVal = 'pretty';
|
2019-10-22 01:07:24 +08:00
|
|
|
for (var i = 0; i < 1024; ++i) {
|
2019-11-06 23:44:17 +08:00
|
|
|
longVal += ' long';
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2019-11-06 23:44:17 +08:00
|
|
|
longVal += ' string';
|
2019-10-22 01:07:24 +08:00
|
|
|
var sql = 'SELECT ';
|
|
|
|
for (i = 0; i < 16; ++i) {
|
2019-11-06 23:44:17 +08:00
|
|
|
sql += "'" + longVal + "'::text as pretty_long_field_name_" + i + ', ';
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
|
|
|
sql += 'cartodb_id, the_geom_webmercator FROM gadm4 g';
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: sql,
|
|
|
|
cartocss: '#layer { marker-fill:red; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2019-11-06 23:44:17 +08:00
|
|
|
var expectedToken;
|
2019-10-22 01:07:24 +08:00
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var data = JSON.stringify(layergroup);
|
|
|
|
assert.ok(data.length > 1024 * 64);
|
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?api_key=1234',
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: data
|
|
|
|
}, {}, function (res) { next(null, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkResult (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-11-06 23:44:17 +08:00
|
|
|
var tokenComponents = parsedBody.layergroupid.split(':');
|
|
|
|
expectedToken = tokenComponents[0];
|
2019-10-22 01:07:24 +08:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function cleanup (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2019-11-06 23:44:17 +08:00
|
|
|
keysToDelete['map_cfg|' + expectedToken] = 0;
|
2014-02-10 18:05:02 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
// WARN: MapConfig with mapnik layer and no cartocss it's valid since
|
|
|
|
// vector & raster aggregation project, now we can request MVT format w/o defining styles
|
|
|
|
// for the layer.
|
|
|
|
|
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/133
|
|
|
|
it.skip('MapConfig with mapnik layer and no cartocss', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' +
|
2015-03-30 18:13:59 +08:00
|
|
|
' from test_table limit 2',
|
2019-10-22 01:07:24 +08:00
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkPost (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
assert.ok(parsed.errors, 'Missing "errors" in response: ' + JSON.stringify(parsed));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(parsed.errors.length, 1);
|
2019-10-22 01:07:24 +08:00
|
|
|
var msg = parsed.errors[0];
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(msg, 'Missing cartocss for layer 0 options');
|
2019-10-22 01:07:24 +08:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish (err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-02-10 18:05:02 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
|
|
|
// See https://github.com/CartoDB/Windshaft-cartodb/issues/167
|
|
|
|
it('lack of response from sql-api will result in a timeout', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: "select *, 'SQLAPINOANSWER' from test_table",
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.1.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
step(
|
2019-11-06 23:44:17 +08:00
|
|
|
function doPost () {
|
2019-10-22 01:07:24 +08:00
|
|
|
var next = this;
|
|
|
|
assert.response(server, {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl,
|
2019-10-22 01:07:24 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
}, {}, function (res, err) { next(err, res); });
|
|
|
|
},
|
2019-11-06 23:44:17 +08:00
|
|
|
function checkPost (err, res) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
assert.ok(parsed.errors, 'Missing "errors" in response: ' + JSON.stringify(parsed));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(parsed.errors.length, 1);
|
2019-10-22 01:07:24 +08:00
|
|
|
var msg = parsed.errors[0];
|
|
|
|
assert.ok(msg, /could not fetch source tables/, msg);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
function finish (err) {
|
|
|
|
done(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-02-27 17:26:42 +08:00
|
|
|
}
|
2014-10-24 22:05:41 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var layergroupTtlRequest = {
|
2019-11-06 23:44:17 +08:00
|
|
|
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify({
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})),
|
|
|
|
method: 'GET',
|
|
|
|
headers: { host: 'localhost' }
|
|
|
|
};
|
|
|
|
var layergroupTtlResponseExpectation = {
|
|
|
|
status: 200
|
|
|
|
};
|
2014-10-24 22:05:41 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('cache control for layergroup default value', function (done) {
|
|
|
|
global.environment.varnish.layergroupTtl = null;
|
2014-10-24 22:05:41 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var server = new CartodbWindshaft(serverOptions);
|
2018-03-21 23:38:37 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(server, layergroupTtlRequest, layergroupTtlResponseExpectation,
|
|
|
|
function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.headers['cache-control'], 'public,max-age=86400,must-revalidate');
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(JSON.parse(res.body).layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2014-10-24 22:05:41 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2014-10-24 22:05:41 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('cache control for layergroup uses configuration for max-age', function (done) {
|
|
|
|
var layergroupTtl = 300;
|
|
|
|
global.environment.varnish.layergroupTtl = layergroupTtl;
|
2014-01-17 00:20:30 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var server = new CartodbWindshaft(serverOptions);
|
2015-02-05 23:46:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(server, layergroupTtlRequest, layergroupTtlResponseExpectation,
|
|
|
|
function (res) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.headers['cache-control'], 'public,max-age=' + layergroupTtl + ',must-revalidate');
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(JSON.parse(res.body).layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("it's not possible to override authorization with a crafted layergroup", function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
version: '1.0.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_private_1',
|
|
|
|
cartocss: '#layer { marker-fill:red; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
2015-02-05 23:46:56 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
],
|
|
|
|
template: {
|
|
|
|
auth: {
|
|
|
|
method: 'open'
|
|
|
|
},
|
|
|
|
name: 'open'
|
2015-02-05 23:46:56 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
};
|
2015-02-05 23:46:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(
|
|
|
|
server,
|
|
|
|
{
|
|
|
|
url: '/api/v1/map?signer=localhost',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
2015-02-05 23:46:56 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
{
|
|
|
|
status: 403
|
|
|
|
},
|
|
|
|
function (res) {
|
|
|
|
assert.ok(res.body.match(/permission denied for .+?test_table_private_1/));
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2016-01-29 02:44:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should response to empty layers mapconfig', function (done) {
|
|
|
|
var layergroup = {
|
|
|
|
layers: []
|
|
|
|
};
|
2016-02-10 18:49:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(
|
|
|
|
server,
|
|
|
|
{
|
|
|
|
url: '/api/v1/map',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
2016-02-10 18:49:56 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function (res, err) {
|
|
|
|
assert.ok(!err);
|
2016-02-10 18:49:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
|
|
|
assert.ok(parsedBody.layergroupid);
|
2016-02-10 18:49:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupid).token] = 0;
|
|
|
|
keysToDelete['user:localhost:mapviews:global'] = 5;
|
2016-02-10 18:49:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2016-02-10 18:49:56 +08:00
|
|
|
});
|
2014-08-07 03:48:08 +08:00
|
|
|
});
|