huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 1 | # 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 Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 16 | from tempest_lib import exceptions as lib_exc |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 17 | import uuid |
| 18 | |
| 19 | from tempest.api.identity import base |
| 20 | from tempest.common.utils import data_utils |
| 21 | from tempest import exceptions |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 22 | from tempest import test |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 23 | |
| 24 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 25 | class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest): |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 26 | _interface = 'json' |
| 27 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 28 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 29 | def test_list_tenants_by_unauthorized_user(self): |
| 30 | # Non-administrator user should not be able to list tenants |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 31 | self.assertRaises(lib_exc.Unauthorized, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 32 | self.non_admin_client.list_tenants) |
| 33 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 34 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 35 | def test_list_tenant_request_without_token(self): |
| 36 | # Request to list tenants without a valid token should fail |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 37 | token = self.client.auth_provider.get_token() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 38 | self.client.delete_token(token) |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 39 | self.assertRaises(lib_exc.Unauthorized, self.client.list_tenants) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 40 | self.client.auth_provider.clear_auth() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 41 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 42 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 43 | 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 Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 46 | tenant = self.client.create_tenant(tenant_name) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 47 | self.data.tenants.append(tenant) |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 48 | self.assertRaises(lib_exc.Unauthorized, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 49 | self.non_admin_client.delete_tenant, tenant['id']) |
| 50 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 51 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 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-') |
David Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 55 | tenant = self.client.create_tenant(tenant_name) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 56 | self.data.tenants.append(tenant) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 57 | token = self.client.auth_provider.get_token() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 58 | self.client.delete_token(token) |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 59 | self.assertRaises(lib_exc.Unauthorized, self.client.delete_tenant, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 60 | tenant['id']) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 61 | self.client.auth_provider.clear_auth() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 62 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 63 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 64 | def test_delete_non_existent_tenant(self): |
| 65 | # Attempt to delete a non existent tenant should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 66 | self.assertRaises(lib_exc.NotFound, self.client.delete_tenant, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 67 | str(uuid.uuid4().hex)) |
| 68 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 69 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 70 | def test_tenant_create_duplicate(self): |
| 71 | # Tenant names should be unique |
| 72 | tenant_name = data_utils.rand_name(name='tenant-') |
David Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 73 | body = self.client.create_tenant(tenant_name) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 74 | 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 Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 80 | self.assertRaises(lib_exc.Conflict, self.client.create_tenant, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 81 | tenant_name) |
| 82 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 83 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 84 | 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 Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 87 | self.assertRaises(lib_exc.Unauthorized, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 88 | self.non_admin_client.create_tenant, tenant_name) |
| 89 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 90 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 91 | 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 Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 94 | token = self.client.auth_provider.get_token() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 95 | self.client.delete_token(token) |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 96 | self.assertRaises(lib_exc.Unauthorized, self.client.create_tenant, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 97 | tenant_name) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 98 | self.client.auth_provider.clear_auth() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 99 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 100 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 101 | 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 Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 106 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 107 | 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 Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 113 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 114 | def test_update_non_existent_tenant(self): |
| 115 | # Attempt to update a non existent tenant should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 116 | self.assertRaises(lib_exc.NotFound, self.client.update_tenant, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 117 | str(uuid.uuid4().hex)) |
| 118 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 119 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 120 | 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 Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 123 | tenant = self.client.create_tenant(tenant_name) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 124 | self.data.tenants.append(tenant) |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 125 | self.assertRaises(lib_exc.Unauthorized, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 126 | self.non_admin_client.update_tenant, tenant['id']) |
| 127 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 128 | @test.attr(type=['negative', 'gate']) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 129 | 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 Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 132 | tenant = self.client.create_tenant(tenant_name) |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 133 | self.data.tenants.append(tenant) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 134 | token = self.client.auth_provider.get_token() |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 135 | self.client.delete_token(token) |
Masayuki Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame^] | 136 | self.assertRaises(lib_exc.Unauthorized, self.client.update_tenant, |
huangtianhua | b0993eb | 2013-09-30 18:07:15 +0800 | [diff] [blame] | 137 | tenant['id']) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 138 | self.client.auth_provider.clear_auth() |