Merge "Strip roles in from_environ"

This commit is contained in:
Jenkins 2016-05-14 13:36:16 +00:00 committed by Gerrit Code Review
commit 6e61493b54
2 changed files with 7 additions and 1 deletions

View File

@ -173,7 +173,8 @@ class RequestContext(object):
if 'roles' not in kwargs:
roles = environ.get('HTTP_X_ROLES', environ.get('HTTP_X_ROLE'))
kwargs['roles'] = roles.split(',') if roles else []
roles = [r.strip() for r in roles.split(',')] if roles else []
kwargs['roles'] = roles
return cls(**kwargs)

View File

@ -209,6 +209,11 @@ class ContextTest(test_base.BaseTestCase):
tenant=override)
self.assertEqual(ctx.tenant, override)
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)
self.assertEqual(['abc', 'def', 'ghi'], ctx.roles)
def test_from_function_and_args(self):
ctx = context.RequestContext(user="user1")
arg = []