Use strict mode

This commit is contained in:
Daniel García Aubert 2018-10-24 15:42:33 +02:00
parent cf5ad64fd4
commit a616982ec3
116 changed files with 314 additions and 91 deletions

2
app.js
View File

@ -1,5 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict';
/* /*
* SQL API loader * SQL API loader
* =============== * ===============

View File

@ -1,3 +1,5 @@
'use strict';
/** /**
* this module allows to auth user using an pregenerated api key * this module allows to auth user using an pregenerated api key
*/ */
@ -32,7 +34,7 @@ ApikeyAuth.prototype.verifyCredentials = function (callback) {
return callback(usernameError); return callback(usernameError);
} }
if (!apikey.grantsSql) { if (!apikey.grantsSql) {
const forbiddenError = new Error('forbidden'); const forbiddenError = new Error('forbidden');
forbiddenError.http_status = 403; forbiddenError.http_status = 403;
@ -47,8 +49,8 @@ ApikeyAuth.prototype.verifyCredentials = function (callback) {
apiKeyNotFoundError.subtype = 'api-key-not-found'; apiKeyNotFoundError.subtype = 'api-key-not-found';
apiKeyNotFoundError.http_status = 401; apiKeyNotFoundError.http_status = 401;
return callback(apiKeyNotFoundError); return callback(apiKeyNotFoundError);
} }
}); });
}; };

View File

@ -1,3 +1,5 @@
'use strict';
var ApiKeyAuth = require('./apikey'), var ApiKeyAuth = require('./apikey'),
OAuthAuth = require('./oauth'); OAuthAuth = require('./oauth');

View File

@ -1,3 +1,5 @@
'use strict';
// too bound to the request object, but ok for now // too bound to the request object, but ok for now
var _ = require('underscore'); var _ = require('underscore');
var OAuthUtil = require('oauth-client'); var OAuthUtil = require('oauth-client');

View File

@ -1,3 +1,5 @@
'use strict';
const util = require('util'); const util = require('util');
const bodyParserMiddleware = require('../middlewares/body-parser'); const bodyParserMiddleware = require('../middlewares/body-parser');
@ -30,25 +32,25 @@ JobController.prototype.route = function (app) {
); );
app.get( app.get(
`${base_url}/jobs-wip`, `${base_url}/jobs-wip`,
bodyParserMiddleware(), bodyParserMiddleware(),
listWorkInProgressJobs(this.jobService), listWorkInProgressJobs(this.jobService),
sendResponse(), sendResponse(),
errorMiddleware() errorMiddleware()
); );
app.post( app.post(
`${base_url}/sql/job`, `${base_url}/sql/job`,
bodyParserMiddleware(), bodyParserMiddleware(),
checkBodyPayloadSize(), checkBodyPayloadSize(),
jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE) jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE)
); );
app.get( app.get(
`${base_url}/sql/job/:job_id`, `${base_url}/sql/job/:job_id`,
bodyParserMiddleware(), bodyParserMiddleware(),
jobMiddlewares('retrieve', getJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_GET) jobMiddlewares('retrieve', getJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_GET)
); );
app.delete( app.delete(
`${base_url}/sql/job/:job_id`, `${base_url}/sql/job/:job_id`,
bodyParserMiddleware(), bodyParserMiddleware(),
jobMiddlewares('cancel', cancelJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_DELETE) jobMiddlewares('cancel', cancelJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_DELETE)
); );

View File

@ -1,3 +1,5 @@
'use strict';
const AuthApi = require('../auth/auth_api'); const AuthApi = require('../auth/auth_api');
const basicAuth = require('basic-auth'); const basicAuth = require('basic-auth');

View File

@ -1,3 +1,4 @@
'use strict';
/*! /*!
* Connect - bodyParser * Connect - bodyParser

View File

@ -1,3 +1,5 @@
'use strict';
module.exports = function connectionParams (userDatabaseService) { module.exports = function connectionParams (userDatabaseService) {
return function connectionParamsMiddleware (req, res, next) { return function connectionParamsMiddleware (req, res, next) {
const { user, api_key: apikeyToken, authorizationLevel } = res.locals; const { user, api_key: apikeyToken, authorizationLevel } = res.locals;

View File

@ -1,3 +1,5 @@
'use strict';
const PSQL = require('cartodb-psql'); const PSQL = require('cartodb-psql');
const remainingQuotaQuery = 'SELECT _CDB_UserQuotaInBytes() - CDB_UserDataSize(current_schema()) AS remaining_quota'; const remainingQuotaQuery = 'SELECT _CDB_UserQuotaInBytes() - CDB_UserDataSize(current_schema()) AS remaining_quota';

View File

@ -1,3 +1,5 @@
'use strict';
const errorHandlerFactory = require('../services/error_handler_factory'); const errorHandlerFactory = require('../services/error_handler_factory');
module.exports = function error() { module.exports = function error() {

View File

@ -1,3 +1,5 @@
'use strict';
module.exports.initializeProfilerMiddleware = function initializeProfiler (label) { module.exports.initializeProfilerMiddleware = function initializeProfiler (label) {
return function initializeProfilerMiddleware (req, res, next) { return function initializeProfilerMiddleware (req, res, next) {
if (req.profiler) { if (req.profiler) {

View File

@ -1,3 +1,5 @@
'use strict';
module.exports = function timeoutLimits (metadataBackend) { module.exports = function timeoutLimits (metadataBackend) {
return function timeoutLimitsMiddleware (req, res, next) { return function timeoutLimitsMiddleware (req, res, next) {
const { user, authorizationLevel } = res.locals; const { user, authorizationLevel } = res.locals;

View File

@ -1,3 +1,5 @@
'use strict';
const CdbRequest = require('../models/cartodb_request'); const CdbRequest = require('../models/cartodb_request');
module.exports = function user(metadataBackend) { module.exports = function user(metadataBackend) {

View File

@ -1,3 +1,4 @@
'use strict';
function ArrayBufferSer(type, data, options) { function ArrayBufferSer(type, data, options) {
if(type === undefined) { if(type === undefined) {
@ -83,7 +84,7 @@ ArrayBufferSer.prototype = {
s = 0; s = 0;
if(this.type === ArrayBufferSer.STRING) { if(this.type === ArrayBufferSer.STRING) {
// calculate size with padding // calculate size with padding
t.forEach(function(arr) { t.forEach(function(arr) {
var pad = self._paddingFor(offset, ArrayBufferSer.MAX_PADDING); var pad = self._paddingFor(offset, ArrayBufferSer.MAX_PADDING);
s += pad; s += pad;
offset += pad; offset += pad;

View File

@ -1,3 +1,5 @@
'use strict';
/** /**
* this module provides cartodb-specific interpretation * this module provides cartodb-specific interpretation
* of request headers * of request headers

View File

@ -1,3 +1,5 @@
'use strict';
var fs = require("fs"); var fs = require("fs");
var formats = {}; var formats = {};

View File

@ -1,3 +1,5 @@
'use strict';
var crypto = require('crypto'); var crypto = require('crypto');
var step = require('step'); var step = require('step');
var fs = require('fs'); var fs = require('fs');

View File

@ -1,3 +1,5 @@
'use strict';
var ogr = require('./../ogr'); var ogr = require('./../ogr');
function CsvFormat() {} function CsvFormat() {}

View File

@ -1,3 +1,5 @@
'use strict';
var ogr = require('./../ogr'); var ogr = require('./../ogr');
function GeoPackageFormat() {} function GeoPackageFormat() {}

View File

@ -1,3 +1,5 @@
'use strict';
var ogr = require('./../ogr'); var ogr = require('./../ogr');
function KmlFormat() {} function KmlFormat() {}

View File

@ -1,3 +1,5 @@
'use strict';
var step = require('step'); var step = require('step');
var fs = require('fs'); var fs = require('fs');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;

View File

@ -1,3 +1,5 @@
'use strict';
var ogr = require('./../ogr'); var ogr = require('./../ogr');
function SpatiaLiteFormat() {} function SpatiaLiteFormat() {}

View File

@ -1,3 +1,5 @@
'use strict';
var step = require('step'); var step = require('step');
var PSQL = require('cartodb-psql'); var PSQL = require('cartodb-psql');
var assert = require('assert'); var assert = require('assert');

View File

@ -1,3 +1,5 @@
'use strict';
var _ = require('underscore'); var _ = require('underscore');
var pg = require('./../pg'); var pg = require('./../pg');
@ -22,7 +24,7 @@ BinaryFormat.prototype.transform = function(result, options, callback) {
var total_rows = result.rowCount; var total_rows = result.rowCount;
var rows = result.rows; var rows = result.rows;
// get headers // get headers
if(!total_rows) { if(!total_rows) {
callback(null, new Buffer(0)); callback(null, new Buffer(0));
return; return;
@ -62,7 +64,7 @@ BinaryFormat.prototype.transform = function(result, options, callback) {
var d = []; var d = [];
var n = headersNames[i]; var n = headersNames[i];
for(var r = 0; r < total_rows; ++r) { for(var r = 0; r < total_rows; ++r) {
var row = rows[r][n]; var row = rows[r][n];
if(headerTypes[i] > ArrayBufferSer.BUFFER) { if(headerTypes[i] > ArrayBufferSer.BUFFER) {
row = new ArrayBufferSer(headerTypes[i] - ArrayBufferSer.BUFFER, row); row = new ArrayBufferSer(headerTypes[i] - ArrayBufferSer.BUFFER, row);
} }

View File

@ -1,3 +1,5 @@
'use strict';
var _ = require('underscore'); var _ = require('underscore');
var pg = require('./../pg'); var pg = require('./../pg');

View File

@ -1,3 +1,5 @@
'use strict';
var _ = require('underscore'); var _ = require('underscore');
var pg = require('./../pg'); var pg = require('./../pg');

View File

@ -1,3 +1,5 @@
'use strict';
var pg = require('./../pg'); var pg = require('./../pg');
var svg_width = 1024.0; var svg_width = 1024.0;

View File

@ -1,3 +1,5 @@
'use strict';
var pg = require('./../pg'); var pg = require('./../pg');
var _ = require('underscore'); var _ = require('underscore');
var geojson = require('./geojson'); var geojson = require('./geojson');

View File

@ -1,3 +1,5 @@
'use strict';
var step = require('step'), var step = require('step'),
fs = require('fs'); fs = require('fs');

View File

@ -1,3 +1,5 @@
'use strict';
var _ = require('underscore'); var _ = require('underscore');
// reference http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html // reference http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html

View File

@ -1,3 +1,5 @@
'use strict';
// CartoDB SQL API // CartoDB SQL API
// //
// all requests expect the following URL args: // all requests expect the following URL args:

View File

@ -1,3 +1,5 @@
'use strict';
var QueryTables = require('cartodb-query-tables'); var QueryTables = require('cartodb-query-tables');
var generateMD5 = require('../utils/md5'); var generateMD5 = require('../utils/md5');

View File

@ -1,3 +1,5 @@
'use strict';
class ErrorHandler extends Error { class ErrorHandler extends Error {
constructor({ message, context, detail, hint, http_status, name }) { constructor({ message, context, detail, hint, http_status, name }) {
super(message); super(message);

View File

@ -1,3 +1,5 @@
'use strict';
const ErrorHandler = require('./error_handler'); const ErrorHandler = require('./error_handler');
const { codeToCondition } = require('../postgresql/error_codes'); const { codeToCondition } = require('../postgresql/error_codes');

View File

@ -1,3 +1,5 @@
'use strict';
const FORBIDDEN_ENTITIES = { const FORBIDDEN_ENTITIES = {
carto: ['*'], carto: ['*'],
cartodb: [ cartodb: [
@ -56,6 +58,6 @@ const Validator = {
return true; return true;
} }
}; };
module.exports = Validator; module.exports = Validator;

View File

@ -1,3 +1,5 @@
'use strict';
const PSQL = require('cartodb-psql'); const PSQL = require('cartodb-psql');
const copyTo = require('pg-copy-streams').to; const copyTo = require('pg-copy-streams').to;
const copyFrom = require('pg-copy-streams').from; const copyFrom = require('pg-copy-streams').from;

View File

@ -1,3 +1,5 @@
'use strict';
const { getFormatFromCopyQuery } = require('../utils/query_info'); const { getFormatFromCopyQuery } = require('../utils/query_info');
module.exports = class StreamCopyMetrics { module.exports = class StreamCopyMetrics {

View File

@ -1,3 +1,5 @@
'use strict';
function isApiKeyFound(apikey) { function isApiKeyFound(apikey) {
return apikey.type !== null && return apikey.type !== null &&
apikey.user !== null && apikey.user !== null &&
@ -43,7 +45,7 @@ UserDatabaseService.prototype.getConnectionParams = function (username, apikeyTo
}; };
this.metadataBackend.getMasterApikey(username, (err, masterApikey) => { this.metadataBackend.getMasterApikey(username, (err, masterApikey) => {
if (err) { if (err) {
err.http_status = 404; err.http_status = 404;
err.message = errorUserNotFoundMessageTemplate(username); err.message = errorUserNotFoundMessageTemplate(username);

View File

@ -1,7 +1,9 @@
'use strict';
/** /**
* UserLimits * UserLimits
* @param {cartodb-redis} metadataBackend * @param {cartodb-redis} metadataBackend
* @param {object} options * @param {object} options
*/ */
class UserLimits { class UserLimits {
constructor(metadataBackend, options = {}) { constructor(metadataBackend, options = {}) {

View File

@ -1,3 +1,5 @@
'use strict';
var _ = require('underscore'); var _ = require('underscore');
var debug = require('debug')('windshaft:stats_client'); var debug = require('debug')('windshaft:stats_client');
var StatsD = require('node-statsd').StatsD; var StatsD = require('node-statsd').StatsD;
@ -70,4 +72,4 @@ module.exports = {
return this.instance; return this.instance;
} }
}; };

View File

@ -1,3 +1,5 @@
'use strict';
var Profiler = require('step-profiler'); var Profiler = require('step-profiler');
/** /**

View File

@ -1,3 +1,5 @@
'use strict';
const COPY_FORMATS = ['TEXT', 'CSV', 'BINARY']; const COPY_FORMATS = ['TEXT', 'CSV', 'BINARY'];
module.exports = { module.exports = {
@ -9,11 +11,11 @@ module.exports = {
if (!copyQuery.startsWith("COPY ")) { if (!copyQuery.startsWith("COPY ")) {
return false; return false;
} }
if(copyQuery.includes(' WITH') && copyQuery.includes('FORMAT ')) { if(copyQuery.includes(' WITH') && copyQuery.includes('FORMAT ')) {
const regex = /\bFORMAT\s+(\w+)/; const regex = /\bFORMAT\s+(\w+)/;
const result = regex.exec(copyQuery); const result = regex.exec(copyQuery);
if (result && result.length === 2) { if (result && result.length === 2) {
if (COPY_FORMATS.includes(result[1])) { if (COPY_FORMATS.includes(result[1])) {
format = result[1]; format = result[1];

View File

@ -1,4 +1,4 @@
'use strict';
function ArrayBufferSer(arrayBuffer) { function ArrayBufferSer(arrayBuffer) {
this.buffer = arrayBuffer; this.buffer = arrayBuffer;

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
/** /**
* *
* Requires the database and tables setup in config/environments/test.js to exist * Requires the database and tables setup in config/environments/test.js to exist

View File

@ -1,3 +1,5 @@
'use strict';
const assert = require('../support/assert'); const assert = require('../support/assert');
const TestClient = require('../support/test-client'); const TestClient = require('../support/test-client');
const BatchTestClient = require('../support/batch-test-client'); const BatchTestClient = require('../support/batch-test-client');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var assert = require('../support/assert'); var assert = require('../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');
var redisUtils = require('../../support/redis_utils'); var redisUtils = require('../../support/redis_utils');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
/** /**
* *
* Requires the database and tables setup in config/environments/test.js to exist * Requires the database and tables setup in config/environments/test.js to exist

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
/** /**
* *
* Requires the database and tables setup in config/environments/test.js to exist * Requires the database and tables setup in config/environments/test.js to exist

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var BatchTestClient = require('../../support/batch-test-client'); var BatchTestClient = require('../../support/batch-test-client');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');

View File

@ -1,4 +1,4 @@
'use const'; 'use strict';
var server = require('../../app/server')(); var server = require('../../app/server')();
const assert = require('../support/assert'); const assert = require('../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
const querystring = require('querystring'); const querystring = require('querystring');
const StatsClient = require('../../app/stats/client'); const StatsClient = require('../../app/stats/client');
const statsClient = StatsClient.getInstance(global.settings.statsd); const statsClient = StatsClient.getInstance(global.settings.statsd);

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
const fs = require('fs'); const fs = require('fs');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,7 +1,9 @@
'use strict';
var server = require('../../app/server')(); var server = require('../../app/server')();
var assert = require('../support/assert'); var assert = require('../support/assert');
describe('error handler', function () { describe('error handler', function () {
it('should returns a errors header', function (done) { it('should returns a errors header', function (done) {
const errorHeader = { const errorHeader = {
detail: undefined, detail: undefined,
@ -22,7 +24,7 @@ describe('error handler', function () {
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
'X-SQLAPI-Errors': JSON.stringify(errorHeader) 'X-SQLAPI-Errors': JSON.stringify(errorHeader)
} }
}, },
function(err){ function(err){
assert.ifError(err); assert.ifError(err);
done(); done();

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
require('../../support/assert'); require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
require('../../support/assert'); require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
require('../../support/assert'); require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();
@ -34,7 +36,7 @@ it('GET /api/v1/sql with SQL parameter, ensuring content-disposition set to geoj
it('POST /api/v1/sql with SQL parameter, ensuring content-disposition set to geojson', function(done) { it('POST /api/v1/sql with SQL parameter, ensuring content-disposition set to geojson', function(done) {
assert.response(server, { assert.response(server, {
url: '/api/v1/sql', url: '/api/v1/sql',
data: querystring.stringify({q: "SELECT * FROM untitle_table_4", format: 'geojson' }), data: querystring.stringify({q: "SELECT * FROM untitle_table_4", format: 'geojson' }),
headers: {host: 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' }, headers: {host: 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'POST' method: 'POST'

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
const TestClient = require('../../support/test-client'); const TestClient = require('../../support/test-client');
require('../../support/assert'); require('../../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../../helper'); require('../../helper');
var server = require('../../../app/server')(); var server = require('../../../app/server')();
@ -46,7 +48,7 @@ it('GET two polygons sharing an edge as topojson', function(done){
var trans = topojson.transform; var trans = topojson.transform;
assert.equal(_.keys(trans).length, 2); // only scale and translate assert.equal(_.keys(trans).length, 2); // only scale and translate
assert.equal(trans.scale.length, 2); // scalex, scaley assert.equal(trans.scale.length, 2); // scalex, scaley
assert.equal(Math.round(trans.scale[0]*1e6), 1000); assert.equal(Math.round(trans.scale[0]*1e6), 1000);
assert.equal(Math.round(trans.scale[1]*1e6), 1000); assert.equal(Math.round(trans.scale[1]*1e6), 1000);
assert.equal(trans.translate.length, 2); // translatex, translatey assert.equal(trans.translate.length, 2); // translatex, translatey
assert.equal(trans.translate[0], -5); assert.equal(trans.translate[0], -5);
@ -58,7 +60,7 @@ it('GET two polygons sharing an edge as topojson', function(done){
var obj = topojson.objects[0]; var obj = topojson.objects[0];
//console.dir(obj); //console.dir(obj);
// Expected: // Expected:
// { type: 'Polygon', // { type: 'Polygon',
// arcs: [ [ 0, 1 ] ], // arcs: [ [ 0, 1 ] ],
// properties: { gid: 1, nam: 'U' } } // properties: { gid: 1, nam: 'U' } }
@ -74,9 +76,9 @@ it('GET two polygons sharing an edge as topojson', function(done){
assert.equal(props.gid, 1); assert.equal(props.gid, 1);
assert.equal(props.name, 'U'); assert.equal(props.name, 'U');
obj = topojson.objects[1]; obj = topojson.objects[1];
//console.dir(obj); //console.dir(obj);
// Expected: // Expected:
// { type: 'Polygon', // { type: 'Polygon',
// arcs: [ [ 0, 2 ] ], // arcs: [ [ 0, 2 ] ],
// properties: { gid: 2, nam: 'D' } } // properties: { gid: 2, nam: 'D' } }
@ -94,37 +96,37 @@ it('GET two polygons sharing an edge as topojson', function(done){
// Check arcs // Check arcs
assert.ok(topojson.hasOwnProperty('arcs')); assert.ok(topojson.hasOwnProperty('arcs'));
assert.equal(topojson.arcs.length, 3); // one shared, two non-shared assert.equal(topojson.arcs.length, 3); // one shared, two non-shared
var arc = topojson.arcs[0]; // shared arc var arc = topojson.arcs[0]; // shared arc
assert.equal(arc.length, 2); // shared arc has two vertices assert.equal(arc.length, 2); // shared arc has two vertices
var p = arc[0]; var p = arc[0];
assert.equal(Math.round(p[0]*trans.scale[0]), 0); assert.equal(Math.round(p[0]*trans.scale[0]), 0);
assert.equal(Math.round(p[1]*trans.scale[1]), 5); assert.equal(Math.round(p[1]*trans.scale[1]), 5);
p = arc[1]; p = arc[1];
assert.equal(Math.round(p[0]*trans.scale[0]), 5); assert.equal(Math.round(p[0]*trans.scale[0]), 5);
assert.equal(Math.round(p[1]*trans.scale[1]), 5); assert.equal(Math.round(p[1]*trans.scale[1]), 5);
arc = topojson.arcs[1]; // non shared arc arc = topojson.arcs[1]; // non shared arc
assert.equal(arc.length, 3); // non shared arcs have three vertices assert.equal(arc.length, 3); // non shared arcs have three vertices
p = arc[0]; p = arc[0];
assert.equal(Math.round(p[0]*trans.scale[0]), 5); assert.equal(Math.round(p[0]*trans.scale[0]), 5);
assert.equal(Math.round(p[1]*trans.scale[1]), 10); assert.equal(Math.round(p[1]*trans.scale[1]), 10);
p = arc[1]; p = arc[1];
assert.equal(Math.round(p[0]*trans.scale[0]), 5); assert.equal(Math.round(p[0]*trans.scale[0]), 5);
assert.equal(Math.round(p[1]*trans.scale[1]), -5); assert.equal(Math.round(p[1]*trans.scale[1]), -5);
p = arc[2]; p = arc[2];
assert.equal(Math.round(p[0]*trans.scale[0]), -10); assert.equal(Math.round(p[0]*trans.scale[0]), -10);
assert.equal(Math.round(p[1]*trans.scale[1]), 0); assert.equal(Math.round(p[1]*trans.scale[1]), 0);
arc = topojson.arcs[2]; // non shared arc arc = topojson.arcs[2]; // non shared arc
assert.equal(arc.length, 3); // non shared arcs have three vertices assert.equal(arc.length, 3); // non shared arcs have three vertices
p = arc[0]; p = arc[0];
assert.equal(Math.round(p[0]*trans.scale[0]), 5); assert.equal(Math.round(p[0]*trans.scale[0]), 5);
assert.equal(Math.round(p[1]*trans.scale[1]), 10); assert.equal(Math.round(p[1]*trans.scale[1]), 10);
p = arc[1]; p = arc[1];
assert.equal(Math.round(p[0]*trans.scale[0]), 0); assert.equal(Math.round(p[0]*trans.scale[0]), 0);
assert.equal(Math.round(p[1]*trans.scale[1]), -10); assert.equal(Math.round(p[1]*trans.scale[1]), -10);
p = arc[2]; p = arc[2];
assert.equal(Math.round(p[0]*trans.scale[0]), -5); assert.equal(Math.round(p[0]*trans.scale[0]), -5);
assert.equal(Math.round(p[1]*trans.scale[1]), 5); assert.equal(Math.round(p[1]*trans.scale[1]), 5);
done(); done();
}); });
@ -151,7 +153,7 @@ it('null geometries', function(done){
var trans = topojson.transform; var trans = topojson.transform;
assert.equal(_.keys(trans).length, 2); // only scale and translate assert.equal(_.keys(trans).length, 2); // only scale and translate
assert.equal(trans.scale.length, 2); // scalex, scaley assert.equal(trans.scale.length, 2); // scalex, scaley
assert.equal(Math.round(trans.scale[0]*1e6), 1000); assert.equal(Math.round(trans.scale[0]*1e6), 1000);
assert.equal(Math.round(trans.scale[1]*1e6), 500); assert.equal(Math.round(trans.scale[1]*1e6), 500);
assert.equal(trans.translate.length, 2); // translatex, translatey assert.equal(trans.translate.length, 2); // translatex, translatey
assert.equal(trans.translate[0], -5); assert.equal(trans.translate[0], -5);
@ -163,7 +165,7 @@ it('null geometries', function(done){
var obj = topojson.objects[0]; var obj = topojson.objects[0];
//console.dir(obj); //console.dir(obj);
// Expected: // Expected:
// { type: 'Polygon', // { type: 'Polygon',
// arcs: [ [ 0, 1 ] ], // arcs: [ [ 0, 1 ] ],
// properties: { gid: 1, nam: 'U' } } // properties: { gid: 1, nam: 'U' } }
@ -180,8 +182,8 @@ it('null geometries', function(done){
// Check arcs // Check arcs
assert.ok(topojson.hasOwnProperty('arcs')); assert.ok(topojson.hasOwnProperty('arcs'));
assert.equal(topojson.arcs.length, 1); assert.equal(topojson.arcs.length, 1);
var arc = topojson.arcs[0]; var arc = topojson.arcs[0];
assert.deepEqual(arc, [ [ 0, 0 ], [ 4999, 9999 ], [ 5000, -9999 ], [ -9999, 0 ] ]); assert.deepEqual(arc, [ [ 0, 0 ], [ 4999, 9999 ], [ 5000, -9999 ], [ -9999, 0 ] ]);
done(); done();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var assert = require('../support/assert'); var assert = require('../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
require('../support/assert'); require('../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var appServer = require('../../app/server'); var appServer = require('../../app/server');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
const assert = require('../support/assert'); const assert = require('../support/assert');
const TestClient = require('../support/test-client'); const TestClient = require('../support/test-client');
@ -26,25 +28,25 @@ describe('PG entities access validator', function () {
describe('validatePGEntitiesAccess enabled', function() { describe('validatePGEntitiesAccess enabled', function() {
before(function(){ before(function(){
global.settings.validatePGEntitiesAccess = true; global.settings.validatePGEntitiesAccess = true;
}); });
forbiddenQueries.forEach(query => { forbiddenQueries.forEach(query => {
it(`testClientApiKey: query: ${query}`, function(done) { it(`testClientApiKey: query: ${query}`, function(done) {
assertQuery(query, testClientApiKey, done); assertQuery(query, testClientApiKey, done);
}); });
it(`testClientAuthorized: query: ${query}`, function(done) { it(`testClientAuthorized: query: ${query}`, function(done) {
assertQuery(query, testClientAuthorized, done); assertQuery(query, testClientAuthorized, done);
}); });
}); });
}); });
describe('validatePGEntitiesAccess disabled', function() { describe('validatePGEntitiesAccess disabled', function() {
before(function(){ before(function(){
global.settings.validatePGEntitiesAccess = false; global.settings.validatePGEntitiesAccess = false;
}); });
forbiddenQueries.forEach(query => { forbiddenQueries.forEach(query => {
it(`testClientApiKey: query: ${query}`, function(done) { it(`testClientApiKey: query: ${query}`, function(done) {
testClientApiKey.getResult(query, err => { testClientApiKey.getResult(query, err => {
@ -52,13 +54,13 @@ describe('PG entities access validator', function () {
done(); done();
}); });
}); });
it(`testClientAuthorized: query: ${query}`, function(done) { it(`testClientAuthorized: query: ${query}`, function(done) {
testClientAuthorized.getResult(query, err => { testClientAuthorized.getResult(query, err => {
assert.ifError(err); assert.ifError(err);
done(); done();
}); });
}); });
}); });
}); });
}); });

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
const server = require('../../app/server')(); const server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var qs = require('querystring'); var qs = require('querystring');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
const qs = require('querystring'); const qs = require('querystring');
@ -30,7 +32,7 @@ function setLimit(count, period, burst) {
return; return;
} }
const key = `limits:rate:store:${user}:sql:${RATE_LIMIT_ENDPOINTS_GROUPS.QUERY}`; const key = `limits:rate:store:${user}:sql:${RATE_LIMIT_ENDPOINTS_GROUPS.QUERY}`;
redisClient.rpush(key, burst); redisClient.rpush(key, burst);
redisClient.rpush(key, count); redisClient.rpush(key, count);
redisClient.rpush(key, period); redisClient.rpush(key, period);
@ -40,9 +42,9 @@ function setLimit(count, period, burst) {
function assertRequest (status, limit, remaining, reset, retry, done = null) { function assertRequest (status, limit, remaining, reset, retry, done = null) {
assert.response( assert.response(
server, server,
request, request,
{ status }, { status },
function(err, res) { function(err, res) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.headers['carto-rate-limit-limit'], limit); assert.equal(res.headers['carto-rate-limit-limit'], limit);
@ -53,10 +55,10 @@ function assertRequest (status, limit, remaining, reset, retry, done = null) {
assert.equal(res.headers['retry-after'], retry); assert.equal(res.headers['retry-after'], retry);
} }
if(status === 429) { if(status === 429) {
const expectedResponse = { const expectedResponse = {
error: ["You are over platform\'s limits. Please contact us to know more details"], error: ["You are over platform\'s limits. Please contact us to know more details"],
context: "limit", context: "limit",
detail: "rate-limit" detail: "rate-limit"
}; };
@ -74,7 +76,7 @@ describe('rate limit', function() {
before(function() { before(function() {
global.settings.ratelimits.rateLimitsEnabled = true; global.settings.ratelimits.rateLimitsEnabled = true;
global.settings.ratelimits.endpoints.query = true; global.settings.ratelimits.endpoints.query = true;
server = app(); server = app();
redisClient = redis.createClient(global.settings.redis_port); redisClient = redis.createClient(global.settings.redis_port);
@ -94,7 +96,7 @@ describe('rate limit', function() {
}); });
it("1 req/sec: 2 req/seg should be limited", function(done) { it("1 req/sec: 2 req/seg should be limited", function(done) {
assertRequest(200, 2, 1, 1); assertRequest(200, 2, 1, 1);
setTimeout( () => assertRequest(200, 2, 0, 1, null), 250 ); setTimeout( () => assertRequest(200, 2, 0, 1, null), 250 );
setTimeout( () => assertRequest(429, 2, 0, 1, 1), 500 ); setTimeout( () => assertRequest(429, 2, 0, 1, 1), 500 );
setTimeout( () => assertRequest(429, 2, 0, 1, 1), 750 ); setTimeout( () => assertRequest(429, 2, 0, 1, 1), 750 );

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();
@ -64,7 +66,7 @@ describe('Surrogate-Key header', function() {
{dbname: 'cartodb_test_user_1_db', schema_name: 'public', table_name: 'untitle_table_4'} {dbname: 'cartodb_test_user_1_db', schema_name: 'public', table_name: 'untitle_table_4'}
], done)); ], done));
}); });
it('supports explicit transactions', function(done) { it('supports explicit transactions', function(done) {
var sql = "BEGIN; SELECT * FROM untitle_table_4; COMMIT; BEGIN; SELECT * FROM private_table; COMMIT;"; var sql = "BEGIN; SELECT * FROM untitle_table_4; COMMIT; BEGIN; SELECT * FROM private_table; COMMIT;";

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,3 +1,5 @@
'use strict';
/** /**
* *
* Requires the database and tables setup in config/environments/test.js to exist * Requires the database and tables setup in config/environments/test.js to exist

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var assert = require('../support/assert'); var assert = require('../support/assert');

View File

@ -1,3 +1,5 @@
'use strict';
require('../helper'); require('../helper');
var server = require('../../app/server')(); var server = require('../../app/server')();

View File

@ -1,2 +1,4 @@
'use strict';
global.settings = require('../config/environments/test'); global.settings = require('../config/environments/test');
process.env.NODE_ENV = 'test'; process.env.NODE_ENV = 'test';

Some files were not shown because too many files have changed in this diff Show More