Browse Source

Merge pull request #1064 from pelias/master

Merge master into staging
pull/1066/head
Julian Simioni 7 years ago committed by GitHub
parent
commit
f95881402e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      middleware/interpolate.js
  2. 10
      package.json
  3. 12
      sanitizer/_geo_common.js
  4. 7
      test/unit/middleware/interpolate.js
  5. 19
      test/unit/sanitizer/_geo_common.js

2
middleware/interpolate.js

@ -57,6 +57,8 @@ function setup(service, should_execute) {
// perform interpolations asynchronously for all relevant hits // perform interpolations asynchronously for all relevant hits
const start = (new Date()).getTime(); const start = (new Date()).getTime();
logger.info(`[interpolation] [street_results] count=${street_results.length}`);
// call the interpolation service asynchronously on every street result // call the interpolation service asynchronously on every street result
async.map(street_results, error_intercepting_service(service, req), (err, interpolation_results) => { async.map(street_results, error_intercepting_service(service, req), (err, interpolation_results) => {

10
package.json

@ -7,7 +7,7 @@
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"audit": "npm shrinkwrap; node node_modules/nsp/bin/nspCLI.js audit-shrinkwrap; rm npm-shrinkwrap.json;", "audit": "npm shrinkwrap; node node_modules/nsp/bin/nsp check; rm npm-shrinkwrap.json;",
"ciao": "node node_modules/ciao/bin/ciao -c test/ciao.json test/ciao", "ciao": "node node_modules/ciao/bin/ciao -c test/ciao.json test/ciao",
"coverage": "node_modules/.bin/istanbul cover test/unit/run.js", "coverage": "node_modules/.bin/istanbul cover test/unit/run.js",
"docs": "./bin/generate-docs", "docs": "./bin/generate-docs",
@ -58,10 +58,10 @@
"pelias-config": "2.13.0", "pelias-config": "2.13.0",
"pelias-labels": "1.7.0", "pelias-labels": "1.7.0",
"pelias-logger": "0.3.0", "pelias-logger": "0.3.0",
"pelias-microservice-wrapper": "1.2.1", "pelias-microservice-wrapper": "1.3.0",
"pelias-model": "5.2.0", "pelias-model": "5.2.0",
"pelias-query": "9.1.0", "pelias-query": "9.1.1",
"pelias-sorting": "1.0.1", "pelias-sorting": "1.1.0",
"pelias-text-analyzer": "1.10.2", "pelias-text-analyzer": "1.10.2",
"predicates": "^2.0.0", "predicates": "^2.0.0",
"retry": "^0.10.1", "retry": "^0.10.1",
@ -74,7 +74,7 @@
"istanbul": "^0.4.2", "istanbul": "^0.4.2",
"jshint": "^2.5.6", "jshint": "^2.5.6",
"npm-check": "git://github.com/orangejulius/npm-check.git#disable-update-check", "npm-check": "git://github.com/orangejulius/npm-check.git#disable-update-check",
"nsp": "^2.2.0", "nsp": "^3.0.0",
"pelias-mock-logger": "1.2.0", "pelias-mock-logger": "1.2.0",
"precommit-hook": "^3.0.0", "precommit-hook": "^3.0.0",
"proxyquire": "^1.7.10", "proxyquire": "^1.7.10",

12
sanitizer/_geo_common.js

@ -39,6 +39,18 @@ function sanitize_rect( key_prefix, clean, raw, bbox_is_required ) {
properties.forEach(function(prop) { properties.forEach(function(prop) {
sanitize_coord(prop, clean, raw, true); sanitize_coord(prop, clean, raw, true);
}); });
var min_lat = parseFloat( raw[key_prefix + '.' + 'min_lat'] );
var max_lat = parseFloat( raw[key_prefix + '.' + 'max_lat'] );
if (min_lat > max_lat) {
throw new Error( util.format( 'min_lat is larger than max_lat in \'%s\'', key_prefix ) );
}
var min_lon = parseFloat( raw[key_prefix + '.' + 'min_lon'] );
var max_lon = parseFloat( raw[key_prefix + '.' + 'max_lon'] );
if (min_lon > max_lon) {
throw new Error( util.format( 'min_lon is larger than max_lon in \'%s\'', key_prefix ) );
}
} }
/** /**

7
test/unit/middleware/interpolate.js

@ -59,6 +59,7 @@ module.exports.tests.success_conditions = (test, common) => {
controller(req, undefined, () => { controller(req, undefined, () => {
t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages');
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/));
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=0/));
t.end(); t.end();
}); });
@ -87,6 +88,7 @@ module.exports.tests.success_conditions = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages');
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/));
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=0/));
t.deepEquals(res, {}); t.deepEquals(res, {});
@ -201,6 +203,7 @@ module.exports.tests.success_conditions = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages');
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/), 'timing should be info-logged'); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/), 'timing should be info-logged');
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=3/), 'street count should be info-logged');
// test debug messages very vaguely to avoid brittle tests // test debug messages very vaguely to avoid brittle tests
t.ok(logger.isDebugMessage(/^\[interpolation\] \[hit\] this is req.clean.parsed_text \{.+?\}$/), t.ok(logger.isDebugMessage(/^\[interpolation\] \[hit\] this is req.clean.parsed_text \{.+?\}$/),
@ -375,6 +378,7 @@ module.exports.tests.success_conditions = (test, common) => {
'[middleware:interpolation] id 3 produced an error object' '[middleware:interpolation] id 3 produced an error object'
]); ]);
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/), 'timing should be info-logged'); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/), 'timing should be info-logged');
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=4/), 'street count should be info-logged');
// test debug messages very vaguely to avoid brittle tests // test debug messages very vaguely to avoid brittle tests
t.ok(logger.isDebugMessage(/^\[interpolation\] \[hit\] this is req.clean.parsed_text \{.+?\}$/), t.ok(logger.isDebugMessage(/^\[interpolation\] \[hit\] this is req.clean.parsed_text \{.+?\}$/),
@ -491,6 +495,7 @@ module.exports.tests.success_conditions = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages');
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/));
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=1/), 'street count should be info-logged');
t.deepEquals(res, { t.deepEquals(res, {
data: [ data: [
@ -579,6 +584,7 @@ module.exports.tests.success_conditions = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages');
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/));
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=2/), 'street count should be info-logged');
// test debug messages very vaguely to avoid brittle tests // test debug messages very vaguely to avoid brittle tests
t.ok(logger.isDebugMessage('[interpolation] [miss] this is req.clean.parsed_text')); t.ok(logger.isDebugMessage('[interpolation] [miss] this is req.clean.parsed_text'));
@ -679,6 +685,7 @@ module.exports.tests.success_conditions = (test, common) => {
controller(req, res, () => { controller(req, res, () => {
t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages');
t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/));
t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=2/), 'street count should be info-logged');
// test debug messages very vaguely to avoid brittle tests // test debug messages very vaguely to avoid brittle tests
t.ok(logger.isDebugMessage('[interpolation] [miss] this is req.clean.parsed_text')); t.ok(logger.isDebugMessage('[interpolation] [miss] this is req.clean.parsed_text'));

19
test/unit/sanitizer/_geo_common.js

@ -216,8 +216,8 @@ module.exports.tests.rect = function(test, common) {
test('valid rect quad', function (t) { test('valid rect quad', function (t) {
var clean = {}; var clean = {};
var params = { var params = {
'boundary.rect.min_lat': -40.659, 'boundary.rect.min_lat': -41.614,
'boundary.rect.max_lat': -41.614, 'boundary.rect.max_lat': -40.659,
'boundary.rect.min_lon': 174.612, 'boundary.rect.min_lon': 174.612,
'boundary.rect.max_lon': 176.333 'boundary.rect.max_lon': 176.333
}; };
@ -283,6 +283,21 @@ module.exports.tests.rect = function(test, common) {
t.end(); t.end();
}); });
test('invalid rect - max/min switched', function (t) {
var clean = {};
var params = {
'boundary.rect.max_lat': 52.2387,
'boundary.rect.max_lon': 14.1367,
'boundary.rect.min_lat': 52.7945,
'boundary.rect.min_lon': 12.6398
};
var mandatory = false;
t.throws( function() {
sanitize.sanitize_rect( 'boundary.rect', clean, params, mandatory );
});
t.end();
});
}; };
module.exports.tests.circle = function(test, common) { module.exports.tests.circle = function(test, common) {

Loading…
Cancel
Save