blob: 060f24a11efa3a525326091bf072662035ea893d [file] [log] [blame]
huangtianhuafc8db4f2013-10-08 12:05:58 +08001# Copyright 2012 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
16from tempest.api.identity import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
huangtianhuafc8db4f2013-10-08 12:05:58 +080018from tempest import exceptions
19from tempest.test import attr
20import uuid
21
22
23class UsersNegativeTestJSON(base.BaseIdentityAdminTest):
24 _interface = 'json'
25
26 @classmethod
27 def setUpClass(cls):
28 super(UsersNegativeTestJSON, cls).setUpClass()
Masayuki Igawa259c1132013-10-31 17:48:44 +090029 cls.alt_user = data_utils.rand_name('test_user_')
30 cls.alt_password = data_utils.rand_name('pass_')
huangtianhuafc8db4f2013-10-08 12:05:58 +080031 cls.alt_email = cls.alt_user + '@testmail.tm'
huangtianhuafc8db4f2013-10-08 12:05:58 +080032
33 @attr(type=['negative', 'gate'])
34 def test_create_user_by_unauthorized_user(self):
35 # Non-administrator should not be authorized to create a user
36 self.data.setup_test_tenant()
37 self.assertRaises(exceptions.Unauthorized,
38 self.non_admin_client.create_user, self.alt_user,
39 self.alt_password, self.data.tenant['id'],
40 self.alt_email)
41
42 @attr(type=['negative', 'gate'])
43 def test_create_user_with_empty_name(self):
44 # User with an empty name should not be created
45 self.data.setup_test_tenant()
46 self.assertRaises(exceptions.BadRequest, self.client.create_user, '',
47 self.alt_password, self.data.tenant['id'],
48 self.alt_email)
49
50 @attr(type=['negative', 'gate'])
51 def test_create_user_with_name_length_over_255(self):
52 # Length of user name filed should be restricted to 255 characters
53 self.data.setup_test_tenant()
54 self.assertRaises(exceptions.BadRequest, self.client.create_user,
55 'a' * 256, self.alt_password,
56 self.data.tenant['id'], self.alt_email)
57
58 @attr(type=['negative', 'gate'])
59 def test_create_user_with_duplicate_name(self):
60 # Duplicate user should not be created
61 self.data.setup_test_user()
Anju5c3e510c2013-10-18 06:40:29 +053062 self.assertRaises(exceptions.Conflict, self.client.create_user,
huangtianhuafc8db4f2013-10-08 12:05:58 +080063 self.data.test_user, self.data.test_password,
64 self.data.tenant['id'], self.data.test_email)
65
66 @attr(type=['negative', 'gate'])
nayna-patel179077c2014-01-15 12:27:16 +000067 def test_create_user_for_non_existent_tenant(self):
huangtianhuafc8db4f2013-10-08 12:05:58 +080068 # Attempt to create a user in a non-existent tenant should fail
69 self.assertRaises(exceptions.NotFound, self.client.create_user,
70 self.alt_user, self.alt_password, '49ffgg99999',
71 self.alt_email)
72
73 @attr(type=['negative', 'gate'])
74 def test_create_user_request_without_a_token(self):
75 # Request to create a user without a valid token should fail
76 self.data.setup_test_tenant()
77 # Get the token of the current client
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000078 token = self.client.auth_provider.get_token()
huangtianhuafc8db4f2013-10-08 12:05:58 +080079 # Delete the token from database
80 self.client.delete_token(token)
81 self.assertRaises(exceptions.Unauthorized, self.client.create_user,
82 self.alt_user, self.alt_password,
83 self.data.tenant['id'], self.alt_email)
84
85 # Unset the token to allow further tests to generate a new token
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000086 self.client.auth_provider.clear_auth()
huangtianhuafc8db4f2013-10-08 12:05:58 +080087
88 @attr(type=['negative', 'gate'])
89 def test_create_user_with_enabled_non_bool(self):
90 # Attempt to create a user with valid enabled para should fail
91 self.data.setup_test_tenant()
Masayuki Igawa259c1132013-10-31 17:48:44 +090092 name = data_utils.rand_name('test_user_')
huangtianhuafc8db4f2013-10-08 12:05:58 +080093 self.assertRaises(exceptions.BadRequest, self.client.create_user,
94 name, self.alt_password,
95 self.data.tenant['id'],
96 self.alt_email, enabled=3)
97
98 @attr(type=['negative', 'gate'])
nayna-patel179077c2014-01-15 12:27:16 +000099 def test_update_user_for_non_existent_user(self):
huangtianhuafc8db4f2013-10-08 12:05:58 +0800100 # Attempt to update a user non-existent user should fail
Masayuki Igawa259c1132013-10-31 17:48:44 +0900101 user_name = data_utils.rand_name('user-')
huangtianhuafc8db4f2013-10-08 12:05:58 +0800102 non_existent_id = str(uuid.uuid4())
103 self.assertRaises(exceptions.NotFound, self.client.update_user,
104 non_existent_id, name=user_name)
105
106 @attr(type=['negative', 'gate'])
107 def test_update_user_request_without_a_token(self):
108 # Request to update a user without a valid token should fail
109
110 # Get the token of the current client
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000111 token = self.client.auth_provider.get_token()
huangtianhuafc8db4f2013-10-08 12:05:58 +0800112 # Delete the token from database
113 self.client.delete_token(token)
114 self.assertRaises(exceptions.Unauthorized, self.client.update_user,
115 self.alt_user)
116
117 # Unset the token to allow further tests to generate a new token
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000118 self.client.auth_provider.clear_auth()
huangtianhuafc8db4f2013-10-08 12:05:58 +0800119
120 @attr(type=['negative', 'gate'])
121 def test_update_user_by_unauthorized_user(self):
122 # Non-administrator should not be authorized to update user
123 self.data.setup_test_tenant()
124 self.assertRaises(exceptions.Unauthorized,
125 self.non_admin_client.update_user, self.alt_user)
126
127 @attr(type=['negative', 'gate'])
128 def test_delete_users_by_unauthorized_user(self):
129 # Non-administrator user should not be authorized to delete a user
130 self.data.setup_test_user()
131 self.assertRaises(exceptions.Unauthorized,
132 self.non_admin_client.delete_user,
133 self.data.user['id'])
134
135 @attr(type=['negative', 'gate'])
nayna-patel179077c2014-01-15 12:27:16 +0000136 def test_delete_non_existent_user(self):
huangtianhuafc8db4f2013-10-08 12:05:58 +0800137 # Attempt to delete a non-existent user should fail
138 self.assertRaises(exceptions.NotFound, self.client.delete_user,
139 'junk12345123')
140
141 @attr(type=['negative', 'gate'])
142 def test_delete_user_request_without_a_token(self):
143 # Request to delete a user without a valid token should fail
144
145 # Get the token of the current client
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000146 token = self.client.auth_provider.get_token()
huangtianhuafc8db4f2013-10-08 12:05:58 +0800147 # Delete the token from database
148 self.client.delete_token(token)
149 self.assertRaises(exceptions.Unauthorized, self.client.delete_user,
150 self.alt_user)
151
152 # Unset the token to allow further tests to generate a new token
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000153 self.client.auth_provider.clear_auth()
huangtianhuafc8db4f2013-10-08 12:05:58 +0800154
155 @attr(type=['negative', 'gate'])
156 def test_authentication_for_disabled_user(self):
157 # Disabled user's token should not get authenticated
158 self.data.setup_test_user()
159 self.disable_user(self.data.test_user)
160 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
161 self.data.test_user,
162 self.data.test_password,
163 self.data.test_tenant)
164
165 @attr(type=['negative', 'gate'])
166 def test_authentication_when_tenant_is_disabled(self):
167 # User's token for a disabled tenant should not be authenticated
168 self.data.setup_test_user()
169 self.disable_tenant(self.data.test_tenant)
170 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
171 self.data.test_user,
172 self.data.test_password,
173 self.data.test_tenant)
174
175 @attr(type=['negative', 'gate'])
176 def test_authentication_with_invalid_tenant(self):
177 # User's token for an invalid tenant should not be authenticated
178 self.data.setup_test_user()
179 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
180 self.data.test_user,
181 self.data.test_password,
182 'junktenant1234')
183
184 @attr(type=['negative', 'gate'])
185 def test_authentication_with_invalid_username(self):
186 # Non-existent user's token should not get authenticated
187 self.data.setup_test_user()
188 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
189 'junkuser123', self.data.test_password,
190 self.data.test_tenant)
191
192 @attr(type=['negative', 'gate'])
193 def test_authentication_with_invalid_password(self):
194 # User's token with invalid password should not be authenticated
195 self.data.setup_test_user()
196 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
197 self.data.test_user, 'junkpass1234',
198 self.data.test_tenant)
199
200 @attr(type=['negative', 'gate'])
201 def test_get_users_by_unauthorized_user(self):
202 # Non-administrator user should not be authorized to get user list
203 self.data.setup_test_user()
204 self.assertRaises(exceptions.Unauthorized,
205 self.non_admin_client.get_users)
206
207 @attr(type=['negative', 'gate'])
208 def test_get_users_request_without_token(self):
209 # Request to get list of users without a valid token should fail
Andrea Frittoli77f9da42014-02-06 11:18:19 +0000210 token = self.client.auth_provider.get_token()
huangtianhuafc8db4f2013-10-08 12:05:58 +0800211 self.client.delete_token(token)
212 self.assertRaises(exceptions.Unauthorized, self.client.get_users)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000213 self.client.auth_provider.clear_auth()
huangtianhuafc8db4f2013-10-08 12:05:58 +0800214
215 @attr(type=['negative', 'gate'])
216 def test_list_users_with_invalid_tenant(self):
217 # Should not be able to return a list of all
218 # users for a non-existent tenant
219 # Assign invalid tenant ids
220 invalid_id = list()
Masayuki Igawa259c1132013-10-31 17:48:44 +0900221 invalid_id.append(data_utils.rand_name('999'))
huangtianhuafc8db4f2013-10-08 12:05:58 +0800222 invalid_id.append('alpha')
Masayuki Igawa259c1132013-10-31 17:48:44 +0900223 invalid_id.append(data_utils.rand_name("dddd@#%%^$"))
huangtianhuafc8db4f2013-10-08 12:05:58 +0800224 invalid_id.append('!@#()$%^&*?<>{}[]')
225 # List the users with invalid tenant id
226 for invalid in invalid_id:
227 self.assertRaises(exceptions.NotFound,
228 self.client.list_users_for_tenant, invalid)
229
230
231class UsersNegativeTestXML(UsersNegativeTestJSON):
232 _interface = 'xml'