diff options
| author | Dan Prince <dan.prince@rackspace.com> | 2011-08-30 19:27:30 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-08-30 19:27:30 +0000 |
| commit | 056832ea04728d387ebbb5d9b2abfe4838b9431d (patch) | |
| tree | 80e13bd6f7e6026c32cc7784f4a62f4209105122 | |
| parent | 2a2aa10316abe9135541198bddd4c189976eb2fd (diff) | |
| parent | ebd47b7cb397f33c1e7c9f32dd5b77f7fd5d6642 (diff) | |
| download | nova-056832ea04728d387ebbb5d9b2abfe4838b9431d.tar.gz nova-056832ea04728d387ebbb5d9b2abfe4838b9431d.tar.xz nova-056832ea04728d387ebbb5d9b2abfe4838b9431d.zip | |
Update RequestContext so that it correctly sets self.is_admin from the roles array. Additionally add a bit of code to ignore case as well.
Resolves issues when accessing admin API's w/ Keystone.
| -rw-r--r-- | nova/context.py | 2 | ||||
| -rw-r--r-- | nova/tests/test_context.py | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/nova/context.py b/nova/context.py index b917a1d81..5c22641a0 100644 --- a/nova/context.py +++ b/nova/context.py @@ -38,7 +38,7 @@ class RequestContext(object): self.roles = roles or [] self.is_admin = is_admin if self.is_admin is None: - self.admin = 'admin' in self.roles + self.is_admin = 'admin' in [x.lower() for x in self.roles] self.read_deleted = read_deleted self.remote_address = remote_address if not timestamp: diff --git a/nova/tests/test_context.py b/nova/tests/test_context.py new file mode 100644 index 000000000..b2507fa59 --- /dev/null +++ b/nova/tests/test_context.py @@ -0,0 +1,33 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from nova import context +from nova import test + + +class ContextTestCase(test.TestCase): + + def test_request_context_sets_is_admin(self): + ctxt = context.RequestContext('111', + '222', + roles=['admin', 'weasel']) + self.assertEquals(ctxt.is_admin, True) + + def test_request_context_sets_is_admin_upcase(self): + ctxt = context.RequestContext('111', + '222', + roles=['Admin', 'weasel']) + self.assertEquals(ctxt.is_admin, True) |
