blob: fc64f67418377eb63f41cba4961b37aa790f7ced [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipesf38eaac2012-06-21 13:37:35 -04002# 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
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090016from testtools import matchers
Sean Dague1937d092013-05-17 16:36:38 -040017
18from tempest.api.identity import base
Masayuki Igawaa2ccca02013-09-17 15:32:46 +090019from tempest.common.utils import data_utils
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090020from tempest import test
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070021
22
Matthew Treinishdb2c5972014-01-31 22:18:59 +000023class UsersTestJSON(base.BaseIdentityV2AdminTest):
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070024
Adalberto Medeiros081464b2013-08-16 09:41:29 -040025 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010026 def resource_setup(cls):
27 super(UsersTestJSON, cls).resource_setup()
Masayuki Igawaa2ccca02013-09-17 15:32:46 +090028 cls.alt_user = data_utils.rand_name('test_user_')
29 cls.alt_password = data_utils.rand_name('pass_')
Adalberto Medeiros081464b2013-08-16 09:41:29 -040030 cls.alt_email = cls.alt_user + '@testmail.tm'
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070031
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090032 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080033 @test.idempotent_id('2d55a71e-da1d-4b43-9c03-d269fd93d905')
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070034 def test_create_user(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050035 # Create a user
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070036 self.data.setup_test_tenant()
David Kranzb7afa922014-12-30 10:56:26 -050037 user = self.client.create_user(self.alt_user, self.alt_password,
38 self.data.tenant['id'],
39 self.alt_email)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070040 self.data.users.append(user)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070041 self.assertEqual(self.alt_user, user['name'])
42
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090043 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080044 @test.idempotent_id('89d9fdb8-15c2-4304-a429-48715d0af33d')
huangtianhuafc8db4f2013-10-08 12:05:58 +080045 def test_create_user_with_enabled(self):
46 # Create a user with enabled : False
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070047 self.data.setup_test_tenant()
Masayuki Igawaa2ccca02013-09-17 15:32:46 +090048 name = data_utils.rand_name('test_user_')
David Kranzb7afa922014-12-30 10:56:26 -050049 user = self.client.create_user(name, self.alt_password,
50 self.data.tenant['id'],
51 self.alt_email, enabled=False)
huangtianhuafc8db4f2013-10-08 12:05:58 +080052 self.data.users.append(user)
huangtianhuafc8db4f2013-10-08 12:05:58 +080053 self.assertEqual(name, user['name'])
54 self.assertEqual('false', str(user['enabled']).lower())
55 self.assertEqual(self.alt_email, user['email'])
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070056
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090057 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080058 @test.idempotent_id('39d05857-e8a5-4ed4-ba83-0b52d3ab97ee')
Chang Bo Guob36b2f12013-09-13 04:52:00 -070059 def test_update_user(self):
60 # Test case to check if updating of user attributes is successful.
Masayuki Igawaa2ccca02013-09-17 15:32:46 +090061 test_user = data_utils.rand_name('test_user_')
Chang Bo Guob36b2f12013-09-13 04:52:00 -070062 self.data.setup_test_tenant()
David Kranzb7afa922014-12-30 10:56:26 -050063 user = self.client.create_user(test_user, self.alt_password,
64 self.data.tenant['id'],
65 self.alt_email)
Chang Bo Guob36b2f12013-09-13 04:52:00 -070066 # Delete the User at the end of this method
67 self.addCleanup(self.client.delete_user, user['id'])
68 # Updating user details with new values
Masayuki Igawaa2ccca02013-09-17 15:32:46 +090069 u_name2 = data_utils.rand_name('user2-')
Chang Bo Guob36b2f12013-09-13 04:52:00 -070070 u_email2 = u_name2 + '@testmail.tm'
David Kranzb7afa922014-12-30 10:56:26 -050071 update_user = self.client.update_user(user['id'], name=u_name2,
72 email=u_email2,
73 enabled=False)
Chang Bo Guob36b2f12013-09-13 04:52:00 -070074 self.assertEqual(u_name2, update_user['name'])
75 self.assertEqual(u_email2, update_user['email'])
76 self.assertEqual('false', str(update_user['enabled']).lower())
77 # GET by id after updating
David Kranzb7afa922014-12-30 10:56:26 -050078 updated_user = self.client.get_user(user['id'])
Chang Bo Guob36b2f12013-09-13 04:52:00 -070079 # Assert response body of GET after updating
80 self.assertEqual(u_name2, updated_user['name'])
81 self.assertEqual(u_email2, updated_user['email'])
82 self.assertEqual('false', str(updated_user['enabled']).lower())
83
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090084 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080085 @test.idempotent_id('29ed26f4-a74e-4425-9a85-fdb49fa269d2')
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070086 def test_delete_user(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050087 # Delete a user
Masayuki Igawaa2ccca02013-09-17 15:32:46 +090088 test_user = data_utils.rand_name('test_user_')
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070089 self.data.setup_test_tenant()
David Kranzb7afa922014-12-30 10:56:26 -050090 user = self.client.create_user(test_user, self.alt_password,
91 self.data.tenant['id'],
92 self.alt_email)
David Kranze9d2f422014-07-02 13:57:41 -040093 self.client.delete_user(user['id'])
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070094
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090095 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('aca696c3-d645-4f45-b728-63646045beb1')
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070097 def test_user_authentication(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050098 # Valid user's token is authenticated
Rohit Karajgi6b1e1542012-05-14 05:55:54 -070099 self.data.setup_test_user()
100 # Get a token
101 self.token_client.auth(self.data.test_user, self.data.test_password,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800102 self.data.test_tenant)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700103 # Re-auth
David Kranzfb3efa72014-08-28 16:58:25 -0400104 self.token_client.auth(self.data.test_user,
105 self.data.test_password,
106 self.data.test_tenant)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700107
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900108 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800109 @test.idempotent_id('5d1fa498-4c2d-4732-a8fe-2b054598cfdd')
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700110 def test_authentication_request_without_token(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500111 # Request for token authentication with a valid token in header
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700112 self.data.setup_test_user()
113 self.token_client.auth(self.data.test_user, self.data.test_password,
114 self.data.test_tenant)
115 # Get the token of the current client
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000116 token = self.client.auth_provider.get_token()
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700117 # Delete the token from database
118 self.client.delete_token(token)
119 # Re-auth
David Kranzfb3efa72014-08-28 16:58:25 -0400120 self.token_client.auth(self.data.test_user,
121 self.data.test_password,
122 self.data.test_tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000123 self.client.auth_provider.clear_auth()
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700124
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900125 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800126 @test.idempotent_id('a149c02e-e5e0-4b89-809e-7e8faf33ccda')
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700127 def test_get_users(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500128 # Get a list of users and find the test user
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700129 self.data.setup_test_user()
David Kranzb7afa922014-12-30 10:56:26 -0500130 users = self.client.get_users()
ivan-zhu1feeb382013-01-24 10:14:39 +0800131 self.assertThat([u['name'] for u in users],
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900132 matchers.Contains(self.data.test_user),
ivan-zhu1feeb382013-01-24 10:14:39 +0800133 "Could not find %s" % self.data.test_user)
Rohit Karajgi6b1e1542012-05-14 05:55:54 -0700134
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900135 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800136 @test.idempotent_id('6e317209-383a-4bed-9f10-075b7c82c79a')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530137 def test_list_users_for_tenant(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500138 # Return a list of all users for a tenant
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530139 self.data.setup_test_tenant()
140 user_ids = list()
141 fetched_user_ids = list()
Masayuki Igawaa2ccca02013-09-17 15:32:46 +0900142 alt_tenant_user1 = data_utils.rand_name('tenant_user1_')
David Kranzb7afa922014-12-30 10:56:26 -0500143 user1 = self.client.create_user(alt_tenant_user1, 'password1',
144 self.data.tenant['id'],
145 'user1@123')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530146 user_ids.append(user1['id'])
147 self.data.users.append(user1)
Adalberto Medeiros081464b2013-08-16 09:41:29 -0400148
Masayuki Igawaa2ccca02013-09-17 15:32:46 +0900149 alt_tenant_user2 = data_utils.rand_name('tenant_user2_')
David Kranzb7afa922014-12-30 10:56:26 -0500150 user2 = self.client.create_user(alt_tenant_user2, 'password2',
151 self.data.tenant['id'],
152 'user2@123')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530153 user_ids.append(user2['id'])
154 self.data.users.append(user2)
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200155 # List of users for the respective tenant ID
David Kranzb7afa922014-12-30 10:56:26 -0500156 body = self.client.list_users_for_tenant(self.data.tenant['id'])
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530157 for i in body:
158 fetched_user_ids.append(i['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200159 # verifying the user Id in the list
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530160 missing_users =\
161 [user for user in user_ids if user not in fetched_user_ids]
162 self.assertEqual(0, len(missing_users),
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800163 "Failed to find user %s in fetched list" %
164 ', '.join(m_user for m_user in missing_users))
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530165
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900166 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800167 @test.idempotent_id('a8b54974-40e1-41c0-b812-50fc90827971')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530168 def test_list_users_with_roles_for_tenant(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500169 # Return list of users on tenant when roles are assigned to users
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530170 self.data.setup_test_user()
171 self.data.setup_test_role()
172 user = self.get_user_by_name(self.data.test_user)
173 tenant = self.get_tenant_by_name(self.data.test_tenant)
174 role = self.get_role_by_name(self.data.test_role)
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200175 # Assigning roles to two users
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530176 user_ids = list()
177 fetched_user_ids = list()
178 user_ids.append(user['id'])
David Kranzb7afa922014-12-30 10:56:26 -0500179 role = self.client.assign_user_role(tenant['id'], user['id'],
180 role['id'])
Adalberto Medeiros081464b2013-08-16 09:41:29 -0400181
Masayuki Igawaa2ccca02013-09-17 15:32:46 +0900182 alt_user2 = data_utils.rand_name('second_user_')
David Kranzb7afa922014-12-30 10:56:26 -0500183 second_user = self.client.create_user(alt_user2, 'password1',
184 self.data.tenant['id'],
185 'user2@123')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530186 user_ids.append(second_user['id'])
187 self.data.users.append(second_user)
David Kranzb7afa922014-12-30 10:56:26 -0500188 role = self.client.assign_user_role(tenant['id'],
189 second_user['id'],
190 role['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200191 # List of users with roles for the respective tenant ID
David Kranzb7afa922014-12-30 10:56:26 -0500192 body = self.client.list_users_for_tenant(self.data.tenant['id'])
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530193 for i in body:
194 fetched_user_ids.append(i['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200195 # verifying the user Id in the list
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700196 missing_users = [missing_user for missing_user in user_ids
197 if missing_user not in fetched_user_ids]
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530198 self.assertEqual(0, len(missing_users),
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800199 "Failed to find user %s in fetched list" %
200 ', '.join(m_user for m_user in missing_users))
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +0530201
Abhijeet.Jainff5c3542014-05-06 16:07:30 +0530202 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800203 @test.idempotent_id('1aeb25ac-6ec5-4d8b-97cb-7ac3567a989f')
Abhijeet.Jainff5c3542014-05-06 16:07:30 +0530204 def test_update_user_password(self):
205 # Test case to check if updating of user password is successful.
206 self.data.setup_test_user()
207 # Updating the user with new password
208 new_pass = data_utils.rand_name('pass-')
David Kranzb7afa922014-12-30 10:56:26 -0500209 update_user = self.client.update_user_password(
Abhijeet.Jainff5c3542014-05-06 16:07:30 +0530210 self.data.user['id'], new_pass)
Abhijeet.Jainff5c3542014-05-06 16:07:30 +0530211 self.assertEqual(update_user['id'], self.data.user['id'])
212
213 # Validate the updated password
214 # Get a token
David Kranzb7afa922014-12-30 10:56:26 -0500215 body = self.token_client.auth(self.data.test_user, new_pass,
216 self.data.test_tenant)
Abhijeet.Jainff5c3542014-05-06 16:07:30 +0530217 self.assertTrue('id' in body['token'])