Browse Source

Merge "Default role checker should be case-insensitive."

changes/55/794955/1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
2b1507faa3
2 changed files with 24 additions and 2 deletions
  1. +2
    -2
      openstack_dashboard/api/keystone.py
  2. +22
    -0
      openstack_dashboard/test/unit/api/test_keystone.py

+ 2
- 2
openstack_dashboard/api/keystone.py View File

@ -781,7 +781,7 @@ def get_default_role(request):
to request. Supports lookup by name or id.
"""
global DEFAULT_ROLE
default = settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE
default = settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE.lower()
if default and DEFAULT_ROLE is None:
try:
roles = keystoneclient(request, admin=True).roles.list()
@ -789,7 +789,7 @@ def get_default_role(request):
roles = []
exceptions.handle(request)
for role in roles:
if default in (role.id, role.name):
if default in (role.id.lower(), role.name.lower()):
DEFAULT_ROLE = role
break
return DEFAULT_ROLE


+ 22
- 0
openstack_dashboard/test/unit/api/test_keystone.py View File

@ -15,6 +15,7 @@
# 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 random import choice
from unittest import mock
@ -68,6 +69,27 @@ class RoleAPITests(test.APIMockTestCase):
role = api.keystone.get_default_role(self.request)
keystoneclient.roles.list.assert_called_once_with()
@mock.patch.object(api.keystone, 'keystoneclient')
@mock.patch.object(api.keystone, 'DEFAULT_ROLE', new=None)
def test_get_case_insensitive_default_role(self, mock_keystoneclient):
def convert_to_random_case(role_):
new_name = list()
for char in list(role_.name):
new_name.append(getattr(char, choice(["lower", "upper"]))())
role_.name = role_._info["name"] = "".join(new_name)
return role_
keystoneclient = mock_keystoneclient.return_value
keystoneclient.roles.list.return_value = list()
for role in self.roles:
role = convert_to_random_case(role)
keystoneclient.roles.list.return_value.append(role)
role = api.keystone.get_default_role(self.request)
self.assertEqual(self.role.name.lower(), role.name.lower())
# Verify that a second call doesn't hit the API again,
# so we use assert_called_once_with() here.
api.keystone.get_default_role(self.request)
keystoneclient.roles.list.assert_called_once_with()
class ServiceAPITests(test.APIMockTestCase):
@override_settings(OPENSTACK_ENDPOINT_TYPE='internalURL')


Loading…
Cancel
Save