# 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'))
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)
"""
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
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)
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,
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'
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')