Merge "Strip roles in from_environ"
This commit is contained in:
commit
6e61493b54
|
@ -173,7 +173,8 @@ class RequestContext(object):
|
||||||
|
|
||||||
if 'roles' not in kwargs:
|
if 'roles' not in kwargs:
|
||||||
roles = environ.get('HTTP_X_ROLES', environ.get('HTTP_X_ROLE'))
|
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)
|
return cls(**kwargs)
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,11 @@ class ContextTest(test_base.BaseTestCase):
|
||||||
tenant=override)
|
tenant=override)
|
||||||
self.assertEqual(ctx.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):
|
def test_from_function_and_args(self):
|
||||||
ctx = context.RequestContext(user="user1")
|
ctx = context.RequestContext(user="user1")
|
||||||
arg = []
|
arg = []
|
||||||
|
|
Loading…
Reference in New Issue