Fixes bug 846347 - Allowed implementation overriding in configman middle... #1106

Merged
merged 1 commit into from Mar 20, 2013

Projects

None yet

2 participants

Member
adngdb commented Mar 5, 2013

...ware app.

@peterbe What do you think?

@peterbe peterbe commented on an outdated diff Mar 5, 2013
socorro/middleware/middleware_app.py
+ impl_code = params['force_api_impl']
+
+ file_name, class_name = self.file_and_class.rsplit('.', 1)
+ implementations = dict(
+ self.context.implementations.implementation_list
+ )
+ base_module_path = implementations[impl_code]
+ try:
+ module = __import__(
+ '%s.%s' % (base_module_path, file_name),
+ globals(),
+ locals(),
+ [class_name]
+ )
+ except ImportError:
+ raise ImportError(
peterbe
peterbe Mar 5, 2013 Contributor

Is this really necessary? How would the traceback look like "naturally"?

In fact, perhaps we should do something like raise RuntimeError('%s.%s not importable' % (base_module_path, file_name)

@peterbe peterbe commented on an outdated diff Mar 5, 2013
socorro/middleware/middleware_app.py
@@ -305,16 +315,43 @@ def wrap(cls):
class ImplementationWrapper(JsonWebServiceBase):
def GET(self, *args, **kwargs):
+ # prepare parameters
+ params = kwargs
+ if len(args) > 0:
+ params.update(self.parse_url_path(args[-1]))
+ self._correct_signature_parameters(params)
+
+ # override implementation class if needed
+ if 'force_api_impl' in params:
peterbe
peterbe Mar 5, 2013 Contributor

Change this to _force_api_impl to indicate that it's something beyond the normal.

peterbe
peterbe Mar 5, 2013 Contributor

Also, change it to if params.get('_force_api_impl'): otherwise you'll allow people to enter /crash/uuid/xxxx/_force_api_impl//

Contributor
peterbe commented Mar 5, 2013

I love it! Well done!

However, we need to think about the except ImportError case.
Either we just let it be the first ImportError (assuming it's not too cryptic) or we need at least a unit test that causes an ImportError and with that, something like self.assertRaises(ImportError, self.get, server ...)

Member
adngdb commented Mar 8, 2013

@peterbe I changed the ImportError to a BadRequest, does that sound right to you? It's indeed a bad request as the user manually entered a URL that is not valid.

@peterbe peterbe merged commit 504ac2b into mozilla:master Mar 20, 2013

1 check passed

default Jenkins build 'socorro-github' #542 has succeeded
Details
@adngdb adngdb deleted the adngdb:846347-middleware-force-impl branch Mar 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment