blob: b29d155db2b561477fb12c5431945711950e29b5 [file] [log] [blame]
huangtianhuafc8db4f2013-10-08 12:05:58 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.api.identity import base
19from tempest.common.utils.data_utils import rand_name
20from tempest import exceptions
21from tempest.test import attr
22import uuid
23
24
25class UsersNegativeTestJSON(base.BaseIdentityAdminTest):
26 _interface = 'json'
27
28 @classmethod
29 def setUpClass(cls):
30 super(UsersNegativeTestJSON, cls).setUpClass()
31 cls.alt_user = rand_name('test_user_')
32 cls.alt_password = rand_name('pass_')
33 cls.alt_email = cls.alt_user + '@testmail.tm'
34 cls.alt_tenant = rand_name('test_tenant_')
35 cls.alt_description = rand_name('desc_')
36
37 @attr(type=['negative', 'gate'])
38 def test_create_user_by_unauthorized_user(self):
39 # Non-administrator should not be authorized to create a user
40 self.data.setup_test_tenant()
41 self.assertRaises(exceptions.Unauthorized,
42 self.non_admin_client.create_user, self.alt_user,
43 self.alt_password, self.data.tenant['id'],
44 self.alt_email)
45
46 @attr(type=['negative', 'gate'])
47 def test_create_user_with_empty_name(self):
48 # User with an empty name should not be created
49 self.data.setup_test_tenant()
50 self.assertRaises(exceptions.BadRequest, self.client.create_user, '',
51 self.alt_password, self.data.tenant['id'],
52 self.alt_email)
53
54 @attr(type=['negative', 'gate'])
55 def test_create_user_with_name_length_over_255(self):
56 # Length of user name filed should be restricted to 255 characters
57 self.data.setup_test_tenant()
58 self.assertRaises(exceptions.BadRequest, self.client.create_user,
59 'a' * 256, self.alt_password,
60 self.data.tenant['id'], self.alt_email)
61
62 @attr(type=['negative', 'gate'])
63 def test_create_user_with_duplicate_name(self):
64 # Duplicate user should not be created
65 self.data.setup_test_user()
Anju5c3e510c2013-10-18 06:40:29 +053066 self.assertRaises(exceptions.Conflict, self.client.create_user,
huangtianhuafc8db4f2013-10-08 12:05:58 +080067 self.data.test_user, self.data.test_password,
68 self.data.tenant['id'], self.data.test_email)
69
70 @attr(type=['negative', 'gate'])
71 def test_create_user_for_non_existant_tenant(self):
72 # Attempt to create a user in a non-existent tenant should fail
73 self.assertRaises(exceptions.NotFound, self.client.create_user,
74 self.alt_user, self.alt_password, '49ffgg99999',
75 self.alt_email)
76
77 @attr(type=['negative', 'gate'])
78 def test_create_user_request_without_a_token(self):
79 # Request to create a user without a valid token should fail
80 self.data.setup_test_tenant()
81 # Get the token of the current client
82 token = self.client.get_auth()
83 # Delete the token from database
84 self.client.delete_token(token)
85 self.assertRaises(exceptions.Unauthorized, self.client.create_user,
86 self.alt_user, self.alt_password,
87 self.data.tenant['id'], self.alt_email)
88
89 # Unset the token to allow further tests to generate a new token
90 self.client.clear_auth()
91
92 @attr(type=['negative', 'gate'])
93 def test_create_user_with_enabled_non_bool(self):
94 # Attempt to create a user with valid enabled para should fail
95 self.data.setup_test_tenant()
96 name = rand_name('test_user_')
97 self.assertRaises(exceptions.BadRequest, self.client.create_user,
98 name, self.alt_password,
99 self.data.tenant['id'],
100 self.alt_email, enabled=3)
101
102 @attr(type=['negative', 'gate'])
103 def test_update_user_for_non_existant_user(self):
104 # Attempt to update a user non-existent user should fail
105 user_name = rand_name('user-')
106 non_existent_id = str(uuid.uuid4())
107 self.assertRaises(exceptions.NotFound, self.client.update_user,
108 non_existent_id, name=user_name)
109
110 @attr(type=['negative', 'gate'])
111 def test_update_user_request_without_a_token(self):
112 # Request to update a user without a valid token should fail
113
114 # Get the token of the current client
115 token = self.client.get_auth()
116 # Delete the token from database
117 self.client.delete_token(token)
118 self.assertRaises(exceptions.Unauthorized, self.client.update_user,
119 self.alt_user)
120
121 # Unset the token to allow further tests to generate a new token
122 self.client.clear_auth()
123
124 @attr(type=['negative', 'gate'])
125 def test_update_user_by_unauthorized_user(self):
126 # Non-administrator should not be authorized to update user
127 self.data.setup_test_tenant()
128 self.assertRaises(exceptions.Unauthorized,
129 self.non_admin_client.update_user, self.alt_user)
130
131 @attr(type=['negative', 'gate'])
132 def test_delete_users_by_unauthorized_user(self):
133 # Non-administrator user should not be authorized to delete a user
134 self.data.setup_test_user()
135 self.assertRaises(exceptions.Unauthorized,
136 self.non_admin_client.delete_user,
137 self.data.user['id'])
138
139 @attr(type=['negative', 'gate'])
140 def test_delete_non_existant_user(self):
141 # Attempt to delete a non-existent user should fail
142 self.assertRaises(exceptions.NotFound, self.client.delete_user,
143 'junk12345123')
144
145 @attr(type=['negative', 'gate'])
146 def test_delete_user_request_without_a_token(self):
147 # Request to delete a user without a valid token should fail
148
149 # Get the token of the current client
150 token = self.client.get_auth()
151 # Delete the token from database
152 self.client.delete_token(token)
153 self.assertRaises(exceptions.Unauthorized, self.client.delete_user,
154 self.alt_user)
155
156 # Unset the token to allow further tests to generate a new token
157 self.client.clear_auth()
158
159 @attr(type=['negative', 'gate'])
160 def test_authentication_for_disabled_user(self):
161 # Disabled user's token should not get authenticated
162 self.data.setup_test_user()
163 self.disable_user(self.data.test_user)
164 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
165 self.data.test_user,
166 self.data.test_password,
167 self.data.test_tenant)
168
169 @attr(type=['negative', 'gate'])
170 def test_authentication_when_tenant_is_disabled(self):
171 # User's token for a disabled tenant should not be authenticated
172 self.data.setup_test_user()
173 self.disable_tenant(self.data.test_tenant)
174 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
175 self.data.test_user,
176 self.data.test_password,
177 self.data.test_tenant)
178
179 @attr(type=['negative', 'gate'])
180 def test_authentication_with_invalid_tenant(self):
181 # User's token for an invalid tenant should not be authenticated
182 self.data.setup_test_user()
183 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
184 self.data.test_user,
185 self.data.test_password,
186 'junktenant1234')
187
188 @attr(type=['negative', 'gate'])
189 def test_authentication_with_invalid_username(self):
190 # Non-existent user's token should not get authenticated
191 self.data.setup_test_user()
192 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
193 'junkuser123', self.data.test_password,
194 self.data.test_tenant)
195
196 @attr(type=['negative', 'gate'])
197 def test_authentication_with_invalid_password(self):
198 # User's token with invalid password should not be authenticated
199 self.data.setup_test_user()
200 self.assertRaises(exceptions.Unauthorized, self.token_client.auth,
201 self.data.test_user, 'junkpass1234',
202 self.data.test_tenant)
203
204 @attr(type=['negative', 'gate'])
205 def test_get_users_by_unauthorized_user(self):
206 # Non-administrator user should not be authorized to get user list
207 self.data.setup_test_user()
208 self.assertRaises(exceptions.Unauthorized,
209 self.non_admin_client.get_users)
210
211 @attr(type=['negative', 'gate'])
212 def test_get_users_request_without_token(self):
213 # Request to get list of users without a valid token should fail
214 token = self.client.get_auth()
215 self.client.delete_token(token)
216 self.assertRaises(exceptions.Unauthorized, self.client.get_users)
217 self.client.clear_auth()
218
219 @attr(type=['negative', 'gate'])
220 def test_list_users_with_invalid_tenant(self):
221 # Should not be able to return a list of all
222 # users for a non-existent tenant
223 # Assign invalid tenant ids
224 invalid_id = list()
225 invalid_id.append(rand_name('999'))
226 invalid_id.append('alpha')
227 invalid_id.append(rand_name("dddd@#%%^$"))
228 invalid_id.append('!@#()$%^&*?<>{}[]')
229 # List the users with invalid tenant id
230 for invalid in invalid_id:
231 self.assertRaises(exceptions.NotFound,
232 self.client.list_users_for_tenant, invalid)
233
234
235class UsersNegativeTestXML(UsersNegativeTestJSON):
236 _interface = 'xml'