Init policy in pecan after hook as well
policy.init() is called in the before hook, but this isn't
invoked on GET calls so if the first call a thread receives
is a GET call, we can end up with an uninitialized policy
enforcer and get a traceback.
This just calls policy.init() in the after hook as well.
Change-Id: I29ebc9a91b98a27e707d5b35ad1a24a26e8c8f44
Closes-Bug: #1671267
(cherry picked from commit 4c40016dfb
)
This commit is contained in:
parent
085afaa649
commit
816ccb35b4
|
@ -163,6 +163,7 @@ class PolicyHook(hooks.PecanHook):
|
|||
return
|
||||
if not data or (resource not in data and collection not in data):
|
||||
return
|
||||
policy.init()
|
||||
is_single = resource in data
|
||||
action_type = pecan_constants.ACTION_MAP[state.request.method]
|
||||
if action_type == 'get':
|
||||
|
|
|
@ -221,6 +221,17 @@ class TestPolicyEnforcementHook(test_functional.PecanFunctionalTest):
|
|||
json_response = jsonutils.loads(response.body)
|
||||
self.assertNotIn('restricted_attr', json_response['mehs'][0])
|
||||
|
||||
def test_after_inits_policy(self):
|
||||
self.mock_plugin.get_mehs.return_value = [{
|
||||
'id': 'xxx',
|
||||
'attr': 'meh',
|
||||
'restricted_attr': '',
|
||||
'tenant_id': 'tenid'}]
|
||||
policy.reset()
|
||||
response = self.app.get('/v2.0/mehs',
|
||||
headers={'X-Project-Id': 'tenid'})
|
||||
self.assertEqual(200, response.status_int)
|
||||
|
||||
|
||||
class TestMetricsNotifierHook(test_functional.PecanFunctionalTest):
|
||||
|
||||
|
|
Loading…
Reference in New Issue