]> git.openstreetmap.org Git - nominatim.git/commitdiff
more strict parameter checking for reverse
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 17 Mar 2015 20:05:54 +0000 (21:05 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 17 Mar 2015 20:06:58 +0000 (21:06 +0100)
tests/features/api/reverse_simple.feature
tests/steps/api_setup.py
website/reverse.php

index 832b20110e6f067efbf2ad93b2fe90be54fe55a3..7d564dde77e0fb656d97204655c5a0c806ccfbf6 100644 (file)
@@ -50,3 +50,48 @@ Feature: Simple Reverse Tests
         Then the result is valid json
         When looking up jsonv2 coordinates 36.791966,127.171726
         Then the result is valid json
+
+    Scenario: Missing lon parameter
+        Given the request parameters
+          | lat
+          | 51.51
+        When sending an API call reverse
+        Then exactly 0 results are returned
+
+    Scenario: Missing lat parameter
+        Given the request parameters
+          | lon
+          | -79.39114
+        When sending an API call reverse
+        Then exactly 0 results are returned
+
+    Scenario: Missing osm_id parameter
+        Given the request parameters
+          | osm_type
+          | N
+        When sending an API call reverse
+        Then exactly 0 results are returned
+
+    Scenario: Missing osm_type parameter
+        Given the request parameters
+          | osm_id
+          | 3498564
+        When sending an API call reverse
+        Then exactly 0 results are returned
+
+    Scenario Outline: Bad format for lat or lon
+        Given the request parameters
+          | lat   | lon   |
+          | <lat> | <lon> |
+        When sending an API call reverse
+        Then exactly 0 results are returned
+
+    Examples:
+     | lat      | lon
+     | 48.9660  | 8,4482
+     | 48,9660  | 8.4482
+     | 48,9660  | 8,4482
+     | 48.966.0 | 8.4482
+     | 48.966   | 8.448.2
+     | Nan      | 8.448
+     | 48.966   | Nan
index ab08009654da3b768536d2efa8b6522533f08c4d..35443cdba6e1dabc3584697827974c379a7278c9 100644 (file)
@@ -122,3 +122,7 @@ def api_setup_details(step, obj):
     else:
         world.params['place_id']  = obj
     api_call('details')
+
+@step(u'sending an API call (\w+)')
+def api_general_call(step, call):
+    api_call(call)
index ee6a6100c8a4da0e4c6addd6058b0c951f66ecf3..93cb58771cd3ad68df10ab6ec50798e4102bd77d 100755 (executable)
                $oPlaceLookup->setOSMID($_GET['osm_type'], $_GET['osm_id']);
 
                $aPlace = $oPlaceLookup->lookup();
-
-               //if (!$iPlaceID) $sError = 'OSM ID Not Found';
        }
-       else
+       else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
        {
                $oReverseGeocode = new ReverseGeocode($oDB);
                $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
 
                $aPlace = $oReverseGeocode->lookup();
        }
+       else
+       {
+               $aPlace = null;
+       }
 
        if (CONST_Debug) exit;