Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame^] | 18 | from tempest.api.identity import base |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | from tempest import exceptions |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 21 | from tempest.test import attr |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 22 | |
| 23 | |
Attila Fazekas | 0d0c616 | 2013-02-24 09:14:23 +0100 | [diff] [blame] | 24 | class RolesTestJSON(base.BaseIdentityAdminTest): |
| 25 | _interface = 'json' |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 26 | |
Attila Fazekas | 0d0c616 | 2013-02-24 09:14:23 +0100 | [diff] [blame] | 27 | @classmethod |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 28 | def setUpClass(cls): |
Attila Fazekas | 0d0c616 | 2013-02-24 09:14:23 +0100 | [diff] [blame] | 29 | super(RolesTestJSON, cls).setUpClass() |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 30 | for _ in xrange(5): |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 31 | resp, role = cls.client.create_role(rand_name('role-')) |
| 32 | cls.data.roles.append(role) |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 33 | |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 34 | def _get_role_params(self): |
| 35 | self.data.setup_test_user() |
| 36 | self.data.setup_test_role() |
| 37 | user = self.get_user_by_name(self.data.test_user) |
| 38 | tenant = self.get_tenant_by_name(self.data.test_tenant) |
| 39 | role = self.get_role_by_name(self.data.test_role) |
| 40 | return (user, tenant, role) |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 41 | |
Attila Fazekas | 0d0c616 | 2013-02-24 09:14:23 +0100 | [diff] [blame] | 42 | def assert_role_in_role_list(self, role, roles): |
| 43 | found = False |
| 44 | for user_role in roles: |
| 45 | if user_role['id'] == role['id']: |
| 46 | found = True |
| 47 | self.assertTrue(found, "assigned role was not in list") |
| 48 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 49 | @attr(type='gate') |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 50 | def test_list_roles(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 51 | # Return a list of all roles |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 52 | resp, body = self.client.list_roles() |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 53 | found = [role for role in body if role in self.data.roles] |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 54 | self.assertTrue(any(found)) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 55 | self.assertEqual(len(found), len(self.data.roles)) |
| 56 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 57 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 58 | def test_list_roles_by_unauthorized_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 59 | # Non admin user should not be able to list roles |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 60 | self.assertRaises(exceptions.Unauthorized, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 61 | self.non_admin_client.list_roles) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 62 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 63 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 64 | def test_list_roles_request_without_token(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 65 | # Request to list roles without a valid token should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 66 | token = self.client.get_auth() |
| 67 | self.client.delete_token(token) |
| 68 | self.assertRaises(exceptions.Unauthorized, self.client.list_roles) |
| 69 | self.client.clear_auth() |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 70 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 71 | @attr(type='gate') |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 72 | def test_role_create_delete(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 73 | # Role should be created, verified, and deleted |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 74 | role_name = rand_name('role-test-') |
| 75 | resp, body = self.client.create_role(role_name) |
| 76 | self.assertTrue('status' in resp) |
| 77 | self.assertTrue(resp['status'].startswith('2')) |
| 78 | self.assertEqual(role_name, body['name']) |
| 79 | |
| 80 | resp, body = self.client.list_roles() |
| 81 | found = [role for role in body if role['name'] == role_name] |
| 82 | self.assertTrue(any(found)) |
| 83 | |
| 84 | resp, body = self.client.delete_role(found[0]['id']) |
| 85 | self.assertTrue('status' in resp) |
| 86 | self.assertTrue(resp['status'].startswith('2')) |
| 87 | |
| 88 | resp, body = self.client.list_roles() |
| 89 | found = [role for role in body if role['name'] == role_name] |
| 90 | self.assertFalse(any(found)) |
| 91 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 92 | @attr(type='gate') |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 93 | def test_role_create_blank_name(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 94 | # Should not be able to create a role with a blank name |
David Kranz | 28e35c5 | 2012-07-10 10:14:38 -0400 | [diff] [blame] | 95 | self.assertRaises(exceptions.BadRequest, self.client.create_role, '') |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 96 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 97 | @attr(type='gate') |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 98 | def test_role_create_duplicate(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 99 | # Role names should be unique |
chris fattarsi | 8ed39ac | 2012-04-30 14:11:27 -0700 | [diff] [blame] | 100 | role_name = rand_name('role-dup-') |
| 101 | resp, body = self.client.create_role(role_name) |
| 102 | role1_id = body.get('id') |
| 103 | self.assertTrue('status' in resp) |
| 104 | self.assertTrue(resp['status'].startswith('2')) |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 105 | self.addCleanup(self.client.delete_role, role1_id) |
| 106 | self.assertRaises(exceptions.Duplicate, self.client.create_role, |
| 107 | role_name) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 108 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 109 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 110 | def test_assign_user_role(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 111 | # Assign a role to a user on a tenant |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 112 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 113 | self.client.assign_user_role(tenant['id'], user['id'], role['id']) |
| 114 | resp, roles = self.client.list_user_roles(tenant['id'], user['id']) |
Adam Young | ddb8289 | 2013-02-15 13:10:35 -0500 | [diff] [blame] | 115 | self.assert_role_in_role_list(role, roles) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 116 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 117 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 118 | def test_assign_user_role_by_unauthorized_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 119 | # Non admin user should not be authorized to assign a role to user |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 120 | (user, tenant, role) = self._get_role_params() |
| 121 | self.assertRaises(exceptions.Unauthorized, |
| 122 | self.non_admin_client.assign_user_role, |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 123 | tenant['id'], user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 124 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 125 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 126 | def test_assign_user_role_request_without_token(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 127 | # Request to assign a role to a user without a valid token |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 128 | (user, tenant, role) = self._get_role_params() |
| 129 | token = self.client.get_auth() |
| 130 | self.client.delete_token(token) |
| 131 | self.assertRaises(exceptions.Unauthorized, |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 132 | self.client.assign_user_role, tenant['id'], |
| 133 | user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 134 | self.client.clear_auth() |
| 135 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 136 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 137 | def test_assign_user_role_for_non_existent_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 138 | # Attempt to assign a role to a non existent user should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 139 | (user, tenant, role) = self._get_role_params() |
| 140 | self.assertRaises(exceptions.NotFound, self.client.assign_user_role, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 141 | tenant['id'], 'junk-user-id-999', role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 142 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 143 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 144 | def test_assign_user_role_for_non_existent_role(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 145 | # Attempt to assign a non existent role to user should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 146 | (user, tenant, role) = self._get_role_params() |
| 147 | self.assertRaises(exceptions.NotFound, self.client.assign_user_role, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 148 | tenant['id'], user['id'], 'junk-role-id-12345') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 149 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 150 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 151 | def test_assign_user_role_for_non_existent_tenant(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 152 | # Attempt to assign a role on a non existent tenant should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 153 | (user, tenant, role) = self._get_role_params() |
| 154 | self.assertRaises(exceptions.NotFound, self.client.assign_user_role, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 155 | 'junk-tenant-1234', user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 156 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 157 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 158 | def test_assign_duplicate_user_role(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 159 | # Duplicate user role should not get assigned |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 160 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 161 | self.client.assign_user_role(tenant['id'], user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 162 | self.assertRaises(exceptions.Duplicate, self.client.assign_user_role, |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 163 | tenant['id'], user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 164 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 165 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 166 | def test_remove_user_role(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 167 | # Remove a role assigned to a user on a tenant |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 168 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 169 | resp, user_role = self.client.assign_user_role(tenant['id'], |
| 170 | user['id'], role['id']) |
| 171 | resp, body = self.client.remove_user_role(tenant['id'], user['id'], |
| 172 | user_role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 173 | self.assertEquals(resp['status'], '204') |
| 174 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 175 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 176 | def test_remove_user_role_by_unauthorized_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 177 | # Non admin user should not be authorized to remove a user's role |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 178 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 179 | resp, user_role = self.client.assign_user_role(tenant['id'], |
| 180 | user['id'], |
| 181 | role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 182 | self.assertRaises(exceptions.Unauthorized, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 183 | self.non_admin_client.remove_user_role, |
| 184 | tenant['id'], user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 185 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 186 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 187 | def test_remove_user_role_request_without_token(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 188 | # Request to remove a user's role without a valid token |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 189 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 190 | resp, user_role = self.client.assign_user_role(tenant['id'], |
| 191 | user['id'], |
| 192 | role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 193 | token = self.client.get_auth() |
| 194 | self.client.delete_token(token) |
| 195 | self.assertRaises(exceptions.Unauthorized, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 196 | self.client.remove_user_role, tenant['id'], |
| 197 | user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 198 | self.client.clear_auth() |
| 199 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 200 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 201 | def test_remove_user_role_non_existant_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 202 | # Attempt to remove a role from a non existent user should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 203 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 204 | resp, user_role = self.client.assign_user_role(tenant['id'], |
| 205 | user['id'], |
| 206 | role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 207 | self.assertRaises(exceptions.NotFound, self.client.remove_user_role, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 208 | tenant['id'], 'junk-user-id-123', role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 209 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 210 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 211 | def test_remove_user_role_non_existant_role(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 212 | # Attempt to delete a non existent role from a user should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 213 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 214 | resp, user_role = self.client.assign_user_role(tenant['id'], |
| 215 | user['id'], |
| 216 | role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 217 | self.assertRaises(exceptions.NotFound, self.client.remove_user_role, |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 218 | tenant['id'], user['id'], 'junk-user-role-123') |
| 219 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 220 | @attr(type='gate') |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 221 | def test_remove_user_role_non_existant_tenant(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 222 | # Attempt to remove a role from a non existent tenant should fail |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 223 | (user, tenant, role) = self._get_role_params() |
| 224 | resp, user_role = self.client.assign_user_role(tenant['id'], |
| 225 | user['id'], |
| 226 | role['id']) |
| 227 | self.assertRaises(exceptions.NotFound, self.client.remove_user_role, |
| 228 | 'junk-tenant-id-123', user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 229 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 230 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 231 | def test_list_user_roles(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 232 | # List roles assigned to a user on tenant |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 233 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 234 | self.client.assign_user_role(tenant['id'], user['id'], role['id']) |
| 235 | resp, roles = self.client.list_user_roles(tenant['id'], user['id']) |
Adam Young | ddb8289 | 2013-02-15 13:10:35 -0500 | [diff] [blame] | 236 | self.assert_role_in_role_list(role, roles) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 237 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 238 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 239 | def test_list_user_roles_by_unauthorized_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 240 | # Non admin user should not be authorized to list a user's roles |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 241 | (user, tenant, role) = self._get_role_params() |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 242 | self.client.assign_user_role(tenant['id'], user['id'], role['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 243 | self.assertRaises(exceptions.Unauthorized, |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 244 | self.non_admin_client.list_user_roles, tenant['id'], |
| 245 | user['id']) |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 246 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 247 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 248 | def test_list_user_roles_request_without_token(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 249 | # Request to list user's roles without a valid token should fail |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 250 | (user, tenant, role) = self._get_role_params() |
| 251 | token = self.client.get_auth() |
| 252 | self.client.delete_token(token) |
Jaroslav Henner | 501cacd | 2012-08-16 10:32:38 +0200 | [diff] [blame] | 253 | try: |
| 254 | self.assertRaises(exceptions.Unauthorized, |
| 255 | self.client.list_user_roles, tenant['id'], |
| 256 | user['id']) |
| 257 | finally: |
| 258 | self.client.clear_auth() |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 259 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 260 | @attr(type='gate') |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 261 | def test_list_user_roles_for_non_existent_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 262 | # Attempt to list roles of a non existent user should fail |
rajalakshmi-ganesan | 8ba945e | 2012-08-01 15:43:19 +0530 | [diff] [blame] | 263 | (user, tenant, role) = self._get_role_params() |
Rohit Karajgi | 69e80a0 | 2012-05-15 03:54:04 -0700 | [diff] [blame] | 264 | self.assertRaises(exceptions.NotFound, self.client.list_user_roles, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 265 | tenant['id'], 'junk-role-aabbcc11') |
Vincent Hou | 6b8a7b7 | 2012-08-25 01:24:33 +0800 | [diff] [blame] | 266 | |
| 267 | |
Attila Fazekas | 0d0c616 | 2013-02-24 09:14:23 +0100 | [diff] [blame] | 268 | class RolesTestXML(RolesTestJSON): |
| 269 | _interface = 'xml' |