blob: 2dbe1234f1d01176867708c168aac18f2ae292ba [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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.
Daryl Walleckced8eb82012-03-19 13:52:37 -050015
Adam Gandelman85f5bed2014-06-19 16:48:17 -070016import StringIO
17
Masayuki Igawabfa07602015-01-20 18:47:17 +090018from tempest_lib import exceptions as lib_exc
19
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.compute import base
Matthew Treinish481466b2012-12-20 17:16:01 -050021from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090022from tempest.common.utils import data_utils
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000023from tempest import config
Giulio Fidente92f77192013-08-26 17:13:28 +020024from tempest.openstack.common import log as logging
Yuiko Takadae9999d62014-03-06 09:22:54 +000025from tempest import test
Daryl Walleckced8eb82012-03-19 13:52:37 -050026
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000027CONF = config.CONF
28
Giulio Fidente92f77192013-08-26 17:13:28 +020029LOG = logging.getLogger(__name__)
30
Daryl Walleckced8eb82012-03-19 13:52:37 -050031
ivan-zhuf2b00502013-10-18 10:06:52 +080032class AuthorizationTestJSON(base.BaseV2ComputeTest):
Emily Hugenbruche7991d92014-12-12 16:53:36 +000033
Daryl Walleckced8eb82012-03-19 13:52:37 -050034 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000035 def skip_checks(cls):
36 super(AuthorizationTestJSON, cls).skip_checks()
Adam Gandelman85f5bed2014-06-19 16:48:17 -070037 if not CONF.service_available.glance:
38 raise cls.skipException('Glance is not available.')
Emily Hugenbruche7991d92014-12-12 16:53:36 +000039
40 @classmethod
41 def setup_credentials(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000042 # No network resources required for this test
43 cls.set_network_resources()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000044 super(AuthorizationTestJSON, cls).setup_credentials()
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000045 if not cls.multi_user:
Jay Pipesf38eaac2012-06-21 13:37:35 -040046 msg = "Need >1 user"
ivan-zhu1feeb382013-01-24 10:14:39 +080047 raise cls.skipException(msg)
Emily Hugenbruche7991d92014-12-12 16:53:36 +000048
49 creds = cls.isolated_creds.get_alt_creds()
50 cls.alt_manager = clients.Manager(credentials=creds)
51
52 @classmethod
53 def setup_clients(cls):
54 super(AuthorizationTestJSON, cls).setup_clients()
Daryl Walleckced8eb82012-03-19 13:52:37 -050055 cls.client = cls.os.servers_client
56 cls.images_client = cls.os.images_client
Adam Gandelman85f5bed2014-06-19 16:48:17 -070057 cls.glance_client = cls.os.image_client
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053058 cls.keypairs_client = cls.os.keypairs_client
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053059 cls.security_client = cls.os.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050060
Jay Pipesf38eaac2012-06-21 13:37:35 -040061 cls.alt_client = cls.alt_manager.servers_client
62 cls.alt_images_client = cls.alt_manager.images_client
63 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
64 cls.alt_security_client = cls.alt_manager.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050065
Emily Hugenbruche7991d92014-12-12 16:53:36 +000066 @classmethod
67 def resource_setup(cls):
68 super(AuthorizationTestJSON, cls).resource_setup()
David Kranz0fb14292015-02-11 15:55:20 -050069 server = cls.create_test_server(wait_until='ACTIVE')
70 cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040071
Masayuki Igawa259c1132013-10-31 17:48:44 +090072 name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -050073 body = cls.glance_client.create_image(name=name,
74 container_format='bare',
75 disk_format='raw',
76 is_public=False)
Adam Gandelman85f5bed2014-06-19 16:48:17 -070077 image_id = body['id']
78 image_file = StringIO.StringIO(('*' * 1024))
David Kranz34f18782015-01-06 13:43:55 -050079 body = cls.glance_client.update_image(image_id, data=image_file)
Adam Gandelman85f5bed2014-06-19 16:48:17 -070080 cls.glance_client.wait_for_image_status(image_id, 'active')
David Kranza5299eb2015-01-15 17:24:05 -050081 cls.image = cls.images_client.get_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050082
Masayuki Igawa259c1132013-10-31 17:48:44 +090083 cls.keypairname = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050084 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050085
Masayuki Igawa259c1132013-10-31 17:48:44 +090086 name = data_utils.rand_name('security')
87 description = data_utils.rand_name('description')
David Kranz9964b4e2015-02-06 15:45:29 -050088 cls.security_group = cls.security_client.create_security_group(
nayna-pateleda1d122013-03-20 14:44:31 +000089 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053090
Jay Pipesf38eaac2012-06-21 13:37:35 -040091 parent_group_id = cls.security_group['id']
92 ip_protocol = 'tcp'
93 from_port = 22
94 to_port = 22
David Kranz9964b4e2015-02-06 15:45:29 -050095 cls.rule = cls.security_client.create_security_group_rule(
nayna-pateleda1d122013-03-20 14:44:31 +000096 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053097
Daryl Walleckced8eb82012-03-19 13:52:37 -050098 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010099 def resource_cleanup(cls):
Matthew Treinishf7fca6a2013-12-09 16:27:23 +0000100 if cls.multi_user:
Daryl Walleckced8eb82012-03-19 13:52:37 -0500101 cls.images_client.delete_image(cls.image['id'])
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530102 cls.keypairs_client.delete_keypair(cls.keypairname)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530103 cls.security_client.delete_security_group(cls.security_group['id'])
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100104 super(AuthorizationTestJSON, cls).resource_cleanup()
Daryl Walleckced8eb82012-03-19 13:52:37 -0500105
Yuiko Takadae9999d62014-03-06 09:22:54 +0000106 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('56816e4a-bd34-47b5-aee9-268c3efeb5d4')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400108 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500109 # A GET request for a server on another user's account should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900110 self.assertRaises(lib_exc.NotFound, self.alt_client.get_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030111 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500112
Yuiko Takadae9999d62014-03-06 09:22:54 +0000113 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800114 @test.idempotent_id('fb8a4870-6d9d-44ad-8375-95d52e98d9f6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400115 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500116 # A DELETE request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900117 self.assertRaises(lib_exc.NotFound, self.alt_client.delete_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030118 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500119
Yuiko Takadae9999d62014-03-06 09:22:54 +0000120 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800121 @test.idempotent_id('d792f91f-1d49-4eb5-b1ff-b229c4b9dc64')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400122 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500123 # An update server request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900124 self.assertRaises(lib_exc.NotFound, self.alt_client.update_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030125 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500126
Yuiko Takadae9999d62014-03-06 09:22:54 +0000127 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800128 @test.idempotent_id('488f24df-d7f7-4207-949a-f17fcb8e8769')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400129 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500130 # A list addresses request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900131 self.assertRaises(lib_exc.NotFound, self.alt_client.list_addresses,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030132 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500133
Yuiko Takadae9999d62014-03-06 09:22:54 +0000134 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800135 @test.idempotent_id('00b442d0-2e72-40e7-9b1f-31772e36da01')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400136 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500137 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500138 server_id = self.server['id']
Masayuki Igawabfa07602015-01-20 18:47:17 +0900139 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030140 self.alt_client.list_addresses_by_network, server_id,
141 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500142
Yuiko Takadae9999d62014-03-06 09:22:54 +0000143 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800144 @test.idempotent_id('cc90b35a-19f0-45d2-b680-2aabf934aa22')
sapan-kona37939762012-06-28 20:22:43 +0530145 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500146 # A list on servers from one tenant should not
147 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200148 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530149 alt_server_ids = []
David Kranzae99b9a2015-02-16 13:37:01 -0500150 body = self.alt_client.list_servers()
sapan-kona37939762012-06-28 20:22:43 +0530151 alt_server_ids = [s['id'] for s in body['servers']]
152 self.assertNotIn(self.server['id'], alt_server_ids)
153
Yuiko Takadae9999d62014-03-06 09:22:54 +0000154 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800155 @test.idempotent_id('376dbc16-0779-4384-a723-752774799641')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400156 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500157 # A change password request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900158 self.assertRaises(lib_exc.NotFound, self.alt_client.change_password,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030159 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500160
Yuiko Takadae9999d62014-03-06 09:22:54 +0000161 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800162 @test.idempotent_id('14cb5ff5-f646-45ca-8f51-09081d6c0c24')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400163 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500164 # A reboot request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900165 self.assertRaises(lib_exc.NotFound, self.alt_client.reboot,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030166 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500167
Yuiko Takadae9999d62014-03-06 09:22:54 +0000168 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800169 @test.idempotent_id('8a0bce51-cd00-480b-88ba-dbc7d8408a37')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400170 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500171 # A rebuild request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900172 self.assertRaises(lib_exc.NotFound, self.alt_client.rebuild,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030173 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500174
Yuiko Takadae9999d62014-03-06 09:22:54 +0000175 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800176 @test.idempotent_id('e4da647e-f982-4e61-9dad-1d1abebfb933')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400177 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500178 # A resize request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900179 self.assertRaises(lib_exc.NotFound, self.alt_client.resize,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030180 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500181
Yuiko Takadae9999d62014-03-06 09:22:54 +0000182 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800183 @test.idempotent_id('a9fe8112-0ffa-4902-b061-f892bd5fe0d3')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400184 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500185 # A create image request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900186 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030187 self.alt_images_client.create_image,
188 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500189
Yuiko Takadae9999d62014-03-06 09:22:54 +0000190 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800191 @test.idempotent_id('95d445f6-babc-4f2e-aea3-aa24ec5e7f0d')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500192 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500193 # Server creation with another user's image should fail
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900194 self.assertRaises(lib_exc.BadRequest, self.alt_client.create_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030195 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500196
Yuiko Takadae9999d62014-03-06 09:22:54 +0000197 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800198 @test.idempotent_id('acf8724b-142b-4044-82c3-78d31a533f24')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500199 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500200 # A create server request should fail if the tenant id does not match
201 # the current user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000202 # Change the base URL to impersonate another user
203 self.alt_client.auth_provider.set_alt_auth_data(
204 request_part='url',
205 auth_data=self.client.auth_provider.auth_data
206 )
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900207 self.assertRaises(lib_exc.BadRequest,
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000208 self.alt_client.create_server, 'test',
209 self.image['id'], self.flavor_ref)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530210
Yuiko Takadae9999d62014-03-06 09:22:54 +0000211 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800212 @test.idempotent_id('f03d1ded-7fd4-4d29-bc13-e2391f29c625')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400213 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500214 # A create keypair request should fail if the tenant id does not match
215 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200216 # POST keypair with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900217 k_name = data_utils.rand_name('keypair-')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530218 try:
219 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000220 self.alt_keypairs_client.auth_provider.set_alt_auth_data(
221 request_part='url',
222 auth_data=self.keypairs_client.auth_provider.auth_data
223 )
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530224 resp = {}
225 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900226 self.assertRaises(lib_exc.BadRequest,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030227 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530228 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000229 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800230 if (resp['status'] is not None):
David Kranz173f0e02015-02-06 13:47:57 -0500231 self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200232 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800233 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530234
Yuiko Takadae9999d62014-03-06 09:22:54 +0000235 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800236 @test.idempotent_id('85bcdd8f-56b4-4868-ae56-63fbf6f7e405')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400237 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500238 # A GET request for another user's keypair should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900239 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030240 self.alt_keypairs_client.get_keypair,
241 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530242
Yuiko Takadae9999d62014-03-06 09:22:54 +0000243 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800244 @test.idempotent_id('6d841683-a8e0-43da-a1b8-b339f7692b61')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400245 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500246 # A DELETE request for another user's keypair should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900247 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030248 self.alt_keypairs_client.delete_keypair,
249 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530250
Yuiko Takadae9999d62014-03-06 09:22:54 +0000251 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800252 @test.idempotent_id('fcb2e144-36e3-4dfb-9f9f-e72fcdec5656')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400253 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500254 # A GET request for an image on another user's account should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900255 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030256 self.alt_images_client.get_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530257
Yuiko Takadae9999d62014-03-06 09:22:54 +0000258 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800259 @test.idempotent_id('9facb962-f043-4a9d-b9ee-166a32dea098')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400260 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500261 # A DELETE request for another user's image should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900262 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030263 self.alt_images_client.delete_image,
264 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530265
Yuiko Takadae9999d62014-03-06 09:22:54 +0000266 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800267 @test.idempotent_id('752c917e-83be-499d-a422-3559127f7d3c')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400268 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500269 # A create security group request should fail if the tenant id does not
270 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200271 # POST security group with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900272 s_name = data_utils.rand_name('security-')
273 s_description = data_utils.rand_name('security')
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530274 try:
275 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000276 self.alt_security_client.auth_provider.set_alt_auth_data(
277 request_part='url',
278 auth_data=self.security_client.auth_provider.auth_data
279 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530280 resp = {}
281 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900282 self.assertRaises(lib_exc.BadRequest,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030283 self.alt_security_client.create_security_group,
284 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530285 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000286 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800287 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700288 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200289 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530290 "the tenant id does not match the current user")
291
Yuiko Takadae9999d62014-03-06 09:22:54 +0000292 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800293 @test.idempotent_id('9db3590f-4d15-4e5f-985e-b28514919a6f')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400294 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500295 # A GET request for another user's security group should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900296 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030297 self.alt_security_client.get_security_group,
298 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530299
Yuiko Takadae9999d62014-03-06 09:22:54 +0000300 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800301 @test.idempotent_id('155387a5-2bbc-4acf-ab06-698dae537ea5')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400302 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500303 # A DELETE request for another user's security group should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900304 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030305 self.alt_security_client.delete_security_group,
306 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530307
Yuiko Takadae9999d62014-03-06 09:22:54 +0000308 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800309 @test.idempotent_id('b2b76de0-210a-4089-b921-591c9ec552f6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400310 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500311 # A create security group rule request should fail if the tenant id
312 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200313 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530314 parent_group_id = self.security_group['id']
315 ip_protocol = 'icmp'
316 from_port = -1
317 to_port = -1
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530318 try:
319 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000320 self.alt_security_client.auth_provider.set_alt_auth_data(
321 request_part='url',
322 auth_data=self.security_client.auth_provider.auth_data
323 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530324 resp = {}
325 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900326 self.assertRaises(lib_exc.BadRequest,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030327 self.alt_security_client.
328 create_security_group_rule,
329 parent_group_id, ip_protocol, from_port,
330 to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530331 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000332 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800333 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700334 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200335 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530336 "happen if the tenant id does not match the"
337 " current user")
338
Yuiko Takadae9999d62014-03-06 09:22:54 +0000339 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800340 @test.idempotent_id('c6044177-37ef-4ce4-b12c-270ddf26d7da')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400341 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500342 # A DELETE request for another user's security group rule
343 # should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900344 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030345 self.alt_security_client.delete_security_group_rule,
346 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530347
Yuiko Takadae9999d62014-03-06 09:22:54 +0000348 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800349 @test.idempotent_id('c5f52351-53d9-4fc9-83e5-917f7f5e3d71')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400350 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500351 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530352 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Masayuki Igawabfa07602015-01-20 18:47:17 +0900353 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030354 self.alt_client.set_server_metadata,
355 self.server['id'],
356 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530357
Yuiko Takadae9999d62014-03-06 09:22:54 +0000358 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800359 @test.idempotent_id('fb6f51e9-df15-4939-898d-1aca38c258f0')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400360 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500361 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530362 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Masayuki Igawabfa07602015-01-20 18:47:17 +0900363 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030364 self.alt_images_client.set_image_metadata,
365 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530366
Yuiko Takadae9999d62014-03-06 09:22:54 +0000367 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800368 @test.idempotent_id('dea1936a-473d-49f2-92ad-97bb7aded22e')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400369 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500370 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530371 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800372 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000373 self.addCleanup(self.client.delete_server_metadata_item,
374 self.server['id'], 'meta1')
Masayuki Igawabfa07602015-01-20 18:47:17 +0900375 self.assertRaises(lib_exc.NotFound,
hi2suresh31bb7cb2013-03-14 04:53:49 +0000376 self.alt_client.get_server_metadata_item,
377 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530378
Yuiko Takadae9999d62014-03-06 09:22:54 +0000379 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800380 @test.idempotent_id('16b2d724-0d3b-4216-a9fa-97bd4d9cf670')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400381 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500382 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530383 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000384 self.addCleanup(self.images_client.delete_image_metadata_item,
385 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530386 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800387 req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900388 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000389 self.alt_images_client.get_image_metadata_item,
390 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530391
Yuiko Takadae9999d62014-03-06 09:22:54 +0000392 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800393 @test.idempotent_id('79531e2e-e721-493c-8b30-a35db36fdaa6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400394 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500395 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530396 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000397 self.addCleanup(self.client.delete_server_metadata_item,
398 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800399 self.client.set_server_metadata(self.server['id'], req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900400 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000401 self.alt_client.delete_server_metadata_item,
402 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530403
Yuiko Takadae9999d62014-03-06 09:22:54 +0000404 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800405 @test.idempotent_id('a5175dcf-cef8-43d6-9b77-3cb707d62e94')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400406 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500407 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530408 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000409 self.addCleanup(self.images_client.delete_image_metadata_item,
410 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530411 self.images_client.set_image_metadata(self.image['id'],
412 req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900413 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000414 self.alt_images_client.delete_image_metadata_item,
415 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530416
Yuiko Takadae9999d62014-03-06 09:22:54 +0000417 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800418 @test.idempotent_id('b0c1e7a0-8853-40fd-8384-01f93d116cae')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400419 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500420 # A Get Console Output for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900421 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030422 self.alt_client.get_console_output,
423 self.server['id'], 10)