Enforce file size limits and user role checks on server#1678
Conversation
… swap missed res sends with success/failure function
…nto test-user-routes
… it is more clear where the file size estimate is shared
… checks into try-catch block for better security
…ramsTest Co-authored-by: Nespina24 <nathane3504@gmail.com>
… EXPORT user in readingsParamsTest
…stimate exceeds limit branch
huss
left a comment
There was a problem hiding this comment.
@Nespina24 & @stockingstocker Testing found this works as desired. I have made a few comments to consider. In addition, I am noting these items to see if you have thoughts or want to address (if not then an issue will be created):
- If the readings route you worked on returns an error then the client hangs up for a while waiting and does not give any message. I did not check but it may have existed before. I saw it since I modified your file size check to force it to fail.
- src/client/app/components/admin/PreferencesComponent.tsx has an issue that is stopping the admin from saving the default file size limits for export. It is because it sends a string and not a number when updated. The changes to route param checks now detects this. On line 42 I added the Number() as shown here:
setLocalAdminPref({ ...localAdminPref, [key]: Number(value) });This seems to have fixed it. There are also other Number casts that can probably go away given this change but I did not check that.
Please let me know if anything is not clear or you have thought/questions.
I don't think I've been able to reproduce this. Could you elaborate on how you modified the file size check to force it to fail? I did think that maybe its a scenario where the client accepts the request but the server rejects which causes lineReadings = await response.unwrap() to throw an error so I added a try-catch with corresponding error notification around it, does that fix the issue? I didn't manage to find a good error message in |
|
I'm just noting I pushed a commit to clarify two comments since that was easy. Let me know if you have any thoughts. |
I wanted to know if you want to do this as part of this PR or if it should be an issue (by you or me) for someone else. Okay either way. |
I went into the raw reading route (currently line 118) and changed it to
Yes, it now works by putting up an error msg rather than taking a while and showing nothing. |
There was a problem hiding this comment.
@Nespina24 and @stockingstocker Thank you for the updates. Overall, they worked well. I have made a little over a half dozen comments to consider where about half are new and half are about previous items. I think all resolved items are done. To try to help me keep items needing my attention as future changes are made, I'm asking you not resolve any comments. You are welcome (encouraged) to put a thumbs up if you think you addressed it or put in a reply. Thanks. Please let me know if anything is not clear or you have thoughts/questions.
…eferences can be saved
With the Number cast on line 42, I was unable to change the default minimum and maximum reading date checks on the admin settings page. I believe this is because |
Thanks for figuring that out. I looked at the code and tried it and it works well for me too. |
|
Noting that all comments before now are resolved and the code seems to work fine. Awaiting GitHub CI for final validation. |
huss
left a comment
There was a problem hiding this comment.
@Nespina24 and @stockingstocker Thank you for the updates. Review and testing found everything is good. Congratulations on an accepted contribution to OED.
Description
The export graph meter data route in the client (
src/client/app/redux/thunks/exportThunk.ts) enforces a file size limit that prevents downloads of meter data if the estimated file size is greater than the set limit and the user’s role is not EXPORT or ADMIN. This change adds the same file size and user role checks to the server route (src/server/routes/readings.js). Added unit tests tosrc/server/test/routes/readingsParamsTest.js.Fixes #1675
Authors: @Nespina24 and @stockingstocker
@huss added: This also fixed an issue with the parameter checking of the meter_id in this route and used the standard return functions.
Type of change
Checklist
Limitations
No limitations.