blob: 44b54b821eeee5eaf84f5bfb62b6db379aff0a09 [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
16import uuid
17
18from tempest.api.identity import base
19from tempest.common.utils import data_utils
20from tempest import exceptions
21from tempest.test import attr
22
23
Matthew Treinishdb2c5972014-01-31 22:18:59 +000024class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
huangtianhuab0993eb2013-09-30 18:07:15 +080025 _interface = 'json'
26
27 @attr(type=['negative', 'gate'])
28 def test_list_tenants_by_unauthorized_user(self):
29 # Non-administrator user should not be able to list tenants
30 self.assertRaises(exceptions.Unauthorized,
31 self.non_admin_client.list_tenants)
32
33 @attr(type=['negative', 'gate'])
34 def test_list_tenant_request_without_token(self):
35 # Request to list tenants without a valid token should fail
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000036 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080037 self.client.delete_token(token)
38 self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000039 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +080040
41 @attr(type=['negative', 'gate'])
42 def test_tenant_delete_by_unauthorized_user(self):
43 # Non-administrator user should not be able to delete a tenant
44 tenant_name = data_utils.rand_name(name='tenant-')
45 resp, tenant = self.client.create_tenant(tenant_name)
46 self.assertEqual(200, resp.status)
47 self.data.tenants.append(tenant)
48 self.assertRaises(exceptions.Unauthorized,
49 self.non_admin_client.delete_tenant, tenant['id'])
50
51 @attr(type=['negative', 'gate'])
52 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-')
55 resp, tenant = self.client.create_tenant(tenant_name)
56 self.assertEqual(200, resp.status)
57 self.data.tenants.append(tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000058 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080059 self.client.delete_token(token)
60 self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
61 tenant['id'])
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000062 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +080063
64 @attr(type=['negative', 'gate'])
65 def test_delete_non_existent_tenant(self):
66 # Attempt to delete a non existent tenant should fail
67 self.assertRaises(exceptions.NotFound, self.client.delete_tenant,
68 str(uuid.uuid4().hex))
69
70 @attr(type=['negative', 'gate'])
71 def test_tenant_create_duplicate(self):
72 # Tenant names should be unique
73 tenant_name = data_utils.rand_name(name='tenant-')
74 resp, body = self.client.create_tenant(tenant_name)
75 self.assertEqual(200, resp.status)
76 tenant = body
77 self.data.tenants.append(tenant)
78 tenant1_id = body.get('id')
79
80 self.addCleanup(self.client.delete_tenant, tenant1_id)
81 self.addCleanup(self.data.tenants.remove, tenant)
Anju5c3e510c2013-10-18 06:40:29 +053082 self.assertRaises(exceptions.Conflict, self.client.create_tenant,
huangtianhuab0993eb2013-09-30 18:07:15 +080083 tenant_name)
84
85 @attr(type=['negative', 'gate'])
86 def test_create_tenant_by_unauthorized_user(self):
87 # Non-administrator user should not be authorized to create a tenant
88 tenant_name = data_utils.rand_name(name='tenant-')
89 self.assertRaises(exceptions.Unauthorized,
90 self.non_admin_client.create_tenant, tenant_name)
91
92 @attr(type=['negative', 'gate'])
93 def test_create_tenant_request_without_token(self):
94 # Create tenant request without a token should not be authorized
95 tenant_name = data_utils.rand_name(name='tenant-')
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000096 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +080097 self.client.delete_token(token)
98 self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
99 tenant_name)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000100 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +0800101
102 @attr(type=['negative', 'gate'])
103 def test_create_tenant_with_empty_name(self):
104 # Tenant name should not be empty
105 self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
106 name='')
107
108 @attr(type=['negative', 'gate'])
109 def test_create_tenants_name_length_over_64(self):
110 # Tenant name length should not be greater than 64 characters
111 tenant_name = 'a' * 65
112 self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
113 tenant_name)
114
115 @attr(type=['negative', 'gate'])
116 def test_update_non_existent_tenant(self):
117 # Attempt to update a non existent tenant should fail
118 self.assertRaises(exceptions.NotFound, self.client.update_tenant,
119 str(uuid.uuid4().hex))
120
121 @attr(type=['negative', 'gate'])
122 def test_tenant_update_by_unauthorized_user(self):
123 # Non-administrator user should not be able to update a tenant
124 tenant_name = data_utils.rand_name(name='tenant-')
125 resp, tenant = self.client.create_tenant(tenant_name)
126 self.assertEqual(200, resp.status)
127 self.data.tenants.append(tenant)
128 self.assertRaises(exceptions.Unauthorized,
129 self.non_admin_client.update_tenant, tenant['id'])
130
131 @attr(type=['negative', 'gate'])
132 def test_tenant_update_request_without_token(self):
133 # Request to update a tenant without a valid token should fail
134 tenant_name = data_utils.rand_name(name='tenant-')
135 resp, tenant = self.client.create_tenant(tenant_name)
136 self.assertEqual(200, resp.status)
137 self.data.tenants.append(tenant)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000138 token = self.client.auth_provider.get_token()
huangtianhuab0993eb2013-09-30 18:07:15 +0800139 self.client.delete_token(token)
140 self.assertRaises(exceptions.Unauthorized, self.client.update_tenant,
141 tenant['id'])
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000142 self.client.auth_provider.clear_auth()
huangtianhuab0993eb2013-09-30 18:07:15 +0800143
144
145class TenantsNegativeTestXML(TenantsNegativeTestJSON):
146 _interface = 'xml'