blob: 3c258193bac2c5f7cc315630ed5e34518ebd4840 [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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.identity import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Matthew Treinish5c660ab2014-05-18 21:14:36 -040018from tempest import test
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053019
20
Matthew Treinishdb2c5972014-01-31 22:18:59 +000021class UsersV3TestJSON(base.BaseIdentityV3AdminTest):
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053022 _interface = 'json'
23
Matthew Treinish5c660ab2014-05-18 21:14:36 -040024 @test.attr(type='gate')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053025 def test_user_update(self):
26 # Test case to check if updating of user attributes is successful.
Attila Fazekasf7f34f92013-08-01 17:01:44 +020027 # Creating first user
Masayuki Igawa259c1132013-10-31 17:48:44 +090028 u_name = data_utils.rand_name('user-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053029 u_desc = u_name + 'description'
30 u_email = u_name + '@testmail.tm'
Masayuki Igawa259c1132013-10-31 17:48:44 +090031 u_password = data_utils.rand_name('pass-')
David Kranze9d2f422014-07-02 13:57:41 -040032 _, user = self.client.create_user(
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053033 u_name, description=u_desc, password=u_password,
34 email=u_email, enabled=False)
35 # Delete the User at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +000036 self.addCleanup(self.client.delete_user, user['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020037 # Creating second project for updation
David Kranze9d2f422014-07-02 13:57:41 -040038 _, project = self.client.create_project(
Masayuki Igawa259c1132013-10-31 17:48:44 +090039 data_utils.rand_name('project-'),
40 description=data_utils.rand_name('project-desc-'))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053041 # Delete the Project at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +000042 self.addCleanup(self.client.delete_project, project['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020043 # Updating user details with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +090044 u_name2 = data_utils.rand_name('user2-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053045 u_email2 = u_name2 + '@testmail.tm'
46 u_description2 = u_name2 + ' description'
David Kranze9d2f422014-07-02 13:57:41 -040047 _, update_user = self.client.update_user(
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053048 user['id'], name=u_name2, description=u_description2,
49 project_id=project['id'],
50 email=u_email2, enabled=False)
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053051 self.assertEqual(u_name2, update_user['name'])
52 self.assertEqual(u_description2, update_user['description'])
53 self.assertEqual(project['id'],
54 update_user['project_id'])
55 self.assertEqual(u_email2, update_user['email'])
56 self.assertEqual('false', str(update_user['enabled']).lower())
Attila Fazekasf7f34f92013-08-01 17:01:44 +020057 # GET by id after updation
David Kranze9d2f422014-07-02 13:57:41 -040058 _, new_user_get = self.client.get_user(user['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020059 # Assert response body of GET after updation
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053060 self.assertEqual(u_name2, new_user_get['name'])
61 self.assertEqual(u_description2, new_user_get['description'])
62 self.assertEqual(project['id'],
63 new_user_get['project_id'])
64 self.assertEqual(u_email2, new_user_get['email'])
65 self.assertEqual('false', str(new_user_get['enabled']).lower())
66
Matthew Treinish5c660ab2014-05-18 21:14:36 -040067 @test.attr(type='gate')
ravikumar-venkatesand35d6442014-05-05 12:14:45 +000068 def test_update_user_password(self):
69 # Creating User to check password updation
70 u_name = data_utils.rand_name('user')
71 original_password = data_utils.rand_name('pass')
72 _, user = self.client.create_user(
73 u_name, password=original_password)
74 # Delete the User at the end all test methods
75 self.addCleanup(self.client.delete_user, user['id'])
76 # Update user with new password
77 new_password = data_utils.rand_name('pass1')
78 self.client.update_user_password(user['id'], new_password,
79 original_password)
80 resp, body = self.token.auth(user['id'], new_password)
81 self.assertEqual(201, resp.status)
82 subject_token = resp['x-subject-token']
83 # Perform GET Token to verify and confirm password is updated
84 _, token_details = self.client.get_token(subject_token)
85 self.assertEqual(resp['x-subject-token'], subject_token)
86 self.assertEqual(token_details['user']['id'], user['id'])
87 self.assertEqual(token_details['user']['name'], u_name)
88
89 @test.attr(type='gate')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053090 def test_list_user_projects(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020091 # List the projects that a user has access upon
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053092 assigned_project_ids = list()
93 fetched_project_ids = list()
Matthew Treinishdb2c5972014-01-31 22:18:59 +000094 _, u_project = self.client.create_project(
Masayuki Igawa259c1132013-10-31 17:48:44 +090095 data_utils.rand_name('project-'),
96 description=data_utils.rand_name('project-desc-'))
Mitsuhiko Yamazakif58442e2013-05-13 15:46:44 +090097 # Delete the Project at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +000098 self.addCleanup(self.client.delete_project, u_project['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020099 # Create a user.
Masayuki Igawa259c1132013-10-31 17:48:44 +0900100 u_name = data_utils.rand_name('user-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530101 u_desc = u_name + 'description'
102 u_email = u_name + '@testmail.tm'
Masayuki Igawa259c1132013-10-31 17:48:44 +0900103 u_password = data_utils.rand_name('pass-')
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000104 _, user_body = self.client.create_user(
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530105 u_name, description=u_desc, password=u_password,
106 email=u_email, enabled=False, project_id=u_project['id'])
107 # Delete the User at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000108 self.addCleanup(self.client.delete_user, user_body['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530109 # Creating Role
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000110 _, role_body = self.client.create_role(
Masayuki Igawa259c1132013-10-31 17:48:44 +0900111 data_utils.rand_name('role-'))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530112 # Delete the Role at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000113 self.addCleanup(self.client.delete_role, role_body['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530114
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000115 _, user = self.client.get_user(user_body['id'])
116 _, role = self.client.get_role(role_body['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530117 for i in range(2):
118 # Creating project so as to assign role
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000119 _, project_body = self.client.create_project(
Masayuki Igawa259c1132013-10-31 17:48:44 +0900120 data_utils.rand_name('project-'),
121 description=data_utils.rand_name('project-desc-'))
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000122 _, project = self.client.get_project(project_body['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530123 # Delete the Project at the end of this method
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000124 self.addCleanup(self.client.delete_project, project_body['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200125 # Assigning roles to user on project
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000126 self.client.assign_user_role(project['id'],
127 user['id'],
128 role['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530129 assigned_project_ids.append(project['id'])
David Kranze9d2f422014-07-02 13:57:41 -0400130 _, body = self.client.list_user_projects(user['id'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530131 for i in body:
132 fetched_project_ids.append(i['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200133 # verifying the project ids in list
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530134 missing_projects =\
135 [p for p in assigned_project_ids
136 if p not in fetched_project_ids]
137 self.assertEqual(0, len(missing_projects),
138 "Failed to find project %s in fetched list" %
139 ', '.join(m_project for m_project
DennyZhangb432bac2013-09-17 16:24:12 +0000140 in missing_projects))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530141
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400142 @test.attr(type='gate')
wanglianminb1ddea72014-02-25 17:17:30 +0800143 def test_get_user(self):
144 # Get a user detail
145 self.data.setup_test_v3_user()
David Kranze9d2f422014-07-02 13:57:41 -0400146 _, user = self.client.get_user(self.data.v3_user['id'])
wanglianminb1ddea72014-02-25 17:17:30 +0800147 self.assertEqual(self.data.v3_user['id'], user['id'])
148
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530149
150class UsersV3TestXML(UsersV3TestJSON):
151 _interface = 'xml'