blob: a4bf2630c06a9b7d50c04ec6a9d2f8d6ffc7aed3 [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
21from tempest import exceptions
Matthew Treinish5c660ab2014-05-18 21:14:36 -040022from tempest import test
huangtianhuab0993eb2013-09-30 18:07:15 +080023
24
Matthew Treinishdb2c5972014-01-31 22:18:59 +000025class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
huangtianhuab0993eb2013-09-30 18:07:15 +080026 _interface = 'json'
27
Matthew Treinish5c660ab2014-05-18 21:14:36 -040028 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +080029 def test_list_tenants_by_unauthorized_user(self):
30 # Non-administrator user should not be able to list tenants
Masayuki Igawa29d554f2015-01-20 12:36:42 +090031 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +080032 self.non_admin_client.list_tenants)
33
Matthew Treinish5c660ab2014-05-18 21:14:36 -040034 @test.attr(type=['negative', 'gate'])
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'])
huangtianhuab0993eb2013-09-30 18:07:15 +080043 def test_tenant_delete_by_unauthorized_user(self):
44 # Non-administrator user should not be able to delete a tenant
45 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050046 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +080047 self.data.tenants.append(tenant)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090048 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +080049 self.non_admin_client.delete_tenant, tenant['id'])
50
Matthew Treinish5c660ab2014-05-18 21:14:36 -040051 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +080052 def test_tenant_delete_request_without_token(self):
53 # Request to delete a tenant without a valid token should fail
54 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050055 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +080056 self.data.tenants.append(tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000057 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080058 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090059 self.assertRaises(lib_exc.Unauthorized, self.client.delete_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080060 tenant['id'])
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000061 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +080062
Matthew Treinish5c660ab2014-05-18 21:14:36 -040063 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +080064 def test_delete_non_existent_tenant(self):
65 # Attempt to delete a non existent tenant should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +090066 self.assertRaises(lib_exc.NotFound, self.client.delete_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080067 str(uuid.uuid4().hex))
68
Matthew Treinish5c660ab2014-05-18 21:14:36 -040069 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +080070 def test_tenant_create_duplicate(self):
71 # Tenant names should be unique
72 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -050073 body = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +080074 tenant = body
75 self.data.tenants.append(tenant)
76 tenant1_id = body.get('id')
77
78 self.addCleanup(self.client.delete_tenant, tenant1_id)
79 self.addCleanup(self.data.tenants.remove, tenant)
Masayuki Igawad9388762015-01-20 14:56:42 +090080 self.assertRaises(lib_exc.Conflict, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080081 tenant_name)
82
Matthew Treinish5c660ab2014-05-18 21:14:36 -040083 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +080084 def test_create_tenant_by_unauthorized_user(self):
85 # Non-administrator user should not be authorized to create a tenant
86 tenant_name = data_utils.rand_name(name='tenant-')
Masayuki Igawa29d554f2015-01-20 12:36:42 +090087 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +080088 self.non_admin_client.create_tenant, tenant_name)
89
Matthew Treinish5c660ab2014-05-18 21:14:36 -040090 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +080091 def test_create_tenant_request_without_token(self):
92 # Create tenant request without a token should not be authorized
93 tenant_name = data_utils.rand_name(name='tenant-')
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000094 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080095 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +090096 self.assertRaises(lib_exc.Unauthorized, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080097 tenant_name)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000098 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +080099
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400100 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +0800101 def test_create_tenant_with_empty_name(self):
102 # Tenant name should not be empty
103 self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
104 name='')
105
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400106 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +0800107 def test_create_tenants_name_length_over_64(self):
108 # Tenant name length should not be greater than 64 characters
109 tenant_name = 'a' * 65
110 self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
111 tenant_name)
112
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400113 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +0800114 def test_update_non_existent_tenant(self):
115 # Attempt to update a non existent tenant should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900116 self.assertRaises(lib_exc.NotFound, self.client.update_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800117 str(uuid.uuid4().hex))
118
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400119 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +0800120 def test_tenant_update_by_unauthorized_user(self):
121 # Non-administrator user should not be able to update a tenant
122 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -0500123 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +0800124 self.data.tenants.append(tenant)
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900125 self.assertRaises(lib_exc.Unauthorized,
huangtianhuab0993eb2013-09-30 18:07:15 +0800126 self.non_admin_client.update_tenant, tenant['id'])
127
Matthew Treinish5c660ab2014-05-18 21:14:36 -0400128 @test.attr(type=['negative', 'gate'])
huangtianhuab0993eb2013-09-30 18:07:15 +0800129 def test_tenant_update_request_without_token(self):
130 # Request to update a tenant without a valid token should fail
131 tenant_name = data_utils.rand_name(name='tenant-')
David Kranzb7afa922014-12-30 10:56:26 -0500132 tenant = self.client.create_tenant(tenant_name)
huangtianhuab0993eb2013-09-30 18:07:15 +0800133 self.data.tenants.append(tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000134 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +0800135 self.client.delete_token(token)
Masayuki Igawa29d554f2015-01-20 12:36:42 +0900136 self.assertRaises(lib_exc.Unauthorized, self.client.update_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +0800137 tenant['id'])
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000138 self.client.auth_provider.clear_auth()