diff --git a/neutron/pecan_wsgi/hooks/policy_enforcement.py b/neutron/pecan_wsgi/hooks/policy_enforcement.py index df1f741254c..c2499a7a007 100644 --- a/neutron/pecan_wsgi/hooks/policy_enforcement.py +++ b/neutron/pecan_wsgi/hooks/policy_enforcement.py @@ -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': diff --git a/neutron/tests/functional/pecan_wsgi/test_hooks.py b/neutron/tests/functional/pecan_wsgi/test_hooks.py index 24def5e9ccc..0455ecb15fd 100644 --- a/neutron/tests/functional/pecan_wsgi/test_hooks.py +++ b/neutron/tests/functional/pecan_wsgi/test_hooks.py @@ -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):