blob: f8d0cca8b24e177b9d8457364a458a8a798aea2c [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
Matthew Treinishb0c65f22015-04-23 09:09:41 -040016import six
Adam Gandelman85f5bed2014-06-19 16:48:17 -070017
Doug Hellmann583ce2c2015-03-11 14:55:46 +000018from oslo_log import log as logging
Masayuki Igawabfa07602015-01-20 18:47:17 +090019from tempest_lib import exceptions as lib_exc
20
Sean Dague1937d092013-05-17 16:36:38 -040021from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120022from tempest.common.utils import data_utils
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000023from tempest import config
Yuiko Takadae9999d62014-03-06 09:22:54 +000024from tempest import test
Daryl Walleckced8eb82012-03-19 13:52:37 -050025
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000026CONF = config.CONF
27
Giulio Fidente92f77192013-08-26 17:13:28 +020028LOG = logging.getLogger(__name__)
29
Daryl Walleckced8eb82012-03-19 13:52:37 -050030
ivan-zhuf2b00502013-10-18 10:06:52 +080031class AuthorizationTestJSON(base.BaseV2ComputeTest):
Emily Hugenbruche7991d92014-12-12 16:53:36 +000032
Andrea Frittolib21de6c2015-02-06 20:12:38 +000033 credentials = ['primary', 'alt']
34
Daryl Walleckced8eb82012-03-19 13:52:37 -050035 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000036 def skip_checks(cls):
37 super(AuthorizationTestJSON, cls).skip_checks()
Adam Gandelman85f5bed2014-06-19 16:48:17 -070038 if not CONF.service_available.glance:
39 raise cls.skipException('Glance is not available.')
Emily Hugenbruche7991d92014-12-12 16:53:36 +000040
41 @classmethod
42 def setup_credentials(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000043 # No network resources required for this test
44 cls.set_network_resources()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000045 super(AuthorizationTestJSON, cls).setup_credentials()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000046
47 @classmethod
48 def setup_clients(cls):
49 super(AuthorizationTestJSON, cls).setup_clients()
Daryl Walleckced8eb82012-03-19 13:52:37 -050050 cls.client = cls.os.servers_client
51 cls.images_client = cls.os.images_client
Adam Gandelman85f5bed2014-06-19 16:48:17 -070052 cls.glance_client = cls.os.image_client
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053053 cls.keypairs_client = cls.os.keypairs_client
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053054 cls.security_client = cls.os.security_groups_client
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +000055 cls.rule_client = cls.os.security_group_rules_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050056
Jay Pipesf38eaac2012-06-21 13:37:35 -040057 cls.alt_client = cls.alt_manager.servers_client
58 cls.alt_images_client = cls.alt_manager.images_client
59 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
60 cls.alt_security_client = cls.alt_manager.security_groups_client
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +000061 cls.alt_rule_client = cls.alt_manager.security_group_rules_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050062
Emily Hugenbruche7991d92014-12-12 16:53:36 +000063 @classmethod
64 def resource_setup(cls):
65 super(AuthorizationTestJSON, cls).resource_setup()
David Kranz0fb14292015-02-11 15:55:20 -050066 server = cls.create_test_server(wait_until='ACTIVE')
ghanshyam0f825252015-08-25 16:02:50 +090067 cls.server = cls.client.show_server(server['id'])['server']
Jay Pipes3f981df2012-03-27 18:59:44 -040068
Masayuki Igawa259c1132013-10-31 17:48:44 +090069 name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -050070 body = cls.glance_client.create_image(name=name,
71 container_format='bare',
72 disk_format='raw',
John Warren66207252015-07-31 15:51:02 -040073 is_public=False)['image']
Adam Gandelman85f5bed2014-06-19 16:48:17 -070074 image_id = body['id']
Matthew Treinishb0c65f22015-04-23 09:09:41 -040075 image_file = six.StringIO(('*' * 1024))
John Warren66207252015-07-31 15:51:02 -040076 body = cls.glance_client.update_image(image_id,
77 data=image_file)['image']
Adam Gandelman85f5bed2014-06-19 16:48:17 -070078 cls.glance_client.wait_for_image_status(image_id, 'active')
ghanshyam1756e0b2015-08-18 19:19:05 +090079 cls.image = cls.images_client.show_image(image_id)['image']
Daryl Walleckced8eb82012-03-19 13:52:37 -050080
Masayuki Igawa259c1132013-10-31 17:48:44 +090081 cls.keypairname = data_utils.rand_name('keypair')
Ken'ichi Ohmichie364bce2015-07-17 10:27:59 +000082 cls.keypairs_client.create_keypair(name=cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050083
Masayuki Igawa259c1132013-10-31 17:48:44 +090084 name = data_utils.rand_name('security')
85 description = data_utils.rand_name('description')
David Kranz9964b4e2015-02-06 15:45:29 -050086 cls.security_group = cls.security_client.create_security_group(
ghanshyamb610b772015-08-24 17:29:38 +090087 name=name, description=description)['security_group']
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053088
Jay Pipesf38eaac2012-06-21 13:37:35 -040089 parent_group_id = cls.security_group['id']
90 ip_protocol = 'tcp'
91 from_port = 22
92 to_port = 22
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +000093 cls.rule = cls.rule_client.create_security_group_rule(
Ken'ichi Ohmichieb7eeec2015-07-21 01:00:06 +000094 parent_group_id=parent_group_id, ip_protocol=ip_protocol,
ghanshyam0a5e1232015-08-24 16:59:59 +090095 from_port=from_port, to_port=to_port)['security_group_rule']
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053096
Daryl Walleckced8eb82012-03-19 13:52:37 -050097 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010098 def resource_cleanup(cls):
Andrea Frittoli (andreaf)1f342412015-05-12 16:37:19 +010099 if hasattr(cls, 'image'):
Daryl Walleckced8eb82012-03-19 13:52:37 -0500100 cls.images_client.delete_image(cls.image['id'])
Andrea Frittoli (andreaf)1f342412015-05-12 16:37:19 +0100101 if hasattr(cls, 'keypairname'):
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530102 cls.keypairs_client.delete_keypair(cls.keypairname)
Andrea Frittoli (andreaf)1f342412015-05-12 16:37:19 +0100103 if hasattr(cls, 'security_group'):
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530104 cls.security_client.delete_security_group(cls.security_group['id'])
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100105 super(AuthorizationTestJSON, cls).resource_cleanup()
Daryl Walleckced8eb82012-03-19 13:52:37 -0500106
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
Ken'ichi Ohmichi76800242015-07-03 05:12:31 +0000110 self.assertRaises(lib_exc.NotFound, self.alt_client.show_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030111 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500112
Chris Hoge7579c1a2015-02-26 14:12:15 -0800113 @test.idempotent_id('fb8a4870-6d9d-44ad-8375-95d52e98d9f6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400114 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500115 # A DELETE request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900116 self.assertRaises(lib_exc.NotFound, self.alt_client.delete_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030117 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500118
Chris Hoge7579c1a2015-02-26 14:12:15 -0800119 @test.idempotent_id('d792f91f-1d49-4eb5-b1ff-b229c4b9dc64')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400120 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500121 # An update server request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900122 self.assertRaises(lib_exc.NotFound, self.alt_client.update_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030123 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500124
Chris Hoge7579c1a2015-02-26 14:12:15 -0800125 @test.idempotent_id('488f24df-d7f7-4207-949a-f17fcb8e8769')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400126 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500127 # A list addresses request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900128 self.assertRaises(lib_exc.NotFound, self.alt_client.list_addresses,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030129 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500130
Chris Hoge7579c1a2015-02-26 14:12:15 -0800131 @test.idempotent_id('00b442d0-2e72-40e7-9b1f-31772e36da01')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400132 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500133 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500134 server_id = self.server['id']
Masayuki Igawabfa07602015-01-20 18:47:17 +0900135 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030136 self.alt_client.list_addresses_by_network, server_id,
137 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500138
Chris Hoge7579c1a2015-02-26 14:12:15 -0800139 @test.idempotent_id('cc90b35a-19f0-45d2-b680-2aabf934aa22')
sapan-kona37939762012-06-28 20:22:43 +0530140 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500141 # A list on servers from one tenant should not
142 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200143 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530144 alt_server_ids = []
David Kranzae99b9a2015-02-16 13:37:01 -0500145 body = self.alt_client.list_servers()
sapan-kona37939762012-06-28 20:22:43 +0530146 alt_server_ids = [s['id'] for s in body['servers']]
147 self.assertNotIn(self.server['id'], alt_server_ids)
148
Chris Hoge7579c1a2015-02-26 14:12:15 -0800149 @test.idempotent_id('376dbc16-0779-4384-a723-752774799641')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400150 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500151 # A change password request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900152 self.assertRaises(lib_exc.NotFound, self.alt_client.change_password,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030153 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500154
Chris Hoge7579c1a2015-02-26 14:12:15 -0800155 @test.idempotent_id('14cb5ff5-f646-45ca-8f51-09081d6c0c24')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400156 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500157 # A reboot request for another user's server should fail
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000158 self.assertRaises(lib_exc.NotFound, self.alt_client.reboot_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030159 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500160
Chris Hoge7579c1a2015-02-26 14:12:15 -0800161 @test.idempotent_id('8a0bce51-cd00-480b-88ba-dbc7d8408a37')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400162 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500163 # A rebuild request for another user's server should fail
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000164 self.assertRaises(lib_exc.NotFound, self.alt_client.rebuild_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030165 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500166
Chris Hoge7579c1a2015-02-26 14:12:15 -0800167 @test.idempotent_id('e4da647e-f982-4e61-9dad-1d1abebfb933')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400168 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500169 # A resize request for another user's server should fail
Ken'ichi Ohmichi5271b0f2015-08-10 07:53:27 +0000170 self.assertRaises(lib_exc.NotFound, self.alt_client.resize_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030171 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500172
Chris Hoge7579c1a2015-02-26 14:12:15 -0800173 @test.idempotent_id('a9fe8112-0ffa-4902-b061-f892bd5fe0d3')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400174 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500175 # A create image request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900176 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030177 self.alt_images_client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +0000178 self.server['id'], name='testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500179
Chris Hoge7579c1a2015-02-26 14:12:15 -0800180 @test.idempotent_id('95d445f6-babc-4f2e-aea3-aa24ec5e7f0d')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500181 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500182 # Server creation with another user's image should fail
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900183 self.assertRaises(lib_exc.BadRequest, self.alt_client.create_server,
Ken'ichi Ohmichif2d436e2015-09-03 01:13:16 +0000184 name='test', imageRef=self.image['id'],
185 flavorRef=self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500186
Chris Hoge7579c1a2015-02-26 14:12:15 -0800187 @test.idempotent_id('acf8724b-142b-4044-82c3-78d31a533f24')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500188 def test_create_server_fails_when_tenant_incorrect(self):
Sean Daguef749cd72015-10-14 08:21:59 -0400189 # BUG(sdague): this test should fail because of bad auth url,
190 # which means that when we run with a service catalog without
191 # project_id in the urls, it should fail to fail, and thus
192 # fail the test. It does not.
193 #
194 # The 400 BadRequest is clearly ambiguous, and something else
195 # is wrong about this request. This should be fixed.
196 #
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500197 # A create server request should fail if the tenant id does not match
198 # the current user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000199 # Change the base URL to impersonate another user
200 self.alt_client.auth_provider.set_alt_auth_data(
201 request_part='url',
202 auth_data=self.client.auth_provider.auth_data
203 )
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900204 self.assertRaises(lib_exc.BadRequest,
Ken'ichi Ohmichif2d436e2015-09-03 01:13:16 +0000205 self.alt_client.create_server, name='test',
206 imageRef=self.image['id'], flavorRef=self.flavor_ref)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530207
Chris Hoge7579c1a2015-02-26 14:12:15 -0800208 @test.idempotent_id('f03d1ded-7fd4-4d29-bc13-e2391f29c625')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400209 def test_create_keypair_in_analt_user_tenant(self):
Sean Daguef749cd72015-10-14 08:21:59 -0400210 """create keypair should not function for alternate tenant
211
212 POST {alt_service_url}/os-keypairs
213
214 Attempt to create a keypair against an alternate tenant by
215 changing using a different tenant's service url. This should
216 return a BadRequest. This tests basic tenant isolation protections.
217
218 NOTE(sdague): if the environment does not use project_id in
219 the service urls, this test is not valid. Skip under these
220 conditions.
221
222 """
223 if self.alt_keypairs_client.base_url == self.keypairs_client.base_url:
224 raise self.skipException("Service urls don't include project_id")
225
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000226 k_name = data_utils.rand_name('keypair')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530227 try:
228 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000229 self.alt_keypairs_client.auth_provider.set_alt_auth_data(
230 request_part='url',
231 auth_data=self.keypairs_client.auth_provider.auth_data
232 )
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530233 resp = {}
234 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900235 self.assertRaises(lib_exc.BadRequest,
Ken'ichi Ohmichie364bce2015-07-17 10:27:59 +0000236 self.alt_keypairs_client.create_keypair,
237 name=k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530238 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000239 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800240 if (resp['status'] is not None):
David Kranz173f0e02015-02-06 13:47:57 -0500241 self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200242 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800243 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530244
Chris Hoge7579c1a2015-02-26 14:12:15 -0800245 @test.idempotent_id('85bcdd8f-56b4-4868-ae56-63fbf6f7e405')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400246 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500247 # A GET request for another user's keypair should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900248 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi0943d9b2015-06-17 02:27:05 +0000249 self.alt_keypairs_client.show_keypair,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030250 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530251
Chris Hoge7579c1a2015-02-26 14:12:15 -0800252 @test.idempotent_id('6d841683-a8e0-43da-a1b8-b339f7692b61')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400253 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500254 # A DELETE request for another user's keypair 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_keypairs_client.delete_keypair,
257 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530258
Chris Hoge7579c1a2015-02-26 14:12:15 -0800259 @test.idempotent_id('fcb2e144-36e3-4dfb-9f9f-e72fcdec5656')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400260 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500261 # A GET request for an image on another user's account should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900262 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi5d410762015-05-22 01:10:03 +0000263 self.alt_images_client.show_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530264
Chris Hoge7579c1a2015-02-26 14:12:15 -0800265 @test.idempotent_id('9facb962-f043-4a9d-b9ee-166a32dea098')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400266 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500267 # A DELETE request for another user's image should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900268 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030269 self.alt_images_client.delete_image,
270 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530271
Chris Hoge7579c1a2015-02-26 14:12:15 -0800272 @test.idempotent_id('752c917e-83be-499d-a422-3559127f7d3c')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400273 def test_create_security_group_in_analt_user_tenant(self):
Sean Daguef749cd72015-10-14 08:21:59 -0400274 """create security group should not function for alternate tenant
275
276 POST {alt_service_url}/os-security-groups
277
278 Attempt to create a security group against an alternate tenant
279 by changing using a different tenant's service url. This
280 should return a BadRequest. This tests basic tenant isolation
281 protections.
282
283 NOTE(sdague): if the environment does not use project_id in
284 the service urls, this test is not valid. Skip under these
285 conditions.
286
287 """
288 if self.alt_security_client.base_url == self.security_client.base_url:
289 raise self.skipException("Service urls don't include project_id")
290
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000291 s_name = data_utils.rand_name('security')
Masayuki Igawa259c1132013-10-31 17:48:44 +0900292 s_description = data_utils.rand_name('security')
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530293 try:
294 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000295 self.alt_security_client.auth_provider.set_alt_auth_data(
296 request_part='url',
297 auth_data=self.security_client.auth_provider.auth_data
298 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530299 resp = {}
300 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900301 self.assertRaises(lib_exc.BadRequest,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030302 self.alt_security_client.create_security_group,
Ken'ichi Ohmichi34563cc2015-07-21 00:53:17 +0000303 name=s_name, description=s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530304 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000305 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800306 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700307 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200308 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530309 "the tenant id does not match the current user")
310
Chris Hoge7579c1a2015-02-26 14:12:15 -0800311 @test.idempotent_id('9db3590f-4d15-4e5f-985e-b28514919a6f')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400312 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500313 # A GET request for another user's security group should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900314 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi217f2f32015-06-17 02:52:44 +0000315 self.alt_security_client.show_security_group,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030316 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530317
Chris Hoge7579c1a2015-02-26 14:12:15 -0800318 @test.idempotent_id('155387a5-2bbc-4acf-ab06-698dae537ea5')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400319 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500320 # A DELETE request for another user's security group should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900321 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030322 self.alt_security_client.delete_security_group,
323 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530324
Chris Hoge7579c1a2015-02-26 14:12:15 -0800325 @test.idempotent_id('b2b76de0-210a-4089-b921-591c9ec552f6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400326 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Daguef749cd72015-10-14 08:21:59 -0400327 """create security group rule should not function for alternate tenant
328
329 POST {alt_service_url}/os-security-group-rules
330
331 Attempt to create a security group rule against an alternate
332 tenant by changing using a different tenant's service
333 url. This should return a BadRequest. This tests basic tenant
334 isolation protections.
335
336 NOTE(sdague): if the environment does not use project_id in
337 the service urls, this test is not valid. Skip under these
338 conditions.
339
340 """
341 if self.alt_security_client.base_url == self.security_client.base_url:
342 raise self.skipException("Service urls don't include project_id")
343
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530344 parent_group_id = self.security_group['id']
345 ip_protocol = 'icmp'
346 from_port = -1
347 to_port = -1
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530348 try:
349 # Change the base URL to impersonate another user
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +0000350 self.alt_rule_client.auth_provider.set_alt_auth_data(
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000351 request_part='url',
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +0000352 auth_data=self.rule_client.auth_provider.auth_data
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000353 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530354 resp = {}
355 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900356 self.assertRaises(lib_exc.BadRequest,
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +0000357 self.alt_rule_client.
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030358 create_security_group_rule,
Ken'ichi Ohmichieb7eeec2015-07-21 01:00:06 +0000359 parent_group_id=parent_group_id,
360 ip_protocol=ip_protocol,
361 from_port=from_port, to_port=to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530362 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000363 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800364 if resp['status'] is not None:
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +0000365 self.alt_rule_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200366 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530367 "happen if the tenant id does not match the"
368 " current user")
369
Chris Hoge7579c1a2015-02-26 14:12:15 -0800370 @test.idempotent_id('c6044177-37ef-4ce4-b12c-270ddf26d7da')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400371 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500372 # A DELETE request for another user's security group rule
373 # should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900374 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi685cd172015-07-13 01:29:57 +0000375 self.alt_rule_client.delete_security_group_rule,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030376 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530377
Chris Hoge7579c1a2015-02-26 14:12:15 -0800378 @test.idempotent_id('c5f52351-53d9-4fc9-83e5-917f7f5e3d71')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400379 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500380 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530381 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Masayuki Igawabfa07602015-01-20 18:47:17 +0900382 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030383 self.alt_client.set_server_metadata,
384 self.server['id'],
385 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530386
Chris Hoge7579c1a2015-02-26 14:12:15 -0800387 @test.idempotent_id('fb6f51e9-df15-4939-898d-1aca38c258f0')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400388 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500389 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530390 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Masayuki Igawabfa07602015-01-20 18:47:17 +0900391 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030392 self.alt_images_client.set_image_metadata,
393 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530394
Chris Hoge7579c1a2015-02-26 14:12:15 -0800395 @test.idempotent_id('dea1936a-473d-49f2-92ad-97bb7aded22e')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400396 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500397 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530398 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800399 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000400 self.addCleanup(self.client.delete_server_metadata_item,
401 self.server['id'], 'meta1')
Masayuki Igawabfa07602015-01-20 18:47:17 +0900402 self.assertRaises(lib_exc.NotFound,
hi2suresh31bb7cb2013-03-14 04:53:49 +0000403 self.alt_client.get_server_metadata_item,
404 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530405
Chris Hoge7579c1a2015-02-26 14:12:15 -0800406 @test.idempotent_id('16b2d724-0d3b-4216-a9fa-97bd4d9cf670')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400407 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500408 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530409 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000410 self.addCleanup(self.images_client.delete_image_metadata_item,
411 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530412 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800413 req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900414 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi0943d9b2015-06-17 02:27:05 +0000415 self.alt_images_client.show_image_metadata_item,
hi2sureshd0e24122013-03-15 03:06:53 +0000416 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530417
Chris Hoge7579c1a2015-02-26 14:12:15 -0800418 @test.idempotent_id('79531e2e-e721-493c-8b30-a35db36fdaa6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400419 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500420 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530421 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000422 self.addCleanup(self.client.delete_server_metadata_item,
423 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800424 self.client.set_server_metadata(self.server['id'], req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900425 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000426 self.alt_client.delete_server_metadata_item,
427 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530428
Chris Hoge7579c1a2015-02-26 14:12:15 -0800429 @test.idempotent_id('a5175dcf-cef8-43d6-9b77-3cb707d62e94')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400430 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500431 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530432 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000433 self.addCleanup(self.images_client.delete_image_metadata_item,
434 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530435 self.images_client.set_image_metadata(self.image['id'],
436 req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900437 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000438 self.alt_images_client.delete_image_metadata_item,
439 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530440
Chris Hoge7579c1a2015-02-26 14:12:15 -0800441 @test.idempotent_id('b0c1e7a0-8853-40fd-8384-01f93d116cae')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400442 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500443 # A Get Console Output for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900444 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030445 self.alt_client.get_console_output,
446 self.server['id'], 10)