blob: 60abde788815d61b0a34b0d04e12c8c40f09ae88 [file] [log] [blame]
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +05301# Copyright 2013 OpenStack Foundation
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
Lance Bragstadf6026442015-11-25 15:29:50 +000016import time
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.identity import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Matthew Treinish5c660ab2014-05-18 21:14:36 -040020from tempest import test
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053021
22
Matthew Treinishdb2c5972014-01-31 22:18:59 +000023class UsersV3TestJSON(base.BaseIdentityV3AdminTest):
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053024
Chris Hoge7579c1a2015-02-26 14:12:15 -080025 @test.idempotent_id('b537d090-afb9-4519-b95d-270b0708e87e')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053026 def test_user_update(self):
27 # Test case to check if updating of user attributes is successful.
Attila Fazekasf7f34f92013-08-01 17:01:44 +020028 # Creating first user
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000029 u_name = data_utils.rand_name('user')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053030 u_desc = u_name + 'description'
31 u_email = u_name + '@testmail.tm'
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000032 u_password = data_utils.rand_name('pass')
David Kranzd8ccb792014-12-29 11:32:05 -050033 user = self.client.create_user(
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053034 u_name, description=u_desc, password=u_password,
John Warren56317e02015-08-12 20:48:32 +000035 email=u_email, enabled=False)['user']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053036 # Delete the User at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +000037 self.addCleanup(self.client.delete_user, user['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020038 # Creating second project for updation
David Kranzd8ccb792014-12-29 11:32:05 -050039 project = self.client.create_project(
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000040 data_utils.rand_name('project'),
John Warren56317e02015-08-12 20:48:32 +000041 description=data_utils.rand_name('project-desc'))['project']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053042 # Delete the Project at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +000043 self.addCleanup(self.client.delete_project, project['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020044 # Updating user details with new values
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000045 u_name2 = data_utils.rand_name('user2')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053046 u_email2 = u_name2 + '@testmail.tm'
47 u_description2 = u_name2 + ' description'
David Kranzd8ccb792014-12-29 11:32:05 -050048 update_user = self.client.update_user(
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053049 user['id'], name=u_name2, description=u_description2,
50 project_id=project['id'],
John Warren56317e02015-08-12 20:48:32 +000051 email=u_email2, enabled=False)['user']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053052 self.assertEqual(u_name2, update_user['name'])
53 self.assertEqual(u_description2, update_user['description'])
54 self.assertEqual(project['id'],
55 update_user['project_id'])
56 self.assertEqual(u_email2, update_user['email'])
Ken'ichi Ohmichi73cb70b2015-04-17 02:31:12 +000057 self.assertEqual(False, update_user['enabled'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020058 # GET by id after updation
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +000059 new_user_get = self.client.show_user(user['id'])['user']
Attila Fazekasf7f34f92013-08-01 17:01:44 +020060 # Assert response body of GET after updation
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053061 self.assertEqual(u_name2, new_user_get['name'])
62 self.assertEqual(u_description2, new_user_get['description'])
63 self.assertEqual(project['id'],
64 new_user_get['project_id'])
65 self.assertEqual(u_email2, new_user_get['email'])
Ken'ichi Ohmichi73cb70b2015-04-17 02:31:12 +000066 self.assertEqual(False, new_user_get['enabled'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053067
Chris Hoge7579c1a2015-02-26 14:12:15 -080068 @test.idempotent_id('2d223a0e-e457-4a70-9fb1-febe027a0ff9')
ravikumar-venkatesand35d6442014-05-05 12:14:45 +000069 def test_update_user_password(self):
70 # Creating User to check password updation
71 u_name = data_utils.rand_name('user')
72 original_password = data_utils.rand_name('pass')
David Kranzd8ccb792014-12-29 11:32:05 -050073 user = self.client.create_user(
John Warren56317e02015-08-12 20:48:32 +000074 u_name, password=original_password)['user']
ravikumar-venkatesand35d6442014-05-05 12:14:45 +000075 # Delete the User at the end all test methods
76 self.addCleanup(self.client.delete_user, user['id'])
77 # Update user with new password
78 new_password = data_utils.rand_name('pass1')
79 self.client.update_user_password(user['id'], new_password,
80 original_password)
Lance Bragstadf6026442015-11-25 15:29:50 +000081 # TODO(lbragstad): Sleeping after the response status has been checked
82 # and the body loaded as JSON allows requests to fail-fast. The sleep
83 # is necessary because keystone will err on the side of security and
84 # invalidate tokens within a small margin of error (within the same
85 # wall clock second) after a revocation event is issued (such as a
86 # password change). Remove this once keystone and Fernet support
87 # sub-second precision, see bug 1517697 for more details.
88 time.sleep(1)
Jamie Lennox97504612015-02-26 16:47:06 +110089 resp = self.token.auth(user_id=user['id'],
90 password=new_password).response
ravikumar-venkatesand35d6442014-05-05 12:14:45 +000091 subject_token = resp['x-subject-token']
92 # Perform GET Token to verify and confirm password is updated
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +000093 token_details = self.client.show_token(subject_token)['token']
ravikumar-venkatesand35d6442014-05-05 12:14:45 +000094 self.assertEqual(resp['x-subject-token'], subject_token)
95 self.assertEqual(token_details['user']['id'], user['id'])
96 self.assertEqual(token_details['user']['name'], u_name)
97
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('a831e70c-e35b-430b-92ed-81ebbc5437b8')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053099 def test_list_user_projects(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200100 # List the projects that a user has access upon
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530101 assigned_project_ids = list()
102 fetched_project_ids = list()
David Kranzd8ccb792014-12-29 11:32:05 -0500103 u_project = self.client.create_project(
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000104 data_utils.rand_name('project'),
John Warren56317e02015-08-12 20:48:32 +0000105 description=data_utils.rand_name('project-desc'))['project']
Mitsuhiko Yamazakif58442e2013-05-13 15:46:44 +0900106 # Delete the Project at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000107 self.addCleanup(self.client.delete_project, u_project['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200108 # Create a user.
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000109 u_name = data_utils.rand_name('user')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530110 u_desc = u_name + 'description'
111 u_email = u_name + '@testmail.tm'
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000112 u_password = data_utils.rand_name('pass')
David Kranzd8ccb792014-12-29 11:32:05 -0500113 user_body = self.client.create_user(
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530114 u_name, description=u_desc, password=u_password,
John Warren56317e02015-08-12 20:48:32 +0000115 email=u_email, enabled=False, project_id=u_project['id'])['user']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530116 # Delete the User at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000117 self.addCleanup(self.client.delete_user, user_body['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530118 # Creating Role
David Kranzd8ccb792014-12-29 11:32:05 -0500119 role_body = self.client.create_role(
John Warren56317e02015-08-12 20:48:32 +0000120 data_utils.rand_name('role'))['role']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530121 # Delete the Role at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000122 self.addCleanup(self.client.delete_role, role_body['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530123
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +0000124 user = self.client.show_user(user_body['id'])['user']
125 role = self.client.show_role(role_body['id'])['role']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530126 for i in range(2):
127 # Creating project so as to assign role
David Kranzd8ccb792014-12-29 11:32:05 -0500128 project_body = self.client.create_project(
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000129 data_utils.rand_name('project'),
John Warren56317e02015-08-12 20:48:32 +0000130 description=data_utils.rand_name('project-desc'))['project']
131 project = self.client.get_project(project_body['id'])['project']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530132 # Delete the Project at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000133 self.addCleanup(self.client.delete_project, project_body['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200134 # Assigning roles to user on project
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000135 self.client.assign_user_role(project['id'],
136 user['id'],
137 role['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530138 assigned_project_ids.append(project['id'])
John Warren56317e02015-08-12 20:48:32 +0000139 body = self.client.list_user_projects(user['id'])['projects']
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530140 for i in body:
141 fetched_project_ids.append(i['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200142 # verifying the project ids in list
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530143 missing_projects =\
144 [p for p in assigned_project_ids
145 if p not in fetched_project_ids]
146 self.assertEqual(0, len(missing_projects),
147 "Failed to find project %s in fetched list" %
148 ', '.join(m_project for m_project
DennyZhangb432bac2013-09-17 16:24:12 +0000149 in missing_projects))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530150
Chris Hoge7579c1a2015-02-26 14:12:15 -0800151 @test.idempotent_id('c10dcd90-461d-4b16-8e23-4eb836c00644')
wanglianminb1ddea72014-02-25 17:17:30 +0800152 def test_get_user(self):
153 # Get a user detail
154 self.data.setup_test_v3_user()
Ken'ichi Ohmichi402b8752015-11-09 10:47:16 +0000155 user = self.client.show_user(self.data.v3_user['id'])['user']
wanglianminb1ddea72014-02-25 17:17:30 +0800156 self.assertEqual(self.data.v3_user['id'], user['id'])