diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-05-14 13:36:16 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-05-14 13:36:16 +0000 |
commit | 6e61493b5477ffc49b6e437effa27c593c15e3b0 (patch) | |
tree | 59d9f19c1080be120fc15e34dfb6e4fd0a346ef7 /oslo_context | |
parent | 390ff18d26b4b230aa7ef37cea6d48bcb2e70f82 (diff) | |
parent | 0511e11287c6c554eac98fc725738baf6290c52e (diff) | |
download | oslo-context-6e61493b5477ffc49b6e437effa27c593c15e3b0.tar.gz |
Merge "Strip roles in from_environ"2.4.0
Diffstat (limited to 'oslo_context')
-rw-r--r-- | oslo_context/context.py | 3 | ||||
-rw-r--r-- | oslo_context/tests/test_context.py | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/oslo_context/context.py b/oslo_context/context.py index bfbedcb..d4902ad 100644 --- a/oslo_context/context.py +++ b/oslo_context/context.py @@ -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) diff --git a/oslo_context/tests/test_context.py b/oslo_context/tests/test_context.py index f2a095a..2165608 100644 --- a/oslo_context/tests/test_context.py +++ b/oslo_context/tests/test_context.py @@ -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 = [] |