Browse Source

Merge pull request #968 from pelias/move-request-language-to-sanitizer

added stub request_language sanitizer that just allows lang param
pull/969/head
Stephen K Hess 7 years ago committed by GitHub
parent
commit
66403e619d
  1. 15
      sanitizer/_request_language.js
  2. 3
      sanitizer/autocomplete.js
  3. 3
      sanitizer/nearby.js
  4. 3
      sanitizer/place.js
  5. 3
      sanitizer/reverse.js
  6. 3
      sanitizer/search.js
  7. 3
      sanitizer/structured_geocoding.js
  8. 1
      test/unit/run.js
  9. 35
      test/unit/sanitizer/_request_language.js
  10. 11
      test/unit/sanitizer/autocomplete.js
  11. 11
      test/unit/sanitizer/nearby.js
  12. 11
      test/unit/sanitizer/place.js
  13. 11
      test/unit/sanitizer/reverse.js
  14. 11
      test/unit/sanitizer/search.js
  15. 11
      test/unit/sanitizer/structured_geocoding.js

15
sanitizer/_request_language.js

@ -0,0 +1,15 @@
// this sanitizer exists solely to allow `lang` as a request parameter
function _sanitize( raw, clean ){
// error & warning messages
return { errors: [], warnings: [] };
}
function _expected(){
return [{ 'name': 'lang' }];
}
// export function
module.exports = () => ({
sanitize: _sanitize,
expected: _expected
});

3
sanitizer/autocomplete.js

@ -17,7 +17,8 @@ module.exports.middleware = (_api_pelias_config) => {
location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters),
geo_autocomplete: require('../sanitizer/_geo_autocomplete')(), geo_autocomplete: require('../sanitizer/_geo_autocomplete')(),
boundary_country: require('../sanitizer/_boundary_country')(), boundary_country: require('../sanitizer/_boundary_country')(),
categories: require('../sanitizer/_categories')() categories: require('../sanitizer/_categories')(),
request_language: require('../sanitizer/_request_language')()
}; };
return ( req, res, next ) => { return ( req, res, next ) => {

3
sanitizer/nearby.js

@ -15,7 +15,8 @@ var sanitizers = {
private: require('../sanitizer/_flag_bool')('private', false), private: require('../sanitizer/_flag_bool')('private', false),
geo_reverse: require('../sanitizer/_geo_reverse')(), geo_reverse: require('../sanitizer/_geo_reverse')(),
boundary_country: require('../sanitizer/_boundary_country')(), boundary_country: require('../sanitizer/_boundary_country')(),
categories: require('../sanitizer/_categories')() categories: require('../sanitizer/_categories')(),
request_language: require('../sanitizer/_request_language')()
}; };
// middleware // middleware

3
sanitizer/place.js

@ -4,7 +4,8 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'),
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(),
debug: require('../sanitizer/_debug')(), debug: require('../sanitizer/_debug')(),
ids: require('../sanitizer/_ids')(), ids: require('../sanitizer/_ids')(),
private: require('../sanitizer/_flag_bool')('private', false) private: require('../sanitizer/_flag_bool')('private', false),
request_language: require('../sanitizer/_request_language')()
}; };
// middleware // middleware

3
sanitizer/reverse.js

@ -13,7 +13,8 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'),
size: require('../sanitizer/_size')(/* use defaults*/), size: require('../sanitizer/_size')(/* use defaults*/),
private: require('../sanitizer/_flag_bool')('private', false), private: require('../sanitizer/_flag_bool')('private', false),
geo_reverse: require('../sanitizer/_geo_reverse')(), geo_reverse: require('../sanitizer/_geo_reverse')(),
boundary_country: require('../sanitizer/_boundary_country')() boundary_country: require('../sanitizer/_boundary_country')(),
request_language: require('../sanitizer/_request_language')()
}; };
// middleware // middleware

3
sanitizer/search.js

@ -18,7 +18,8 @@ module.exports.middleware = (_api_pelias_config) => {
boundary_country: require('../sanitizer/_boundary_country')(), boundary_country: require('../sanitizer/_boundary_country')(),
categories: require('../sanitizer/_categories')(), categories: require('../sanitizer/_categories')(),
// this can go away once geonames has been abrogated // this can go away once geonames has been abrogated
geonames_warnings: require('../sanitizer/_geonames_warnings')() geonames_warnings: require('../sanitizer/_geonames_warnings')(),
request_language: require('../sanitizer/_request_language')()
}; };
return ( req, res, next ) => { return ( req, res, next ) => {

3
sanitizer/structured_geocoding.js

@ -19,7 +19,8 @@ module.exports.middleware = (_api_pelias_config) => {
location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters),
geo_search: require('../sanitizer/_geo_search')(), geo_search: require('../sanitizer/_geo_search')(),
boundary_country: require('../sanitizer/_boundary_country')(), boundary_country: require('../sanitizer/_boundary_country')(),
categories: require('../sanitizer/_categories')() categories: require('../sanitizer/_categories')(),
request_language: require('../sanitizer/_request_language')()
}; };
return ( req, res, next ) => { return ( req, res, next ) => {

1
test/unit/run.js

@ -76,6 +76,7 @@ var tests = [
require('./sanitizer/_layers'), require('./sanitizer/_layers'),
require('./sanitizer/_location_bias'), require('./sanitizer/_location_bias'),
require('./sanitizer/_city_name_standardizer'), require('./sanitizer/_city_name_standardizer'),
require('./sanitizer/_request_language'),
require('./sanitizer/_single_scalar_parameters'), require('./sanitizer/_single_scalar_parameters'),
require('./sanitizer/_size'), require('./sanitizer/_size'),
require('./sanitizer/_sources'), require('./sanitizer/_sources'),

35
test/unit/sanitizer/_request_language.js

@ -0,0 +1,35 @@
const sanitizer = require('../../../sanitizer/_request_language')();
module.exports.tests = {};
module.exports.tests.do_nothing = (test, common) => {
test('sanitize should return empty warnings/erros', t => {
const messages = sanitizer.sanitize();
t.deepEquals(messages.errors, [], 'no errors');
t.deepEquals(messages.warnings, [], 'no warnings');
t.end();
});
};
module.exports.tests.expected = (test, common) => {
test('expected should contain only \'lang\'', t => {
const expected = sanitizer.expected();
t.deepEquals(expected, [{'name': 'lang'}]);
t.end();
});
};
module.exports.all = (tape, common) => {
function test(name, testFunction) {
return tape(`SANITIZE _request_language: ${name}`, testFunction);
}
for( const testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

11
test/unit/sanitizer/autocomplete.js

@ -120,6 +120,14 @@ module.exports.tests.sanitizers = function(test, common) {
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
} }
}; };
},
'../sanitizer/_request_language': () => {
return {
sanitize: () => {
called_sanitizers.push('_request_language');
return { errors: [], warnings: [] };
}
};
} }
}); });
@ -136,7 +144,8 @@ module.exports.tests.sanitizers = function(test, common) {
'_location_bias', '_location_bias',
'_geo_autocomplete', '_geo_autocomplete',
'_boundary_country', '_boundary_country',
'_categories' '_categories',
'_request_language'
]; ];
const req = {}; const req = {};

11
test/unit/sanitizer/nearby.js

@ -109,6 +109,14 @@ module.exports.tests.sanitize = function(test, common) {
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
} }
}; };
},
'../sanitizer/_request_language': () => {
return {
sanitize: () => {
called_sanitizers.push('_request_language');
return { errors: [], warnings: [] };
}
};
} }
}); });
@ -124,7 +132,8 @@ module.exports.tests.sanitize = function(test, common) {
'_flag_bool', '_flag_bool',
'_geo_reverse', '_geo_reverse',
'_boundary_country', '_boundary_country',
'_categories' '_categories',
'_request_language'
]; ];
const req = {}; const req = {};

11
test/unit/sanitizer/place.js

@ -45,6 +45,14 @@ module.exports.tests.sanitize = function(test, common) {
} else { } else {
throw new Error('incorrect parameters passed to _flag_bool'); throw new Error('incorrect parameters passed to _flag_bool');
} }
},
'../sanitizer/_request_language': () => {
return {
sanitize: () => {
called_sanitizers.push('_request_language');
return { errors: [], warnings: [] };
}
};
} }
}); });
@ -52,7 +60,8 @@ module.exports.tests.sanitize = function(test, common) {
'_single_scalar_parameters', '_single_scalar_parameters',
'_debug', '_debug',
'_ids', '_ids',
'_flag_bool' '_flag_bool',
'_request_language'
]; ];
const req = {}; const req = {};

11
test/unit/sanitizer/reverse.js

@ -101,6 +101,14 @@ module.exports.tests.sanitize = function(test, common) {
return { errors: [], warnings: [] }; return { errors: [], warnings: [] };
} }
}; };
},
'../sanitizer/_request_language': () => {
return {
sanitize: () => {
called_sanitizers.push('_request_language');
return { errors: [], warnings: [] };
}
};
} }
}); });
@ -115,7 +123,8 @@ module.exports.tests.sanitize = function(test, common) {
'_size', '_size',
'_flag_bool', '_flag_bool',
'_geo_reverse', '_geo_reverse',
'_boundary_country' '_boundary_country',
'_request_language'
]; ];
const req = {}; const req = {};

11
test/unit/sanitizer/search.js

@ -133,6 +133,14 @@ module.exports.tests.sanitize = (test, common) => {
} }
} }
}; };
},
'../sanitizer/_request_language': () => {
return {
sanitize: () => {
called_sanitizers.push('_request_language');
return { errors: [], warnings: [] };
}
};
} }
}); });
@ -151,7 +159,8 @@ module.exports.tests.sanitize = (test, common) => {
'_geo_search', '_geo_search',
'_boundary_country', '_boundary_country',
'_categories', '_categories',
'_geonames_warnings' '_geonames_warnings',
'_request_language'
]; ];
const req = {}; const req = {};

11
test/unit/sanitizer/structured_geocoding.js

@ -137,6 +137,14 @@ module.exports.tests.sanitize = function(test, common) {
} }
} }
}; };
},
'../sanitizer/_request_language': () => {
return {
sanitize: () => {
called_sanitizers.push('_request_language');
return { errors: [], warnings: [] };
}
};
} }
}); });
@ -155,7 +163,8 @@ module.exports.tests.sanitize = function(test, common) {
'_location_bias', '_location_bias',
'_geo_search', '_geo_search',
'_boundary_country', '_boundary_country',
'_categories' '_categories',
'_request_language'
]; ];
var req = {}; var req = {};

Loading…
Cancel
Save