Merge pull request #36 from PeteBa/fix-options-hardening

Harden against malformed api request
This commit is contained in:
Samer Albahra
2019-05-19 09:59:55 -05:00
committed by GitHub
2 changed files with 4 additions and 3 deletions

View File

@@ -125,7 +125,7 @@ You should see "OpenSprinkler Weather Service" in response.
You can use the following request to see the watering level that the Weather Service calculates. Note: to be consistent, change the values of h, t and r to the % weightings and bh (as a %), bt (in F), bp (in inches) to the offsets from the Zimmerman config page in App. You can use the following request to see the watering level that the Weather Service calculates. Note: to be consistent, change the values of h, t and r to the % weightings and bh (as a %), bt (in F), bp (in inches) to the offsets from the Zimmerman config page in App.
``` ```
http://<Weather Service IP>:3000/weather1.py?loc=50,1&wto="\"h\":100,\"t\":100,\"r\":100,\"bh\":70,\"bt\":59,\"br\":0" http://<Weather Service IP>:3000/weather1.py?loc=50,1&wto="h":100,"t":100,"r":100,"bh":70,"bt":59,"br":0
``` ```
This will return a response similar to below with ```scale``` value equating to the watering level and ```rawData``` reflecting the temp (F), humidity (%) and daily rainfall (inches) used in the zimmerman calc. This will return a response similar to below with ```scale``` value equating to the watering level and ```rawData``` reflecting the temp (F), humidity (%) and daily rainfall (inches) used in the zimmerman calc.

View File

@@ -242,8 +242,9 @@ export const getWateringData = async function( req: express.Request, res: expres
adjustmentOptions = JSON.parse( "{" + adjustmentOptionsString + "}" ); adjustmentOptions = JSON.parse( "{" + adjustmentOptionsString + "}" );
} catch ( err ) { } catch ( err ) {
// If the JSON is not valid, do not incorporate weather adjustment options // If the JSON is not valid then abort the claculation
adjustmentOptions = undefined; res.send(`Error: Unable to parse options (${err})`);
return;
} }
// Attempt to resolve provided location to GPS coordinates. // Attempt to resolve provided location to GPS coordinates.