]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add the project name into CinderKeystoneContext.
authorVincent Hou <sbhou@cn.ibm.com>
Mon, 17 Jun 2013 08:42:43 +0000 (16:42 +0800)
committerVincent Hou <sbhou@cn.ibm.com>
Thu, 20 Jun 2013 05:47:48 +0000 (13:47 +0800)
Fixed Bug 1178576.

Change-Id: I35cbd40c6f4aba45aeb8722ae5e10db8349d4510

cinder/api/middleware/auth.py
cinder/context.py
cinder/tests/api/middleware/test_auth.py

index 17bda1f94fbf7bc439baacbe4e40272759d9502e..a953b490fb56921164fcd9e1b3c9ebf03964a198 100644 (file)
@@ -91,6 +91,7 @@ class CinderKeystoneContext(base_wsgi.Middleware):
             # This is for legacy compatibility
             project_id = req.headers['X_TENANT']
 
+        project_name = req.headers.get('X_TENANT_NAME')
         # Get the auth token
         auth_token = req.headers.get('X_AUTH_TOKEN',
                                      req.headers.get('X_STORAGE_TOKEN'))
@@ -101,6 +102,7 @@ class CinderKeystoneContext(base_wsgi.Middleware):
             remote_address = req.headers.get('X-Forwarded-For', remote_address)
         ctx = context.RequestContext(user_id,
                                      project_id,
+                                     project_name=project_name,
                                      roles=roles,
                                      auth_token=auth_token,
                                      remote_address=remote_address)
index 951496043edc4ca75e5bd2219cf1d155801ca2f8..4b50d63ddf4228c86d5d9726944effdfac287e94 100644 (file)
@@ -43,9 +43,9 @@ class RequestContext(object):
     """
 
     def __init__(self, user_id, project_id, is_admin=None, read_deleted="no",
-                 roles=None, remote_address=None, timestamp=None,
-                 request_id=None, auth_token=None, overwrite=True,
-                 quota_class=None, **kwargs):
+                 roles=None, project_name=None, remote_address=None,
+                 timestamp=None, request_id=None, auth_token=None,
+                 overwrite=True, quota_class=None, **kwargs):
         """
         :param read_deleted: 'no' indicates deleted records are hidden, 'yes'
             indicates deleted records are visible, 'only' indicates that
@@ -64,6 +64,7 @@ class RequestContext(object):
         self.user_id = user_id
         self.project_id = project_id
         self.roles = roles or []
+        self.project_name = project_name
         self.is_admin = is_admin
         if self.is_admin is None:
             self.is_admin = policy.check_is_admin(self.roles)
@@ -105,6 +106,7 @@ class RequestContext(object):
     def to_dict(self):
         return {'user_id': self.user_id,
                 'project_id': self.project_id,
+                'project_name': self.project_name,
                 'is_admin': self.is_admin,
                 'read_deleted': self.read_deleted,
                 'roles': self.roles,
index 4fca13fe62cba2357b555cff4a165e39c3c13a64..879ff99a57748b33aab36537dad4c8fc346cf4f8 100644 (file)
@@ -40,16 +40,16 @@ class TestCinderKeystoneContextMiddleware(test.TestCase):
         self.assertEqual(response.status, '401 Unauthorized')
 
     def test_user_only(self):
-        self.request.headers['X_USER_ID'] = 'testuserid'
+        self.request.headers['X_USER'] = 'testuser'
         response = self.request.get_response(self.middleware)
         self.assertEqual(response.status, '200 OK')
-        self.assertEqual(self.context.user_id, 'testuserid')
+        self.assertEqual(self.context.user_id, 'testuser')
 
     def test_user_id_only(self):
-        self.request.headers['X_USER'] = 'testuser'
+        self.request.headers['X_USER_ID'] = 'testuserid'
         response = self.request.get_response(self.middleware)
         self.assertEqual(response.status, '200 OK')
-        self.assertEqual(self.context.user_id, 'testuser')
+        self.assertEqual(self.context.user_id, 'testuserid')
 
     def test_user_id_trumps_user(self):
         self.request.headers['X_USER_ID'] = 'testuserid'
@@ -57,3 +57,11 @@ class TestCinderKeystoneContextMiddleware(test.TestCase):
         response = self.request.get_response(self.middleware)
         self.assertEqual(response.status, '200 OK')
         self.assertEqual(self.context.user_id, 'testuserid')
+
+    def test_tenant_id_name(self):
+        self.request.headers['X_USER_ID'] = 'testuserid'
+        self.request.headers['X_TENANT_NAME'] = 'testtenantname'
+        response = self.request.get_response(self.middleware)
+        self.assertEqual(response.status, '200 OK')
+        self.assertEqual(self.context.project_id, 'testtenantid')
+        self.assertEqual(self.context.project_name, 'testtenantname')