-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix for unhandled undefined config #4334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When an invalid application id is passed either for reset/change password or email verification, config.get returns undefined. This causes internal server.
Codecov Report
@@ Coverage Diff @@
## master #4334 +/- ##
==========================================
+ Coverage 92.52% 92.54% +0.01%
==========================================
Files 118 118
Lines 8258 8273 +15
==========================================
+ Hits 7641 7656 +15
Misses 617 617
Continue to review full report at Codecov.
|
Nice catch. The standard 'Not found.' & '404' response seems ok, @flovilmart think we're good using the existing |
We should probably throw if Config.get(appId) don’t return anything no? |
Something like this? throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'appId not found'); or maybe |
What do we usually throw when making a request with an invalid appId? Unauthorized I guess .) |
No specific cases come to mind actually, just
Simple and to the point. Both of those other refs just throw errors, the latter uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bryandel if you can split up the checking on the config and throw instead that would be fantastic 👍 .
src/Routers/PublicAPIRouter.js
Outdated
@@ -15,7 +15,7 @@ export class PublicAPIRouter extends PromiseRouter { | |||
const appId = req.params.appId; | |||
const config = Config.get(appId); | |||
|
|||
if (!config.publicServerURL) { | |||
if (!config || !config.publicServerURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be willing to update this to handle !config
separately? We would like to throw an exception rather than return a standard 404. Something like this should do
if (!config) {
throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'appId does not exist in config.');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following in middleware.js if appId can't be found, this should be
if (!config) {
const error = new Error();
error.status = 403;
error.message = "unauthorized";
throw error;
}
The error will be handled by the PromiseRouter and transformed in to the proper response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, didn't see that initially. @bryandel take flovilmart's suggestion for the proper error to report.
src/Routers/PublicAPIRouter.js
Outdated
@@ -40,7 +40,7 @@ export class PublicAPIRouter extends PromiseRouter { | |||
const appId = req.params.appId; | |||
const config = Config.get(appId); | |||
|
|||
if (!config.publicServerURL) { | |||
if (!config || !config.publicServerURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/Routers/PublicAPIRouter.js
Outdated
@@ -66,7 +66,7 @@ export class PublicAPIRouter extends PromiseRouter { | |||
changePassword(req) { | |||
return new Promise((resolve, reject) => { | |||
const config = Config.get(req.query.id); | |||
if (!config.publicServerURL) { | |||
if (!config || !config.publicServerURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
src/Routers/PublicAPIRouter.js
Outdated
@@ -89,7 +89,7 @@ export class PublicAPIRouter extends PromiseRouter { | |||
|
|||
const config = req.config; | |||
|
|||
if (!config.publicServerURL) { | |||
if (!config || !config.publicServerURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
src/Routers/PublicAPIRouter.js
Outdated
@@ -114,7 +114,7 @@ export class PublicAPIRouter extends PromiseRouter { | |||
|
|||
const config = req.config; | |||
|
|||
if (!config.publicServerURL) { | |||
if (!config || !config.publicServerURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
…p id Also, added a missing semicolon
Thank you for the suggestions. I have changed the implementation and also added tests for the code coverage. But it seems in the last build a different test has failed
|
@bryandel thanks again for the PR! |
…munity#4334) * Fix for unhandled undefined config When an invalid application id is passed either for reset/change password or email verification, config.get returns undefined. This causes internal server. * Throwing a 403 exception instead of returning a 404 for an invalid app id Also, added a missing semicolon * Fix indent issues * Fix invalid colon to semicolon * Fix space and indent issues * Tests for the fix for unhandled undefined config
When an invalid application id is passed either for reset/change password or email verification, config.get returns undefined. This causes internal server.