Reinitialize the policy engine where it is needed

Policy engine should be reinitialized in the testcases where
policy enforcement is needed so that the `policy.json` from
the code base is readable.

Previously, it's only reinitialized for V3 restful testcases,
but the V2 APIs such as create credential also need to read
policy file.

Bunches of testcases will fail if run testcases separately.
$ python -m unittest keystone.tests.unit.test_v2

...
Ran 122 tests in 18.954s
FAILED (errors=73, skipped=3)

V2 restful testcases could be pass and escaped detection just
because they are run with V3 restful testcases together, and
the `policy.json` is loaded from code base and won't loaded
any more.

Change-Id: I0cbc13f0902db66de0d673c64ec81a56861a2bc3
Closes-Bug: #1541218
This commit is contained in:
Dave Chen 2016-02-03 15:02:40 +08:00
parent 543707bbac
commit 52f507c319
2 changed files with 7 additions and 8 deletions

View File

@ -17,6 +17,7 @@ from six.moves import http_client
import webtest
from keystone.auth import controllers as auth_controllers
from keystone.policy.backends import rules
from keystone.tests import unit
from keystone.tests.unit import default_fixtures
from keystone.tests.unit.ksfixtures import database
@ -71,6 +72,12 @@ class RestfulTestCase(unit.TestCase):
self.admin_app = webtest.TestApp(
self.loadapp(app_conf, name='admin'))
self.addCleanup(delattr, self, 'admin_app')
# Initialize the policy engine and allow us to write to a temp
# file in each test to create the policies
rules.reset()
# drop the policy rules
self.addCleanup(rules.reset)
def request(self, app, path, body=None, headers=None, token=None,
expected_status=None, **kwargs):

View File

@ -28,7 +28,6 @@ from keystone.common import cache
from keystone.common.validation import validators
from keystone import exception
from keystone import middleware
from keystone.policy.backends import rules
from keystone.tests.common import auth as common_auth
from keystone.tests import unit
from keystone.tests.unit import rest
@ -281,13 +280,6 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase,
self.empty_context = {'environment': {}}
# Initialize the policy engine and allow us to write to a temp
# file in each test to create the policies
rules.reset()
# drop the policy rules
self.addCleanup(rules.reset)
def load_backends(self):
# ensure the cache region instance is setup
cache.configure_cache()