ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Yaroslav Lobankov | cbcb611 | 2016-03-08 12:30:01 -0600 | [diff] [blame] | 16 | import time |
| 17 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 18 | from testtools import matchers |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 19 | |
| 20 | from tempest.api.identity import base |
Ken'ichi Ohmichi | 7bd2575 | 2017-03-10 10:45:39 -0800 | [diff] [blame] | 21 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 22 | from tempest.lib import decorators |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 23 | |
| 24 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 25 | class UsersTestJSON(base.BaseIdentityV2AdminTest): |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 26 | |
Adalberto Medeiros | 081464b | 2013-08-16 09:41:29 -0400 | [diff] [blame] | 27 | @classmethod |
Andrea Frittoli | 7688e74 | 2014-09-15 12:38:22 +0100 | [diff] [blame] | 28 | def resource_setup(cls): |
| 29 | super(UsersTestJSON, cls).resource_setup() |
Ken'ichi Ohmichi | 9650847 | 2015-03-23 01:43:42 +0000 | [diff] [blame] | 30 | cls.alt_user = data_utils.rand_name('test_user') |
Adalberto Medeiros | 081464b | 2013-08-16 09:41:29 -0400 | [diff] [blame] | 31 | cls.alt_email = cls.alt_user + '@testmail.tm' |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 32 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 33 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 34 | @decorators.idempotent_id('2d55a71e-da1d-4b43-9c03-d269fd93d905') |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 35 | def test_create_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 36 | # Create a user |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 37 | tenant = self.setup_test_tenant() |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 38 | user = self.create_test_user(name=self.alt_user, tenantId=tenant['id']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 39 | self.assertEqual(self.alt_user, user['name']) |
| 40 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 41 | @decorators.idempotent_id('89d9fdb8-15c2-4304-a429-48715d0af33d') |
huangtianhua | fc8db4f | 2013-10-08 12:05:58 +0800 | [diff] [blame] | 42 | def test_create_user_with_enabled(self): |
| 43 | # Create a user with enabled : False |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 44 | tenant = self.setup_test_tenant() |
Ken'ichi Ohmichi | 9650847 | 2015-03-23 01:43:42 +0000 | [diff] [blame] | 45 | name = data_utils.rand_name('test_user') |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 46 | user = self.create_test_user(name=name, |
| 47 | tenantId=tenant['id'], |
| 48 | email=self.alt_email, |
| 49 | enabled=False) |
huangtianhua | fc8db4f | 2013-10-08 12:05:58 +0800 | [diff] [blame] | 50 | self.assertEqual(name, user['name']) |
Ken'ichi Ohmichi | 73cb70b | 2015-04-17 02:31:12 +0000 | [diff] [blame] | 51 | self.assertEqual(False, user['enabled']) |
huangtianhua | fc8db4f | 2013-10-08 12:05:58 +0800 | [diff] [blame] | 52 | self.assertEqual(self.alt_email, user['email']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 53 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 54 | @decorators.idempotent_id('39d05857-e8a5-4ed4-ba83-0b52d3ab97ee') |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 55 | def test_update_user(self): |
| 56 | # Test case to check if updating of user attributes is successful. |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 57 | tenant = self.setup_test_tenant() |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 58 | user = self.create_test_user(tenantId=tenant['id']) |
| 59 | |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 60 | # Updating user details with new values |
Ken'ichi Ohmichi | 9650847 | 2015-03-23 01:43:42 +0000 | [diff] [blame] | 61 | u_name2 = data_utils.rand_name('user2') |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 62 | u_email2 = u_name2 + '@testmail.tm' |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 63 | update_user = self.users_client.update_user(user['id'], name=u_name2, |
| 64 | email=u_email2, |
| 65 | enabled=False)['user'] |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 66 | self.assertEqual(u_name2, update_user['name']) |
| 67 | self.assertEqual(u_email2, update_user['email']) |
Ken'ichi Ohmichi | 73cb70b | 2015-04-17 02:31:12 +0000 | [diff] [blame] | 68 | self.assertEqual(False, update_user['enabled']) |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 69 | # GET by id after updating |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 70 | updated_user = self.users_client.show_user(user['id'])['user'] |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 71 | # Assert response body of GET after updating |
| 72 | self.assertEqual(u_name2, updated_user['name']) |
| 73 | self.assertEqual(u_email2, updated_user['email']) |
Ken'ichi Ohmichi | 73cb70b | 2015-04-17 02:31:12 +0000 | [diff] [blame] | 74 | self.assertEqual(False, update_user['enabled']) |
Chang Bo Guo | b36b2f1 | 2013-09-13 04:52:00 -0700 | [diff] [blame] | 75 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 76 | @decorators.idempotent_id('29ed26f4-a74e-4425-9a85-fdb49fa269d2') |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 77 | def test_delete_user(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 78 | # Delete a user |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 79 | tenant = self.setup_test_tenant() |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 80 | user = self.create_test_user(tenantId=tenant['id']) |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 81 | self.users_client.delete_user(user['id']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 82 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 83 | @decorators.idempotent_id('aca696c3-d645-4f45-b728-63646045beb1') |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 84 | def test_user_authentication(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 85 | # Valid user's token is authenticated |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 86 | password = data_utils.rand_password() |
| 87 | user = self.setup_test_user(password) |
| 88 | tenant = self.tenants_client.show_tenant(user['tenantId'])['tenant'] |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 89 | # Get a token |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 90 | self.token_client.auth(user['name'], |
| 91 | password, |
| 92 | tenant['name']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 93 | # Re-auth |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 94 | self.token_client.auth(user['name'], |
| 95 | password, |
| 96 | tenant['name']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 97 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 98 | @decorators.idempotent_id('5d1fa498-4c2d-4732-a8fe-2b054598cfdd') |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 99 | def test_authentication_request_without_token(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 100 | # Request for token authentication with a valid token in header |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 101 | password = data_utils.rand_password() |
| 102 | user = self.setup_test_user(password) |
| 103 | tenant = self.tenants_client.show_tenant(user['tenantId'])['tenant'] |
| 104 | self.token_client.auth(user['name'], |
| 105 | password, |
| 106 | tenant['name']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 107 | # Get the token of the current client |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 108 | token = self.client.auth_provider.get_token() |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 109 | # Delete the token from database |
| 110 | self.client.delete_token(token) |
| 111 | # Re-auth |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 112 | self.token_client.auth(user['name'], |
| 113 | password, |
| 114 | tenant['name']) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 115 | self.client.auth_provider.clear_auth() |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 116 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 117 | @decorators.idempotent_id('a149c02e-e5e0-4b89-809e-7e8faf33ccda') |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 118 | def test_get_users(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 119 | # Get a list of users and find the test user |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 120 | user = self.setup_test_user() |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 121 | users = self.users_client.list_users()['users'] |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 122 | self.assertThat([u['name'] for u in users], |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 123 | matchers.Contains(user['name']), |
| 124 | "Could not find %s" % user['name']) |
Rohit Karajgi | 6b1e154 | 2012-05-14 05:55:54 -0700 | [diff] [blame] | 125 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 126 | @decorators.idempotent_id('6e317209-383a-4bed-9f10-075b7c82c79a') |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 127 | def test_list_users_for_tenant(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 128 | # Return a list of all users for a tenant |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 129 | tenant = self.setup_test_tenant() |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 130 | user_ids = list() |
| 131 | fetched_user_ids = list() |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 132 | user1 = self.create_test_user(tenantId=tenant['id']) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 133 | user_ids.append(user1['id']) |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 134 | user2 = self.create_test_user(tenantId=tenant['id']) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 135 | user_ids.append(user2['id']) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 136 | # List of users for the respective tenant ID |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 137 | body = (self.tenants_client.list_tenant_users(tenant['id']) |
Anusha Ramineni | 0cfb461 | 2015-08-24 08:49:10 +0530 | [diff] [blame] | 138 | ['users']) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 139 | for i in body: |
| 140 | fetched_user_ids.append(i['id']) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 141 | # verifying the user Id in the list |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 142 | missing_users =\ |
| 143 | [user for user in user_ids if user not in fetched_user_ids] |
| 144 | self.assertEqual(0, len(missing_users), |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 145 | "Failed to find user %s in fetched list" % |
| 146 | ', '.join(m_user for m_user in missing_users)) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 147 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 148 | @decorators.idempotent_id('a8b54974-40e1-41c0-b812-50fc90827971') |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 149 | def test_list_users_with_roles_for_tenant(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 150 | # Return list of users on tenant when roles are assigned to users |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 151 | user = self.setup_test_user() |
| 152 | tenant = self.tenants_client.show_tenant(user['tenantId'])['tenant'] |
| 153 | role = self.setup_test_role() |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 154 | # Assigning roles to two users |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 155 | user_ids = list() |
| 156 | fetched_user_ids = list() |
| 157 | user_ids.append(user['id']) |
ghanshyam | 50894fc | 2016-06-17 13:20:25 +0900 | [diff] [blame] | 158 | role = self.roles_client.create_user_role_on_project( |
| 159 | tenant['id'], user['id'], role['id'])['role'] |
Adalberto Medeiros | 081464b | 2013-08-16 09:41:29 -0400 | [diff] [blame] | 160 | |
zhufl | 75d51a9 | 2017-04-11 16:02:39 +0800 | [diff] [blame] | 161 | second_user = self.create_test_user(tenantId=tenant['id']) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 162 | user_ids.append(second_user['id']) |
ghanshyam | 50894fc | 2016-06-17 13:20:25 +0900 | [diff] [blame] | 163 | role = self.roles_client.create_user_role_on_project( |
| 164 | tenant['id'], second_user['id'], role['id'])['role'] |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 165 | # List of users with roles for the respective tenant ID |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 166 | body = (self.tenants_client.list_tenant_users(tenant['id'])['users']) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 167 | for i in body: |
| 168 | fetched_user_ids.append(i['id']) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 169 | # verifying the user Id in the list |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 170 | missing_users = [missing_user for missing_user in user_ids |
| 171 | if missing_user not in fetched_user_ids] |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 172 | self.assertEqual(0, len(missing_users), |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 173 | "Failed to find user %s in fetched list" % |
| 174 | ', '.join(m_user for m_user in missing_users)) |
rajalakshmi-ganesan | efc8bd7 | 2012-05-30 17:52:11 +0530 | [diff] [blame] | 175 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 176 | @decorators.idempotent_id('1aeb25ac-6ec5-4d8b-97cb-7ac3567a989f') |
Abhijeet.Jain | ff5c354 | 2014-05-06 16:07:30 +0530 | [diff] [blame] | 177 | def test_update_user_password(self): |
| 178 | # Test case to check if updating of user password is successful. |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 179 | user = self.setup_test_user() |
| 180 | tenant = self.tenants_client.show_tenant(user['tenantId'])['tenant'] |
Abhijeet.Jain | ff5c354 | 2014-05-06 16:07:30 +0530 | [diff] [blame] | 181 | # Updating the user with new password |
Zack Feldstein | d8c5f7a | 2015-12-14 10:44:07 -0600 | [diff] [blame] | 182 | new_pass = data_utils.rand_password() |
Daniel Mellado | 82c83a5 | 2015-12-09 15:16:49 +0000 | [diff] [blame] | 183 | update_user = self.users_client.update_user_password( |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 184 | user['id'], password=new_pass)['user'] |
| 185 | self.assertEqual(update_user['id'], user['id']) |
Yaroslav Lobankov | cbcb611 | 2016-03-08 12:30:01 -0600 | [diff] [blame] | 186 | # NOTE(morganfainberg): Fernet tokens are not subsecond aware and |
| 187 | # Keystone should only be precise to the second. Sleep to ensure |
| 188 | # we are passing the second boundary. |
| 189 | time.sleep(1) |
| 190 | # Validate the updated password through getting a token. |
Castulo J. Martinez | e3adee4 | 2016-07-14 10:40:08 -0700 | [diff] [blame] | 191 | body = self.token_client.auth(user['name'], new_pass, |
| 192 | tenant['name']) |
melissaml | 37503dd | 2016-09-14 13:10:49 +0800 | [diff] [blame] | 193 | self.assertIn('id', body['token']) |