Fix context.elevated
The current version of elevated method sets for the original context the admin role too. This change fix this. Added unittest. Closes-bug: #1386932 Change-Id: Ife881112efa151e53bfa4b7af35643dcf2d1114f
This commit is contained in:
parent
1aaa85c8c4
commit
5469ee3d1d
@ -145,7 +145,7 @@ class ContextBase(common_context.RequestContext):
|
|||||||
context.is_admin = True
|
context.is_admin = True
|
||||||
|
|
||||||
if 'admin' not in [x.lower() for x in context.roles]:
|
if 'admin' not in [x.lower() for x in context.roles]:
|
||||||
context.roles.append('admin')
|
context.roles = context.roles + ["admin"]
|
||||||
|
|
||||||
if read_deleted is not None:
|
if read_deleted is not None:
|
||||||
context.read_deleted = read_deleted
|
context.read_deleted = read_deleted
|
||||||
|
@ -89,6 +89,16 @@ class RequestTestCase(base.BaseTestCase):
|
|||||||
def test_context_without_neutron_context(self):
|
def test_context_without_neutron_context(self):
|
||||||
self.assertTrue(self.req.context.is_admin)
|
self.assertTrue(self.req.context.is_admin)
|
||||||
|
|
||||||
|
def test_request_context_elevated(self):
|
||||||
|
user_context = context.Context(
|
||||||
|
'fake_user', 'fake_project', admin=False)
|
||||||
|
self.assertFalse(user_context.is_admin)
|
||||||
|
admin_context = user_context.elevated()
|
||||||
|
self.assertFalse(user_context.is_admin)
|
||||||
|
self.assertTrue(admin_context.is_admin)
|
||||||
|
self.assertNotIn('admin', user_context.roles)
|
||||||
|
self.assertIn('admin', admin_context.roles)
|
||||||
|
|
||||||
def test_best_match_language(self):
|
def test_best_match_language(self):
|
||||||
# Test that we are actually invoking language negotiation by webop
|
# Test that we are actually invoking language negotiation by webop
|
||||||
request = wsgi.Request.blank('/')
|
request = wsgi.Request.blank('/')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user