Allow deprecated X-Tenant-Name in from_environ

Support the old and deprecated X-Tenant-Name header in the
from_environ method.

Change-Id: I0d1784ee96e38a5be256370a3e6dbf7cd1b21b05
This commit is contained in:
Jamie Lennox 2016-07-11 11:10:46 +10:00
parent 740b81784b
commit 5118040676
2 changed files with 12 additions and 1 deletions

View File

@ -46,7 +46,8 @@ _ENVIRON_HEADERS = {'auth_token': ['HTTP_X_AUTH_TOKEN',
'user_domain': ['HTTP_X_USER_DOMAIN_ID'],
'project_domain': ['HTTP_X_PROJECT_DOMAIN_ID'],
'user_name': ['HTTP_X_USER_NAME'],
'project_name': ['HTTP_X_PROJECT_NAME'],
'project_name': ['HTTP_X_PROJECT_NAME',
'HTTP_X_TENANT_NAME'],
'user_domain_name': ['HTTP_X_USER_DOMAIN_NAME'],
'project_domain_name': ['HTTP_X_PROJECT_DOMAIN_NAME'],
'request_id': ['openstack.request_id'],

View File

@ -214,6 +214,10 @@ class ContextTest(test_base.BaseTestCase):
ctx = context.RequestContext.from_environ(environ=environ)
self.assertEqual([value], ctx.roles)
environ = {'HTTP_X_TENANT_NAME': value}
ctx = context.RequestContext.from_environ(environ=environ)
self.assertEqual(value, ctx.project_name)
def test_from_environ_deprecated_precendence(self):
old = uuid.uuid4().hex
new = uuid.uuid4().hex
@ -239,6 +243,12 @@ class ContextTest(test_base.BaseTestCase):
tenant=override)
self.assertEqual(ctx.tenant, override)
environ = {'HTTP_X_TENANT_NAME': old,
'HTTP_X_PROJECT_NAME': new}
ctx = context.RequestContext.from_environ(environ=environ)
self.assertEqual(ctx.project_name, new)
def test_from_environ_strip_roles(self):
environ = {'HTTP_X_ROLES': ' abc\t,\ndef\n,ghi\n\n'}
ctx = context.RequestContext.from_environ(environ=environ)