blob: 486b7396496f1d95fb3f573144c772ae0c57d9a2 [file] [log] [blame]
Jay Pipesf38eaac2012-06-21 13:37:35 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipesf38eaac2012-06-21 13:37:35 -04004# 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
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.identity import base
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070019from tempest.common.utils.data_utils import rand_name
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020from tempest import exceptions
Chris Yeoh01cb2792013-02-09 22:25:37 +103021from tempest.test import attr
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070022
23
Attila Fazekas0d0c6162013-02-24 09:14:23 +010024class TenantsTestJSON(base.BaseIdentityAdminTest):
25 _interface = 'json'
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070026
Giampaolo Lauriaea294952013-05-15 08:52:04 -040027 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -070028 def test_list_tenants_by_unauthorized_user(self):
Chang Bo Guof099f802013-09-13 19:01:46 -070029 # Non-administrator user should not be able to list tenants
Rohit Karajgid2d3f792012-05-14 10:28:43 -070030 self.assertRaises(exceptions.Unauthorized,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080031 self.non_admin_client.list_tenants)
Rohit Karajgid2d3f792012-05-14 10:28:43 -070032
Giampaolo Lauriaea294952013-05-15 08:52:04 -040033 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -070034 def test_list_tenant_request_without_token(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050035 # Request to list tenants without a valid token should fail
Rohit Karajgid2d3f792012-05-14 10:28:43 -070036 token = self.client.get_auth()
37 self.client.delete_token(token)
38 self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
39 self.client.clear_auth()
40
Giampaolo Lauriaea294952013-05-15 08:52:04 -040041 @attr(type='gate')
Attila Fazekas40ec1232013-01-08 11:45:32 +010042 def test_tenant_list_delete(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050043 # Create several tenants and delete them
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070044 tenants = []
Attila Fazekas40ec1232013-01-08 11:45:32 +010045 for _ in xrange(3):
46 resp, tenant = self.client.create_tenant(rand_name('tenant-new'))
47 self.data.tenants.append(tenant)
48 tenants.append(tenant)
49 tenant_ids = map(lambda x: x['id'], tenants)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070050 resp, body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010051 self.assertTrue(resp['status'].startswith('2'))
52 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
53 self.assertEqual(len(found), len(tenants), 'Tenants not created')
54
55 for tenant in tenants:
56 resp, body = self.client.delete_tenant(tenant['id'])
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070057 self.assertTrue(resp['status'].startswith('2'))
Attila Fazekas40ec1232013-01-08 11:45:32 +010058 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070059
60 resp, body = self.client.list_tenants()
Attila Fazekas40ec1232013-01-08 11:45:32 +010061 found = [tenant for tenant in body if tenant['id'] in tenant_ids]
62 self.assertFalse(any(found), 'Tenants failed to delete')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070063
Giampaolo Lauriaea294952013-05-15 08:52:04 -040064 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -070065 def test_tenant_delete_by_unauthorized_user(self):
Chang Bo Guof099f802013-09-13 19:01:46 -070066 # Non-administrator user should not be able to delete a tenant
Rohit Karajgid2d3f792012-05-14 10:28:43 -070067 tenant_name = rand_name('tenant-')
68 resp, tenant = self.client.create_tenant(tenant_name)
Attila Fazekas40ec1232013-01-08 11:45:32 +010069 self.data.tenants.append(tenant)
Rohit Karajgid2d3f792012-05-14 10:28:43 -070070 self.assertRaises(exceptions.Unauthorized,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080071 self.non_admin_client.delete_tenant, tenant['id'])
Rohit Karajgid2d3f792012-05-14 10:28:43 -070072
Giampaolo Lauriaea294952013-05-15 08:52:04 -040073 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -070074 def test_tenant_delete_request_without_token(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050075 # Request to delete a tenant without a valid token should fail
Rohit Karajgid2d3f792012-05-14 10:28:43 -070076 tenant_name = rand_name('tenant-')
77 resp, tenant = self.client.create_tenant(tenant_name)
Attila Fazekas40ec1232013-01-08 11:45:32 +010078 self.data.tenants.append(tenant)
Rohit Karajgid2d3f792012-05-14 10:28:43 -070079 token = self.client.get_auth()
80 self.client.delete_token(token)
81 self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080082 tenant['id'])
Rohit Karajgid2d3f792012-05-14 10:28:43 -070083 self.client.clear_auth()
84
Giampaolo Lauriaea294952013-05-15 08:52:04 -040085 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -070086 def test_delete_non_existent_tenant(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050087 # Attempt to delete a non existent tenant should fail
Rohit Karajgid2d3f792012-05-14 10:28:43 -070088 self.assertRaises(exceptions.NotFound, self.client.delete_tenant,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080089 'junk_tenant_123456abc')
Rohit Karajgid2d3f792012-05-14 10:28:43 -070090
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040091 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070092 def test_tenant_create_with_description(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050093 # Create tenant with a description
chris fattarsi9ba7b0e2012-05-07 13:55:51 -070094 tenant_name = rand_name('tenant-')
95 tenant_desc = rand_name('desc-')
96 resp, body = self.client.create_tenant(tenant_name,
97 description=tenant_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +010098 tenant = body
99 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700100 st1 = resp['status']
101 tenant_id = body['id']
102 desc1 = body['description']
103 self.assertTrue(st1.startswith('2'))
104 self.assertEqual(desc1, tenant_desc, 'Description should have '
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800105 'been sent in response for create')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700106 resp, body = self.client.get_tenant(tenant_id)
107 desc2 = body['description']
108 self.assertEqual(desc2, tenant_desc, 'Description does not appear'
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800109 'to be set')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700110 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100111 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700112
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400113 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700114 def test_tenant_create_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500115 # Create a tenant that is enabled
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700116 tenant_name = rand_name('tenant-')
117 resp, body = self.client.create_tenant(tenant_name, enabled=True)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100118 tenant = body
119 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700120 tenant_id = body['id']
121 st1 = resp['status']
122 en1 = body['enabled']
123 self.assertTrue(st1.startswith('2'))
124 self.assertTrue(en1, 'Enable should be True in response')
125 resp, body = self.client.get_tenant(tenant_id)
126 en2 = body['enabled']
127 self.assertTrue(en2, 'Enable should be True in lookup')
128 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100129 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700130
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400131 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700132 def test_tenant_create_not_enabled(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500133 # Create a tenant that is not enabled
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700134 tenant_name = rand_name('tenant-')
135 resp, body = self.client.create_tenant(tenant_name, enabled=False)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100136 tenant = body
137 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700138 tenant_id = body['id']
139 st1 = resp['status']
140 en1 = body['enabled']
141 self.assertTrue(st1.startswith('2'))
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800142 self.assertEqual('false', str(en1).lower(),
143 'Enable should be False in response')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700144 resp, body = self.client.get_tenant(tenant_id)
145 en2 = body['enabled']
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800146 self.assertEqual('false', str(en2).lower(),
147 'Enable should be False in lookup')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700148 self.client.delete_tenant(tenant_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100149 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700150
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400151 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700152 def test_tenant_create_duplicate(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500153 # Tenant names should be unique
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700154 tenant_name = rand_name('tenant-dup-')
155 resp, body = self.client.create_tenant(tenant_name)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100156 tenant = body
157 self.data.tenants.append(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700158 tenant1_id = body.get('id')
159
Chris Yeohe04628e2013-02-25 17:12:21 +1030160 self.addCleanup(self.client.delete_tenant, tenant1_id)
161 self.addCleanup(self.data.tenants.remove, tenant)
162 self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
163 tenant_name)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700164
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400165 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700166 def test_create_tenant_by_unauthorized_user(self):
Chang Bo Guof099f802013-09-13 19:01:46 -0700167 # Non-administrator user should not be authorized to create a tenant
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700168 tenant_name = rand_name('tenant-')
169 self.assertRaises(exceptions.Unauthorized,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800170 self.non_admin_client.create_tenant, tenant_name)
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700171
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400172 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700173 def test_create_tenant_request_without_token(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500174 # Create tenant request without a token should not be authorized
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700175 tenant_name = rand_name('tenant-')
176 token = self.client.get_auth()
177 self.client.delete_token(token)
178 self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800179 tenant_name)
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700180 self.client.clear_auth()
181
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400182 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700183 def test_create_tenant_with_empty_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500184 # Tenant name should not be empty
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700185 self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
186 name='')
187
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400188 @attr(type='gate')
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700189 def test_create_tenants_name_length_over_64(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500190 # Tenant name length should not be greater than 64 characters
David Kranz28e35c52012-07-10 10:14:38 -0400191 tenant_name = 'a' * 65
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700192 self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800193 tenant_name)
Rohit Karajgid2d3f792012-05-14 10:28:43 -0700194
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400195 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700196 def test_tenant_update_name(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500197 # Update name attribute of a tenant
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700198 t_name1 = rand_name('tenant-')
199 resp, body = self.client.create_tenant(t_name1)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100200 tenant = body
201 self.data.tenants.append(tenant)
202
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700203 t_id = body['id']
204 resp1_name = body['name']
205
206 t_name2 = rand_name('tenant2-')
207 resp, body = self.client.update_tenant(t_id, name=t_name2)
208 st2 = resp['status']
209 resp2_name = body['name']
210 self.assertTrue(st2.startswith('2'))
211 self.assertNotEqual(resp1_name, resp2_name)
212
213 resp, body = self.client.get_tenant(t_id)
214 resp3_name = body['name']
215
216 self.assertNotEqual(resp1_name, resp3_name)
217 self.assertEqual(t_name1, resp1_name)
218 self.assertEqual(resp2_name, resp3_name)
219
220 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100221 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700222
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400223 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700224 def test_tenant_update_desc(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500225 # Update description attribute of a tenant
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700226 t_name = rand_name('tenant-')
227 t_desc = rand_name('desc-')
228 resp, body = self.client.create_tenant(t_name, description=t_desc)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100229 tenant = body
230 self.data.tenants.append(tenant)
231
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700232 t_id = body['id']
233 resp1_desc = body['description']
234
235 t_desc2 = rand_name('desc2-')
236 resp, body = self.client.update_tenant(t_id, description=t_desc2)
237 st2 = resp['status']
Gordon Chungad873602013-02-18 19:26:27 -0500238 resp2_desc = body['description']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700239 self.assertTrue(st2.startswith('2'))
240 self.assertNotEqual(resp1_desc, resp2_desc)
241
242 resp, body = self.client.get_tenant(t_id)
243 resp3_desc = body['description']
244
245 self.assertNotEqual(resp1_desc, resp3_desc)
246 self.assertEqual(t_desc, resp1_desc)
247 self.assertEqual(resp2_desc, resp3_desc)
248
249 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100250 self.data.tenants.remove(tenant)
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700251
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400252 @attr(type='gate')
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700253 def test_tenant_update_enable(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500254 # Update the enabled attribute of a tenant
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700255 t_name = rand_name('tenant-')
256 t_en = False
257 resp, body = self.client.create_tenant(t_name, enabled=t_en)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100258 tenant = body
259 self.data.tenants.append(tenant)
260
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700261 t_id = body['id']
262 resp1_en = body['enabled']
263
264 t_en2 = True
265 resp, body = self.client.update_tenant(t_id, enabled=t_en2)
266 st2 = resp['status']
Gordon Chungad873602013-02-18 19:26:27 -0500267 resp2_en = body['enabled']
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700268 self.assertTrue(st2.startswith('2'))
269 self.assertNotEqual(resp1_en, resp2_en)
270
271 resp, body = self.client.get_tenant(t_id)
272 resp3_en = body['enabled']
273
274 self.assertNotEqual(resp1_en, resp3_en)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800275 self.assertEqual('false', str(resp1_en).lower())
chris fattarsi9ba7b0e2012-05-07 13:55:51 -0700276 self.assertEqual(resp2_en, resp3_en)
277
278 self.client.delete_tenant(t_id)
Attila Fazekas40ec1232013-01-08 11:45:32 +0100279 self.data.tenants.remove(tenant)
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800280
281
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100282class TenantsTestXML(TenantsTestJSON):
283 _interface = 'xml'