Merge remote-tracking branch 'carto/master' into mvt-invalid-props

This commit is contained in:
Raul Marin 2018-04-17 10:25:05 +02:00
commit 8d6a406779
10 changed files with 1003 additions and 152 deletions

12
NEWS.md
View File

@ -1,10 +1,20 @@
# Changelog
## 6.1.0
## 6.1.1
Released 2018-mm-dd
New features:
Bug Fixes:
## 6.1.0
Released 2018-04-16
New features:
- Aggreation filters
- Upgrades Windshaft to 4.7.0, which includes @carto/mapnik v3.6.2-carto.7 with improvements to metrics and markers caching. It also adds an option to disable the markers symbolizer caches in mapnik.
Bug Fixes:
- Non-default aggregation selected the wrong columns (e.g. for vector tiles)

View File

@ -210,7 +210,12 @@ var config = {
'cache-features': true,
// Require metrics to the renderer
metrics: false
metrics: false,
// Options for markers attributes, ellipses and images caches
markers_symbolizer_caches: {
disabled: false
}
},
http: {
timeout: 2000, // the timeout in ms for a http tile request

View File

@ -205,8 +205,12 @@ var config = {
'cache-features': true,
// Require metrics to the renderer
metrics: false
metrics: false,
// Options for markers attributes, ellipses and images caches
markers_symbolizer_caches: {
disabled: false
}
},
http: {
timeout: 2000, // the timeout in ms for a http tile request

View File

@ -205,8 +205,12 @@ var config = {
'cache-features': true,
// Require metrics to the renderer
metrics: false
metrics: false,
// Options for markers attributes, ellipses and images caches
markers_symbolizer_caches: {
disabled: false
}
},
http: {
timeout: 2000, // the timeout in ms for a http tile request

View File

@ -1,7 +1,7 @@
{
"private": true,
"name": "windshaft-cartodb",
"version": "6.0.1",
"version": "6.1.1",
"description": "A map tile server for CartoDB",
"keywords": [
"cartodb"
@ -48,7 +48,7 @@
"step-profiler": "~0.3.0",
"turbo-carto": "0.20.2",
"underscore": "~1.6.0",
"windshaft": "4.6.0",
"windshaft": "4.7.0",
"yargs": "~5.0.0"
},
"devDependencies": {

View File

@ -37,31 +37,6 @@ describe('authorization', function() {
});
});
it.skip('should create and get a named map tile using a regular apikey token', function (done) {
const apikeyToken = 'regular1';
const mapConfig = {
version: '1.7.0',
layers: [
{
options: {
sql: 'select * FROM test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}
]
};
const testClient = new TestClient(mapConfig, apikeyToken);
testClient.getTile(0, 0, 0, function (err, res, tile) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.ok(tile instanceof mapnik.Image);
testClient.drain(done);
});
});
it('should fail getting a named map tile with default apikey token', function (done) {
const apikeyTokenCreate = 'regular1';
@ -354,110 +329,604 @@ describe('authorization', function() {
});
});
it('should fail while listing named maps with a regular apikey token', function (done) {
const apikeyToken = 'regular1';
describe('Named maps', function () {
describe('LIST Named maps', function () {
const testClient = new TestClient({}, apikeyToken);
it('should fail while listing named maps with a regular apikey token', function (done) {
const apikeyToken = 'regular1';
testClient.getNamedMapList({ response: {status: 403 }}, function (err, res, body) {
assert.ifError(err);
const testClient = new TestClient({}, apikeyToken);
assert.equal(res.statusCode, 403);
testClient.getNamedMapList({ response: { status: 403 } }, function (err, res, body) {
assert.ifError(err);
assert.equal(body.errors.length, 1);
assert.ok(body.errors[0].match(/Forbidden/), body.errors[0]);
assert.equal(res.statusCode, 403);
testClient.drain(done);
assert.equal(body.errors.length, 1);
assert.ok(body.errors[0].match(/Forbidden/), body.errors[0]);
testClient.drain(done);
});
});
it('should fail while listing named maps with the default apikey token', function (done) {
const apikeyToken = 'default_public';
const testClient = new TestClient({}, apikeyToken);
testClient.getNamedMapList({ response: { status: 403 } }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(body.errors.length, 1);
assert.ok(body.errors[0].match(/Forbidden/), body.errors[0]);
testClient.drain(done);
});
});
it('should fail while listing named maps with non-existent apikey token', function (done) {
const apikeyToken = 'wadus-wadus';
const testClient = new TestClient({}, apikeyToken);
testClient.getNamedMapList({ response: { status: 401 } }, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(body.errors.length, 1);
assert.ok(body.errors[0].match(/Unauthorized/), body.errors[0]);
testClient.drain(done);
});
});
it('should list named maps with master apikey token', function (done) {
const apikeyToken = 1234;
const testClient = new TestClient({}, apikeyToken);
testClient.getNamedMapList({}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.ok(Array.isArray(body.template_ids));
testClient.drain(done);
});
});
});
});
it('should list named maps with master apikey token', function (done) {
const apikeyToken = 1234;
const testClient = new TestClient({}, apikeyToken);
testClient.getNamedMapList({}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.ok(Array.isArray(body.template_ids));
testClient.drain(done);
});
});
it.skip('should create and get a named map tile using a regular apikey token', function (done) {
const apikeyToken = 'regular1';
const template = {
version: '0.0.1',
name: 'auth-api-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
},
layergroup: {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0',
describe('CREATE Named Map', function () {
const template = {
version: '0.0.1',
name: 'auth-api-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
}]
}
};
const testClient = new TestClient(template, apikeyToken);
testClient.getTile(0, 0, 0, function (err, res, tile) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.ok(tile instanceof mapnik.Image);
testClient.drain(done);
});
});
it.skip('should fail creating a named map using a regular apikey token and a private table', function (done) {
const apikeyToken = 'regular1';
const template = {
version: '0.0.1',
name: 'auth-api-template-private',
placeholders: {
buffersize: {
type: 'number',
default: 0
},
layergroup: {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0',
}
}]
}
},
layergroup: {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from populated_places_simple_reduced_private',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0',
}
}]
}
};
};
const testClient = new TestClient(template, apikeyToken);
it('should create and get a named map tile using the master apikey token', function (done) {
const apikeyToken = 1234;
testClient.getTile(0, 0, 0, { response: PERMISSION_DENIED_RESPONSE }, function (err, res, body) {
assert.ifError(err);
const testClient = new TestClient(template, apikeyToken);
assert.ok(body.hasOwnProperty('errors'));
assert.equal(body.errors.length, 1);
assert.ok(body.errors[0].match(/permission denied/), body.errors[0]);
testClient.getTile(0, 0, 0, function (err, res, tile) {
assert.ifError(err);
testClient.drain(done);
assert.equal(res.statusCode, 200);
assert.ok(tile instanceof mapnik.Image);
testClient.drain(done);
});
});
it('should fail creating a named map using a regular apikey token', function (done) {
const apikeyToken = 'regular1';
const testClient = new TestClient(template, apikeyToken);
testClient.createTemplate({ response: { status: 403 } }, function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClient.drain(done);
});
});
it('should fail creating a named map using the default apikey token', function (done) {
const apikeyToken = 'default_public';
const testClient = new TestClient(template, apikeyToken);
testClient.createTemplate({ response: { status: 403 } }, function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClient.drain(done);
});
});
it('should fail creating a named map using a non-existent apikey token', function (done) {
const apikeyToken = 'wadus-wadus';
const testClient = new TestClient(template, apikeyToken);
testClient.createTemplate({ response: { status: 401 } }, function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
testClient.drain(done);
});
});
});
describe('DELETE Named Map', function () {
const templateBase = {
version: '0.0.1',
name: 'auth-api-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
},
layergroup: {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0',
}
}]
}
};
it('should delete a named map using the master apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenDelete = 1234;
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-master' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient(template, apikeyTokenDelete);
testClientDelete.deleteTemplate(
{
templateId: template.template_id,
response: { status: 204 }
},
function (err, res) {
assert.ifError(err);
assert.equal(res.statusCode, 204);
testClientDelete.drain(done);
}
);
});
});
it('should fail deleting a named map using a regular apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenDelete = 'regular1';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-regular' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient({}, apikeyTokenDelete);
testClientDelete.deleteTemplate(
{
templateId: template.template_id,
response: { status: 403 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClientDelete.drain(done);
}
);
});
});
it('should fail deleting a named map using the default apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenDelete = 'default_public';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-default' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient(template, apikeyTokenDelete);
testClientDelete.deleteTemplate(
{
templateId: template.template_id,
response: { status: 403 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClientDelete.drain(done);
}
);
});
});
it('should fail deleting a named map using a non-existent apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenDelete = 'wadus';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-wadus' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient(template, apikeyTokenDelete);
testClientDelete.deleteTemplate(
{
templateId: template.template_id,
response: { status: 401 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
testClientDelete.drain(done);
}
);
});
});
});
describe('GET Named Map', function () {
const templateBase = {
version: '0.0.1',
name: 'auth-api-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
},
layergroup: {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0',
}
}]
}
};
it('should get a named map using the master apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenGet = 1234;
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-master' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient({}, apikeyTokenGet);
testClientDelete.getTemplate(
{
templateId: template.template_id,
response: { status: 200 }
},
function (err, res) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
testClientDelete.drain(done);
}
);
});
});
it('should fail getting a named map using a regular apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenGet = 'regular1';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-regular' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientGet = new TestClient({}, apikeyTokenGet);
testClientGet.getTemplate(
{
templateId: template.template_id,
response: { status: 403 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClientGet.drain(done);
}
);
});
});
it('should fail getting a named map using the default apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenGet = 'default_public';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-default' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientGet = new TestClient(template, apikeyTokenGet);
testClientGet.getTemplate(
{
templateId: template.template_id,
response: { status: 403 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClientGet.drain(done);
}
);
});
});
it('should fail getting a named map using a non-existent apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenGet = 'wadus';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-wadus' });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientGet = new TestClient(template, apikeyTokenGet);
testClientGet.getTemplate(
{
templateId: template.template_id,
response: { status: 401 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
testClientGet.drain(done);
}
);
});
});
});
describe('UPDATE Named Map', function () {
const templateBase = {
version: '0.0.1',
name: 'auth-api-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
},
layergroup: {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0',
}
}]
}
};
it('should update a named map using the master apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenUpdate = 1234;
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-master' });
const templateUpdate = Object.assign({}, template, { zoom: 3 });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
testClientDelete.updateTemplate(
{
templateId: template.template_id,
templateData: templateUpdate,
response: { status: 200 }
},
function (err, res) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
testClientDelete.drain(done);
}
);
});
});
it('should fail updating a named map using a regular apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenUpdate = 'regular1';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-regular' });
const templateUpdate = Object.assign({}, template, { zoom: 3 });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
testClientDelete.updateTemplate(
{
templateId: template.template_id,
templateData: templateUpdate,
response: { status: 403 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClientDelete.drain(done);
}
);
});
});
it('should fail updating a named map using the default apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenUpdate = 'default_public';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-default' });
const templateUpdate = Object.assign({}, template, { zoom: 3 });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
testClientDelete.updateTemplate(
{
templateId: template.template_id,
templateData: templateUpdate,
response: { status: 403 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
testClientDelete.drain(done);
}
);
});
});
it('should fail updating a named map using a non-existent apikey token', function (done) {
const apikeyTokenCreate = 1234;
const apikeyTokenUpdate = 'wadus';
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-wadus' });
const templateUpdate = Object.assign({}, template, { zoom: 3 });
const testClientCreate = new TestClient(template, apikeyTokenCreate);
testClientCreate.createTemplate({}, function (err, res, template) {
assert.ifError(err);
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
testClientDelete.updateTemplate(
{
templateId: template.template_id,
templateData: templateUpdate,
response: { status: 401 }
},
function (err, res, response) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert.equal(response.errors.length, 1);
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
testClientDelete.drain(done);
}
);
});
});
});
});
});

View File

@ -1,7 +1,7 @@
require('../support/test_helper');
var assert = require('../support/assert');
var TestClient = require('../support/test-client');
const LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
describe('regressions', function() {
@ -37,4 +37,131 @@ describe('regressions', function() {
testClient.drain(done);
});
});
describe('map instantiation', function () {
const apikeyToken = 'regular1';
const mapConfig = {
version: '1.7.0',
layers: [{
type: 'cartodb',
options: {
sql: 'select * from test_table_localhost_regular1',
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}]
};
it('should have distint timestamps when the source was updated', function (done) {
const testClient = new TestClient(mapConfig, apikeyToken);
testClient.getLayergroup({}, (err, layergroup) => {
if (err) {
return done(err);
}
const { cacheBuster: cacheBusterA } = LayergroupToken.parse(layergroup.layergroupid);
const conn = testClient.getDBConnection();
const sql = `select CDB_TableMetadataTouch('test_table_localhost_regular1'::regclass)`;
conn.query(sql, (err) => {
if (err) {
return done(err);
}
testClient.getLayergroup({}, (err, layergroup) => {
if (err) {
return done(err);
}
const { cacheBuster: cacheBusterB } = LayergroupToken.parse(layergroup.layergroupid);
const timestampA = parseInt(cacheBusterA, 10);
const timestampB = parseInt(cacheBusterB, 10);
assert.notEqual(timestampA, timestampB);
assert.ok(timestampA < timestampB, `timestampA: ${timestampA} > timestampB:${timestampB}`);
testClient.drain(done);
});
});
});
});
});
it('should create and instantiate a named map with filters', function (done) {
const apikeyToken = '1234';
const template = {
version: '0.0.1',
name: 'regression-dataview-filter-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
},
layergroup: {
version: '1.6.0',
layers: [
{
type: 'cartodb',
options: {
source: {
id: 'a1'
},
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}
],
dataviews: {
country_places_count: {
source: {
id: 'a1'
},
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
}
},
analyses: [
{
id: 'a1',
type: 'source',
params: {
query: 'select * from populated_places_simple_reduced'
}
}
]
}
};
const testClient = new TestClient(template, apikeyToken);
const params = {
own_filter: 1,
filters: {
dataviews: {
country_places_count: {
accept: ['CAN']
}
}
}
};
testClient.getDataview('country_places_count', params, (err, dataview) => {
assert.ifError(err);
assert.equal(dataview.type, 'aggregation');
assert.equal(dataview.categories.length, 1);
assert.deepEqual(dataview.categories[0], { value: 256, category: 'CAN', agg: false });
testClient.drain(done);
});
});
});

View File

@ -465,6 +465,8 @@ CREATE INDEX test_table_localhost_regular1_the_geom_webmercator_idx ON test_tabl
GRANT ALL ON TABLE test_table_localhost_regular1 TO :TESTUSER;
GRANT ALL ON TABLE test_table_localhost_regular1 TO test_windshaft_regular1;
INSERT INTO CDB_TableMetadata (tabname, updated_at) VALUES ('test_table_localhost_regular1'::regclass, '2009-02-13T23:31:30.123Z');
-- analysis tables -----------------------------------------------
ALTER TABLE cdb_analysis_catalog OWNER TO :TESTUSER;

View File

@ -358,6 +358,8 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
}
var url = '/api/v1/map';
var urlNamed = url + '/named';
if (Object.keys(extraParams).length > 0) {
url += '?' + qs.stringify(extraParams);
}
@ -370,17 +372,73 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
};
step(
function createLayergroup() {
function createTemplate () {
var next = this;
if (!self.template) {
return next();
}
if (!self.apiKey) {
return next(new Error('apiKey param is mandatory to create a new template'));
}
params.placeholders = params.placeholders || {};
assert.response(self.server,
{
url: url,
url: urlNamed + '?' + qs.stringify({ api_key: self.apiKey }),
method: 'POST',
headers: {
host: 'localhost',
'Content-Type': 'application/json'
},
data: JSON.stringify(self.mapConfig)
data: JSON.stringify(self.template)
},
{
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function (res, err) {
if (err) {
return next(err);
}
return next(null, JSON.parse(res.body).template_id);
}
);
},
function createLayergroup(err, templateId) {
assert.ifError(err);
var next = this;
var data = templateId ? params.placeholders : self.mapConfig;
const queryParams = {};
if (self.apiKey) {
queryParams.api_key = self.apiKey;
}
if (params.filters !== undefined) {
queryParams.filters = JSON.stringify(params.filters);
}
var path = templateId ?
urlNamed + '/' + templateId + '?' + qs.stringify(queryParams) :
url;
assert.response(self.server,
{
url: path,
method: 'POST',
headers: {
host: 'localhost',
'Content-Type': 'application/json'
},
data: JSON.stringify(data)
},
{
status: 200,
@ -1183,6 +1241,19 @@ TestClient.prototype.setUserRenderTimeoutLimit = function (user, userTimeoutLimi
helper.configureMetadata('hmset', params, callback);
};
TestClient.prototype.getDBConnection = function () {
const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db';
const psql = new PSQL({
user: 'postgres',
dbname: dbname,
host: global.environment.postgres.host,
port: global.environment.postgres.port
});
return psql;
};
TestClient.prototype.setUserDatabaseTimeoutLimit = function (timeoutLimit, callback) {
const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db';
const dbuser = _.template(global.environment.postgres_auth_user, { user_id: 1 });
@ -1367,3 +1438,162 @@ TestClient.prototype.getNamedTile = function (name, z, x, y, format, options, c
});
});
};
TestClient.prototype.createTemplate = function (params, callback) {
if (!this.apiKey) {
return callback(new Error('apiKey param is mandatory to create a new template'));
}
const createTemplateRequest = {
url: `/api/v1/map/named?${qs.stringify({ api_key: this.apiKey })}`,
method: 'POST',
headers: {
host: 'localhost',
'Content-Type': 'application/json'
},
data: JSON.stringify(this.template)
};
let createTemplateResponse = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
if (params.response) {
createTemplateResponse = Object.assign(createTemplateResponse, params.response);
}
assert.response(this.server, createTemplateRequest, createTemplateResponse, (res, err) => {
let body;
switch (res.headers['content-type']) {
case 'application/json; charset=utf-8':
body = JSON.parse(res.body);
break;
default:
body = res.body;
break;
}
return callback(err, res, body);
});
};
TestClient.prototype.deleteTemplate = function (params, callback) {
if (!this.apiKey) {
return callback(new Error('apiKey param is mandatory to create a new template'));
}
const deleteTemplateRequest = {
url: `/api/v1/map/named/${params.templateId}?${qs.stringify({ api_key: this.apiKey })}`,
method: 'DELETE',
headers: {
host: 'localhost',
}
};
let deleteTemplateResponse = {
status: 204,
headers: {}
};
if (params.response) {
deleteTemplateResponse = Object.assign(deleteTemplateResponse, params.response);
}
assert.response(this.server, deleteTemplateRequest, deleteTemplateResponse, (res, err) => {
let body;
switch (res.headers['content-type']) {
case 'application/json; charset=utf-8':
body = JSON.parse(res.body);
break;
default:
body = res.body;
break;
}
return callback(err, res, body);
});
};
TestClient.prototype.updateTemplate = function (params, callback) {
if (!this.apiKey) {
return callback(new Error('apiKey param is mandatory to create a new template'));
}
const updateTemplateRequest = {
url: `/api/v1/map/named/${params.templateId}?${qs.stringify({ api_key: this.apiKey })}`,
method: 'PUT',
headers: {
host: 'localhost',
'Content-Type': 'application/json; charset=utf-8'
},
data: JSON.stringify(params.templateData)
};
let updateTemplateResponse = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
if (params.response) {
updateTemplateResponse = Object.assign(updateTemplateResponse, params.response);
}
assert.response(this.server, updateTemplateRequest, updateTemplateResponse, (res, err) => {
let body;
switch (res.headers['content-type']) {
case 'application/json; charset=utf-8':
body = JSON.parse(res.body);
break;
default:
body = res.body;
break;
}
return callback(err, res, body);
});
};
TestClient.prototype.getTemplate = function (params, callback) {
if (!this.apiKey) {
return callback(new Error('apiKey param is mandatory to create a new template'));
}
const getTemplateRequest = {
url: `/api/v1/map/named/${params.templateId}?${qs.stringify({ api_key: this.apiKey })}`,
method: 'GET',
headers: {
host: 'localhost'
}
};
let getTemplateResponse = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
if (params.response) {
getTemplateResponse = Object.assign(getTemplateResponse, params.response);
}
assert.response(this.server, getTemplateRequest, getTemplateResponse, (res, err) => {
let body;
switch (res.headers['content-type']) {
case 'application/json; charset=utf-8':
body = JSON.parse(res.body);
break;
default:
body = res.body;
break;
}
return callback(err, res, body);
});
};

View File

@ -2,20 +2,20 @@
# yarn lockfile v1
"@carto/mapnik@3.6.2-carto.4":
version "3.6.2-carto.4"
resolved "https://registry.yarnpkg.com/@carto/mapnik/-/mapnik-3.6.2-carto.4.tgz#54042a5dbea293c54e1bd286b32277694c5dc2d2"
"@carto/mapnik@3.6.2-carto.7":
version "3.6.2-carto.7"
resolved "https://registry.yarnpkg.com/@carto/mapnik/-/mapnik-3.6.2-carto.7.tgz#ef057b0a379fec03bce92362a46f8d1729c950d9"
dependencies:
mapnik-vector-tile "1.5.0"
nan "~2.7.0"
node-pre-gyp "~0.6.30"
protozero "1.5.1"
"@carto/tilelive-bridge@cartodb/tilelive-bridge#2.5.1-cdb4":
version "2.5.1-cdb4"
resolved "https://codeload.github.com/cartodb/tilelive-bridge/tar.gz/3eb554e5109199f50f457cec72ee288cffa5d6b3"
"@carto/tilelive-bridge@cartodb/tilelive-bridge#2.5.1-cdb6":
version "2.5.1-cdb6"
resolved "https://codeload.github.com/cartodb/tilelive-bridge/tar.gz/1d71bc845f257d635f54047f1d2be858341cd552"
dependencies:
"@carto/mapnik" "3.6.2-carto.4"
"@carto/mapnik" "3.6.2-carto.7"
"@mapbox/sphericalmercator" "~1.0.1"
mapnik-pool "~0.1.3"
@ -23,11 +23,11 @@
version "1.0.5"
resolved "https://registry.yarnpkg.com/@mapbox/sphericalmercator/-/sphericalmercator-1.0.5.tgz#70237b9774095ed1cfdbcea7a8fd1fc82b2691f2"
abaculus@cartodb/abaculus#2.0.3-cdb5:
version "2.0.3-cdb5"
resolved "https://codeload.github.com/cartodb/abaculus/tar.gz/b899cbea04b3e6093aa3ef32331920acd5f839a1"
abaculus@cartodb/abaculus#2.0.3-cdb7:
version "2.0.3-cdb7"
resolved "https://codeload.github.com/cartodb/abaculus/tar.gz/fcdefbf39956c1c86ce3d39547b903857796657f"
dependencies:
"@carto/mapnik" "3.6.2-carto.4"
"@carto/mapnik" "3.6.2-carto.7"
d3-queue "^2.0.2"
sphericalmercator "1.0.x"
@ -861,9 +861,9 @@ graceful-fs@^4.1.2:
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
grainstore@1.8.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/grainstore/-/grainstore-1.8.2.tgz#79dd7a91a098bf8b0ea3189961775c8cc7474319"
grainstore@1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/grainstore/-/grainstore-1.9.0.tgz#4f7604bb83538dbfe5d7dbe63be3a7fa345a14f8"
dependencies:
carto "0.16.3"
debug "~3.1.0"
@ -2239,11 +2239,11 @@ through@2:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
tilelive-mapnik@cartodb/tilelive-mapnik#0.6.18-cdb8:
version "0.6.18-cdb8"
resolved "https://codeload.github.com/cartodb/tilelive-mapnik/tar.gz/9cb4546c8fdd34ced0a41dbf70e143475b4e2067"
tilelive-mapnik@cartodb/tilelive-mapnik#0.6.18-cdb11:
version "0.6.18-cdb11"
resolved "https://codeload.github.com/cartodb/tilelive-mapnik/tar.gz/90b7a2d4a7032b72c15b0d3ea1a6ec8258a4a250"
dependencies:
"@carto/mapnik" "3.6.2-carto.4"
"@carto/mapnik" "3.6.2-carto.7"
generic-pool "~2.4.0"
mime "~1.6.0"
sphericalmercator "~1.0.4"
@ -2400,19 +2400,19 @@ window-size@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.2.0.tgz#b4315bb4214a3d7058ebeee892e13fa24d98b075"
windshaft@4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/windshaft/-/windshaft-4.6.0.tgz#d9394aff73c0aa761207ad2b0f12d1c23ac41244"
windshaft@4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/windshaft/-/windshaft-4.7.0.tgz#6fdee3c8c9b28b15835981d1ef565a52884e951c"
dependencies:
"@carto/mapnik" "3.6.2-carto.4"
"@carto/tilelive-bridge" cartodb/tilelive-bridge#2.5.1-cdb4
abaculus cartodb/abaculus#2.0.3-cdb5
"@carto/mapnik" "3.6.2-carto.7"
"@carto/tilelive-bridge" cartodb/tilelive-bridge#2.5.1-cdb6
abaculus cartodb/abaculus#2.0.3-cdb7
canvas cartodb/node-canvas#1.6.2-cdb2
carto cartodb/carto#0.15.1-cdb3
cartodb-psql "^0.10.1"
debug "^3.1.0"
dot "~1.0.2"
grainstore "1.8.2"
grainstore "1.9.0"
queue-async "~1.0.7"
redis-mpool "^0.5.0"
request "2.85.0"
@ -2420,7 +2420,7 @@ windshaft@4.6.0:
sphericalmercator "1.0.4"
step "~0.0.6"
tilelive "5.12.2"
tilelive-mapnik cartodb/tilelive-mapnik#0.6.18-cdb8
tilelive-mapnik cartodb/tilelive-mapnik#0.6.18-cdb11
torque.js "~2.11.0"
underscore "~1.6.0"