blob: 8346a3dcb4eb399b61f3115a3ae24aba034a8392 [file] [log] [blame]
huangtianhuab0993eb2013-09-30 18:07:15 +08001# Copyright 2013 Huawei Technologies Co.,LTD.
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
Masayuki Igawad9388762015-01-20 14:56:42 +090016from tempest_lib import exceptions as lib_exc
huangtianhuab0993eb2013-09-30 18:07:15 +080017import uuid
18
19from tempest.api.identity import base
20from tempest.common.utils import data_utils
Matthew Treinish5c660ab2014-05-18 21:14:36 -040021from tempest import test
huangtianhuab0993eb2013-09-30 18:07:15 +080022
23
Matthew Treinishdb2c5972014-01-31 22:18:59 +000024class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
huangtianhuab0993eb2013-09-30 18:07:15 +080025
Matthew Treinish5c660ab2014-05-18 21:14:36 -040026 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080027 @test.idempotent_id('ca9bb202-63dd-4240-8a07-8ef9c19c04bb')
huangtianhuab0993eb2013-09-30 18:07:15 +080028 def test_list_tenants_by_unauthorized_user(self):
29 # Non-administrator user should not be able to list tenants
Masayuki Igawa29d554f2015-01-20 12:36:42 +090030 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +080031 self.non_admin_client.list_tenants)
32
Matthew Treinish5c660ab2014-05-18 21:14:36 -040033 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080034 @test.idempotent_id('df33926c-1c96-4d8d-a762-79cc6b0c3cf4')
huangtianhuab0993eb2013-09-30 18:07:15 +080035 def test_list_tenant_request_without_token(self):
36 # Request to list tenants without a valid token should fail
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000037 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080038 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090039 self.assertRaises(lib_exc.Unauthorized, self.client.list_tenants)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000040 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +080041
Matthew Treinish5c660ab2014-05-18 21:14:36 -040042 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080043 @test.idempotent_id('162ba316-f18b-4987-8c0c-fd9140cd63ed')
huangtianhuab0993eb2013-09-30 18:07:15 +080044 def test_tenant_delete_by_unauthorized_user(self):
45 # Non-administrator user should not be able to delete a tenant
46 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050047 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +080048 self.data.tenants.append(tenant)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090049 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +080050 self.non_admin_client.delete_tenant, tenant['id'])
51
Matthew Treinish5c660ab2014-05-18 21:14:36 -040052 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080053 @test.idempotent_id('e450db62-2e9d-418f-893a-54772d6386b1')
huangtianhuab0993eb2013-09-30 18:07:15 +080054 def test_tenant_delete_request_without_token(self):
55 # Request to delete a tenant without a valid token should fail
56 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050057 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +080058 self.data.tenants.append(tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000059 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080060 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090061 self.assertRaises(lib_exc.Unauthorized, self.client.delete_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080062 tenant['id'])
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000063 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +080064
Matthew Treinish5c660ab2014-05-18 21:14:36 -040065 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080066 @test.idempotent_id('9c9a2aed-6e3c-467a-8f5c-89da9d1b516b')
huangtianhuab0993eb2013-09-30 18:07:15 +080067 def test_delete_non_existent_tenant(self):
68 # Attempt to delete a non existent tenant should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +090069 self.assertRaises(lib_exc.NotFound, self.client.delete_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080070 str(uuid.uuid4().hex))
71
Matthew Treinish5c660ab2014-05-18 21:14:36 -040072 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080073 @test.idempotent_id('af16f44b-a849-46cb-9f13-a751c388f739')
huangtianhuab0993eb2013-09-30 18:07:15 +080074 def test_tenant_create_duplicate(self):
75 # Tenant names should be unique
76 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050077 body = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +080078 tenant = body
79 self.data.tenants.append(tenant)
80 tenant1_id = body.get('id')
81
82 self.addCleanup(self.client.delete_tenant, tenant1_id)
83 self.addCleanup(self.data.tenants.remove, tenant)
Masayuki Igawad9388762015-01-20 14:56:42 +090084 self.assertRaises(lib_exc.Conflict, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080085 tenant_name)
86
Matthew Treinish5c660ab2014-05-18 21:14:36 -040087 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080088 @test.idempotent_id('d26b278a-6389-4702-8d6e-5980d80137e0')
huangtianhuab0993eb2013-09-30 18:07:15 +080089 def test_create_tenant_by_unauthorized_user(self):
90 # Non-administrator user should not be authorized to create a tenant
91 tenant_name = data_utils.rand_name(name='tenant-')
Masayuki Igawa29d554f2015-01-20 12:36:42 +090092 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +080093 self.non_admin_client.create_tenant, tenant_name)
94
Matthew Treinish5c660ab2014-05-18 21:14:36 -040095 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('a3ee9d7e-6920-4dd5-9321-d4b2b7f0a638')
huangtianhuab0993eb2013-09-30 18:07:15 +080097 def test_create_tenant_request_without_token(self):
98 # Create tenant request without a token should not be authorized
99 tenant_name = data_utils.rand_name(name='tenant-')
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000100 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +0800101 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900102 self.assertRaises(lib_exc.Unauthorized, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800103 tenant_name)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000104 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +0800105
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400106 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('5a2e4ca9-b0c0-486c-9c48-64a94fba2395')
huangtianhuab0993eb2013-09-30 18:07:15 +0800108 def test_create_tenant_with_empty_name(self):
109 # Tenant name should not be empty
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900110 self.assertRaises(lib_exc.BadRequest, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800111 name='')
112
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400113 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800114 @test.idempotent_id('2ff18d1e-dfe3-4359-9dc3-abf582c196b9')
huangtianhuab0993eb2013-09-30 18:07:15 +0800115 def test_create_tenants_name_length_over_64(self):
116 # Tenant name length should not be greater than 64 characters
117 tenant_name = 'a' * 65
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900118 self.assertRaises(lib_exc.BadRequest, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800119 tenant_name)
120
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400121 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800122 @test.idempotent_id('bd20dc2a-9557-4db7-b755-f48d952ad706')
huangtianhuab0993eb2013-09-30 18:07:15 +0800123 def test_update_non_existent_tenant(self):
124 # Attempt to update a non existent tenant should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900125 self.assertRaises(lib_exc.NotFound, self.client.update_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800126 str(uuid.uuid4().hex))
127
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400128 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800129 @test.idempotent_id('41704dc5-c5f7-4f79-abfa-76e6fedc570b')
huangtianhuab0993eb2013-09-30 18:07:15 +0800130 def test_tenant_update_by_unauthorized_user(self):
131 # Non-administrator user should not be able to update a tenant
132 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -0500133 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +0800134 self.data.tenants.append(tenant)
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900135 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +0800136 self.non_admin_client.update_tenant, tenant['id'])
137
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400138 @test.attr(type=['negative', 'gate'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800139 @test.idempotent_id('7a421573-72c7-4c22-a98e-ce539219c657')
huangtianhuab0993eb2013-09-30 18:07:15 +0800140 def test_tenant_update_request_without_token(self):
141 # Request to update a tenant without a valid token should fail
142 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -0500143 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +0800144 self.data.tenants.append(tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000145 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +0800146 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900147 self.assertRaises(lib_exc.Unauthorized, self.client.update_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800148 tenant['id'])
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000149 self.client.auth_provider.clear_auth()