Merge "Pecan: Fix subresource policy check"

This commit is contained in:
Jenkins 2017-01-07 00:40:19 +00:00 committed by Gerrit Code Review
commit ee3149d928
2 changed files with 24 additions and 3 deletions

View File

@ -161,11 +161,16 @@ class PolicyHook(hooks.PecanHook):
return
if state.request.method not in pecan_constants.ACTION_MAP:
return
action = '%s_%s' % (pecan_constants.ACTION_MAP[state.request.method],
resource)
if not data or (resource not in data and collection not in data):
return
is_single = resource in data
action_type = pecan_constants.ACTION_MAP[state.request.method]
if action_type == 'get' and is_single:
action = controller.plugin_handlers[controller.SHOW]
elif action_type == 'get':
action = controller.plugin_handlers[controller.LIST]
else:
action = controller.plugin_handlers[action_type]
key = resource if is_single else collection
to_process = [data[resource]] if is_single else data[collection]
# in the single case, we enforce which raises on violation

View File

@ -959,6 +959,7 @@ class TestParentSubresourceController(test_functional.PecanFunctionalTest):
policy._ENFORCER.set_rules(
oslo_policy.Rules.from_dict(
{'get_fake_duplicate': '',
'get_fake_duplicates': '',
'get_meh_meh_fake_duplicates': ''}),
overwrite=False)
self.addCleanup(policy.reset)
@ -982,7 +983,22 @@ class TestParentSubresourceController(test_functional.PecanFunctionalTest):
def test_get_parent_resource_and_duplicate_subresources(self):
url = '/v2.0/{0}/something/{1}'.format(self.collection,
self.fake_collection)
self.fake_collection)
resp = self.app.get(url)
self.assertEqual(200, resp.status_int)
self.assertEqual({'fake_duplicates': [{'fake': 'something'}]},
resp.json)
def test_get_child_resource_policy_check(self):
policy.reset()
policy.init()
policy._ENFORCER.set_rules(
oslo_policy.Rules.from_dict(
{'get_meh_meh_fake_duplicates': ''}
)
)
url = '/v2.0/{0}/something/{1}'.format(self.collection,
self.fake_collection)
resp = self.app.get(url)
self.assertEqual(200, resp.status_int)
self.assertEqual({'fake_duplicates': [{'fake': 'something'}]},