]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix context.elevated
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Thu, 20 Nov 2014 16:13:52 +0000 (19:13 +0300)
committerYaguang Tang <yaguang.tang@canonical.com>
Tue, 25 Nov 2014 03:20:34 +0000 (11:20 +0800)
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
(cherry picked from commit 98fae47ad1b9b72e41d444ce6f96cf5f2a3b6f0c)

neutron/context.py
neutron/tests/unit/test_api_v2_resource.py

index f248e70250fe69d2f9a3725711f3ac7ef0eef2b0..1da9b774235f338daaeb71aca597b0fea7336f7f 100644 (file)
@@ -144,7 +144,7 @@ class ContextBase(common_context.RequestContext):
         context.is_admin = True
 
         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:
             context.read_deleted = read_deleted
index 91e24de711c77126fe700a332c45f6bcf61bb065..ae3dad5a7c79c30c0d9f61ba8e21541fdd0811ee 100644 (file)
@@ -94,6 +94,16 @@ class RequestTestCase(base.BaseTestCase):
     def test_context_without_neutron_context(self):
         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):
         # Test that we are actually invoking language negotiation by webop
         request = wsgi.Request.blank('/')