diff --git a/middleware/interpolate.js b/middleware/interpolate.js index a7d3e1d8..10c3f7e8 100644 --- a/middleware/interpolate.js +++ b/middleware/interpolate.js @@ -57,6 +57,8 @@ function setup(service, should_execute) { // perform interpolations asynchronously for all relevant hits const start = (new Date()).getTime(); + logger.info(`[interpolation] [street_results] count=${street_results.length}`); + // call the interpolation service asynchronously on every street result async.map(street_results, error_intercepting_service(service, req), (err, interpolation_results) => { diff --git a/package.json b/package.json index 147c87e4..80243ad1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "main": "index.js", "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", "coverage": "node_modules/.bin/istanbul cover test/unit/run.js", "docs": "./bin/generate-docs", @@ -58,10 +58,10 @@ "pelias-config": "2.13.0", "pelias-labels": "1.7.0", "pelias-logger": "0.3.0", - "pelias-microservice-wrapper": "1.2.1", + "pelias-microservice-wrapper": "1.3.0", "pelias-model": "5.2.0", - "pelias-query": "9.1.0", - "pelias-sorting": "1.0.1", + "pelias-query": "9.1.1", + "pelias-sorting": "1.1.0", "pelias-text-analyzer": "1.10.2", "predicates": "^2.0.0", "retry": "^0.10.1", @@ -74,7 +74,7 @@ "istanbul": "^0.4.2", "jshint": "^2.5.6", "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", "precommit-hook": "^3.0.0", "proxyquire": "^1.7.10", diff --git a/sanitizer/_geo_common.js b/sanitizer/_geo_common.js index d7620b08..a3b15865 100644 --- a/sanitizer/_geo_common.js +++ b/sanitizer/_geo_common.js @@ -39,6 +39,18 @@ function sanitize_rect( key_prefix, clean, raw, bbox_is_required ) { properties.forEach(function(prop) { 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 ) ); + } } /** diff --git a/test/unit/middleware/interpolate.js b/test/unit/middleware/interpolate.js index f020628d..6dbf1ae6 100644 --- a/test/unit/middleware/interpolate.js +++ b/test/unit/middleware/interpolate.js @@ -59,6 +59,7 @@ module.exports.tests.success_conditions = (test, common) => { controller(req, undefined, () => { t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); + t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=0/)); t.end(); }); @@ -87,6 +88,7 @@ module.exports.tests.success_conditions = (test, common) => { controller(req, res, () => { t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); t.ok(logger.isInfoMessage(/\[interpolation\] \[took\] \d+ ms/)); + t.ok(logger.isInfoMessage(/\[interpolation\] \[street_results\] count=0/)); t.deepEquals(res, {}); @@ -201,6 +203,7 @@ module.exports.tests.success_conditions = (test, common) => { controller(req, res, () => { 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\] \[street_results\] count=3/), 'street count should be info-logged'); // test debug messages very vaguely to avoid brittle tests 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' ]); 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 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, () => { t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); 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, { data: [ @@ -579,6 +584,7 @@ module.exports.tests.success_conditions = (test, common) => { controller(req, res, () => { t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); 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 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, () => { t.notOk(logger.hasErrorMessages(), 'there shouldn\'t be any error messages'); 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 t.ok(logger.isDebugMessage('[interpolation] [miss] this is req.clean.parsed_text')); diff --git a/test/unit/sanitizer/_geo_common.js b/test/unit/sanitizer/_geo_common.js index bdb58078..09c008ba 100644 --- a/test/unit/sanitizer/_geo_common.js +++ b/test/unit/sanitizer/_geo_common.js @@ -216,8 +216,8 @@ module.exports.tests.rect = function(test, common) { test('valid rect quad', function (t) { var clean = {}; var params = { - 'boundary.rect.min_lat': -40.659, - 'boundary.rect.max_lat': -41.614, + 'boundary.rect.min_lat': -41.614, + 'boundary.rect.max_lat': -40.659, 'boundary.rect.min_lon': 174.612, 'boundary.rect.max_lon': 176.333 }; @@ -283,6 +283,21 @@ module.exports.tests.rect = function(test, common) { 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) {