blob: 63b78a04a6fca4f02c14bd87229e41e81dbf4ceb [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050019from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090020from tempest_lib import exceptions as lib_exc
21
Sean Dague1937d092013-05-17 16:36:38 -040022from tempest.api.compute import base
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
Daryl Walleckced8eb82012-03-19 13:52:37 -050055
Jay Pipesf38eaac2012-06-21 13:37:35 -040056 cls.alt_client = cls.alt_manager.servers_client
57 cls.alt_images_client = cls.alt_manager.images_client
58 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
59 cls.alt_security_client = cls.alt_manager.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050060
Emily Hugenbruche7991d92014-12-12 16:53:36 +000061 @classmethod
62 def resource_setup(cls):
63 super(AuthorizationTestJSON, cls).resource_setup()
David Kranz0fb14292015-02-11 15:55:20 -050064 server = cls.create_test_server(wait_until='ACTIVE')
65 cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040066
Masayuki Igawa259c1132013-10-31 17:48:44 +090067 name = data_utils.rand_name('image')
David Kranz34f18782015-01-06 13:43:55 -050068 body = cls.glance_client.create_image(name=name,
69 container_format='bare',
70 disk_format='raw',
71 is_public=False)
Adam Gandelman85f5bed2014-06-19 16:48:17 -070072 image_id = body['id']
Matthew Treinishb0c65f22015-04-23 09:09:41 -040073 image_file = six.StringIO(('*' * 1024))
David Kranz34f18782015-01-06 13:43:55 -050074 body = cls.glance_client.update_image(image_id, data=image_file)
Adam Gandelman85f5bed2014-06-19 16:48:17 -070075 cls.glance_client.wait_for_image_status(image_id, 'active')
Ken'ichi Ohmichi5d410762015-05-22 01:10:03 +000076 cls.image = cls.images_client.show_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050077
Masayuki Igawa259c1132013-10-31 17:48:44 +090078 cls.keypairname = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050079 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050080
Masayuki Igawa259c1132013-10-31 17:48:44 +090081 name = data_utils.rand_name('security')
82 description = data_utils.rand_name('description')
David Kranz9964b4e2015-02-06 15:45:29 -050083 cls.security_group = cls.security_client.create_security_group(
nayna-pateleda1d122013-03-20 14:44:31 +000084 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053085
Jay Pipesf38eaac2012-06-21 13:37:35 -040086 parent_group_id = cls.security_group['id']
87 ip_protocol = 'tcp'
88 from_port = 22
89 to_port = 22
David Kranz9964b4e2015-02-06 15:45:29 -050090 cls.rule = cls.security_client.create_security_group_rule(
nayna-pateleda1d122013-03-20 14:44:31 +000091 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053092
Daryl Walleckced8eb82012-03-19 13:52:37 -050093 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010094 def resource_cleanup(cls):
Andrea Frittoli (andreaf)1f342412015-05-12 16:37:19 +010095 if hasattr(cls, 'image'):
Daryl Walleckced8eb82012-03-19 13:52:37 -050096 cls.images_client.delete_image(cls.image['id'])
Andrea Frittoli (andreaf)1f342412015-05-12 16:37:19 +010097 if hasattr(cls, 'keypairname'):
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053098 cls.keypairs_client.delete_keypair(cls.keypairname)
Andrea Frittoli (andreaf)1f342412015-05-12 16:37:19 +010099 if hasattr(cls, 'security_group'):
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530100 cls.security_client.delete_security_group(cls.security_group['id'])
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100101 super(AuthorizationTestJSON, cls).resource_cleanup()
Daryl Walleckced8eb82012-03-19 13:52:37 -0500102
Chris Hoge7579c1a2015-02-26 14:12:15 -0800103 @test.idempotent_id('56816e4a-bd34-47b5-aee9-268c3efeb5d4')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400104 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500105 # A GET request for a server on another user's account should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900106 self.assertRaises(lib_exc.NotFound, self.alt_client.get_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030107 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500108
Chris Hoge7579c1a2015-02-26 14:12:15 -0800109 @test.idempotent_id('fb8a4870-6d9d-44ad-8375-95d52e98d9f6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400110 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500111 # A DELETE request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900112 self.assertRaises(lib_exc.NotFound, self.alt_client.delete_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030113 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500114
Chris Hoge7579c1a2015-02-26 14:12:15 -0800115 @test.idempotent_id('d792f91f-1d49-4eb5-b1ff-b229c4b9dc64')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400116 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500117 # An update server request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900118 self.assertRaises(lib_exc.NotFound, self.alt_client.update_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030119 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500120
Chris Hoge7579c1a2015-02-26 14:12:15 -0800121 @test.idempotent_id('488f24df-d7f7-4207-949a-f17fcb8e8769')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400122 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500123 # A list addresses request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900124 self.assertRaises(lib_exc.NotFound, self.alt_client.list_addresses,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030125 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500126
Chris Hoge7579c1a2015-02-26 14:12:15 -0800127 @test.idempotent_id('00b442d0-2e72-40e7-9b1f-31772e36da01')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400128 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500129 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500130 server_id = self.server['id']
Masayuki Igawabfa07602015-01-20 18:47:17 +0900131 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030132 self.alt_client.list_addresses_by_network, server_id,
133 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500134
Chris Hoge7579c1a2015-02-26 14:12:15 -0800135 @test.idempotent_id('cc90b35a-19f0-45d2-b680-2aabf934aa22')
sapan-kona37939762012-06-28 20:22:43 +0530136 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500137 # A list on servers from one tenant should not
138 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200139 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530140 alt_server_ids = []
David Kranzae99b9a2015-02-16 13:37:01 -0500141 body = self.alt_client.list_servers()
sapan-kona37939762012-06-28 20:22:43 +0530142 alt_server_ids = [s['id'] for s in body['servers']]
143 self.assertNotIn(self.server['id'], alt_server_ids)
144
Chris Hoge7579c1a2015-02-26 14:12:15 -0800145 @test.idempotent_id('376dbc16-0779-4384-a723-752774799641')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400146 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500147 # A change password request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900148 self.assertRaises(lib_exc.NotFound, self.alt_client.change_password,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030149 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500150
Chris Hoge7579c1a2015-02-26 14:12:15 -0800151 @test.idempotent_id('14cb5ff5-f646-45ca-8f51-09081d6c0c24')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400152 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500153 # A reboot request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900154 self.assertRaises(lib_exc.NotFound, self.alt_client.reboot,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030155 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500156
Chris Hoge7579c1a2015-02-26 14:12:15 -0800157 @test.idempotent_id('8a0bce51-cd00-480b-88ba-dbc7d8408a37')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400158 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500159 # A rebuild request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900160 self.assertRaises(lib_exc.NotFound, self.alt_client.rebuild,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030161 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500162
Chris Hoge7579c1a2015-02-26 14:12:15 -0800163 @test.idempotent_id('e4da647e-f982-4e61-9dad-1d1abebfb933')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400164 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500165 # A resize request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900166 self.assertRaises(lib_exc.NotFound, self.alt_client.resize,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030167 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500168
Chris Hoge7579c1a2015-02-26 14:12:15 -0800169 @test.idempotent_id('a9fe8112-0ffa-4902-b061-f892bd5fe0d3')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400170 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500171 # A create image request for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900172 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030173 self.alt_images_client.create_image,
174 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500175
Chris Hoge7579c1a2015-02-26 14:12:15 -0800176 @test.idempotent_id('95d445f6-babc-4f2e-aea3-aa24ec5e7f0d')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500177 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500178 # Server creation with another user's image should fail
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900179 self.assertRaises(lib_exc.BadRequest, self.alt_client.create_server,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030180 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500181
Chris Hoge7579c1a2015-02-26 14:12:15 -0800182 @test.idempotent_id('acf8724b-142b-4044-82c3-78d31a533f24')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500183 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500184 # A create server request should fail if the tenant id does not match
185 # the current user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000186 # Change the base URL to impersonate another user
187 self.alt_client.auth_provider.set_alt_auth_data(
188 request_part='url',
189 auth_data=self.client.auth_provider.auth_data
190 )
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900191 self.assertRaises(lib_exc.BadRequest,
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000192 self.alt_client.create_server, 'test',
193 self.image['id'], self.flavor_ref)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530194
Chris Hoge7579c1a2015-02-26 14:12:15 -0800195 @test.idempotent_id('f03d1ded-7fd4-4d29-bc13-e2391f29c625')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400196 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500197 # A create keypair request should fail if the tenant id does not match
198 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200199 # POST keypair with other user tenant
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000200 k_name = data_utils.rand_name('keypair')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530201 try:
202 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000203 self.alt_keypairs_client.auth_provider.set_alt_auth_data(
204 request_part='url',
205 auth_data=self.keypairs_client.auth_provider.auth_data
206 )
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530207 resp = {}
208 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900209 self.assertRaises(lib_exc.BadRequest,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030210 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530211 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000212 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800213 if (resp['status'] is not None):
David Kranz173f0e02015-02-06 13:47:57 -0500214 self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200215 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800216 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530217
Chris Hoge7579c1a2015-02-26 14:12:15 -0800218 @test.idempotent_id('85bcdd8f-56b4-4868-ae56-63fbf6f7e405')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400219 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500220 # A GET request for another user's keypair should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900221 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030222 self.alt_keypairs_client.get_keypair,
223 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530224
Chris Hoge7579c1a2015-02-26 14:12:15 -0800225 @test.idempotent_id('6d841683-a8e0-43da-a1b8-b339f7692b61')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400226 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500227 # A DELETE request for another user's keypair should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900228 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030229 self.alt_keypairs_client.delete_keypair,
230 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530231
Chris Hoge7579c1a2015-02-26 14:12:15 -0800232 @test.idempotent_id('fcb2e144-36e3-4dfb-9f9f-e72fcdec5656')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400233 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500234 # A GET request for an image on another user's account should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900235 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi5d410762015-05-22 01:10:03 +0000236 self.alt_images_client.show_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530237
Chris Hoge7579c1a2015-02-26 14:12:15 -0800238 @test.idempotent_id('9facb962-f043-4a9d-b9ee-166a32dea098')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400239 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500240 # A DELETE request for another user's image should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900241 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030242 self.alt_images_client.delete_image,
243 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530244
Chris Hoge7579c1a2015-02-26 14:12:15 -0800245 @test.idempotent_id('752c917e-83be-499d-a422-3559127f7d3c')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400246 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500247 # A create security group request should fail if the tenant id does not
248 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200249 # POST security group with other user tenant
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000250 s_name = data_utils.rand_name('security')
Masayuki Igawa259c1132013-10-31 17:48:44 +0900251 s_description = data_utils.rand_name('security')
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530252 try:
253 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000254 self.alt_security_client.auth_provider.set_alt_auth_data(
255 request_part='url',
256 auth_data=self.security_client.auth_provider.auth_data
257 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530258 resp = {}
259 resp['status'] = None
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900260 self.assertRaises(lib_exc.BadRequest,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030261 self.alt_security_client.create_security_group,
262 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530263 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000264 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800265 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700266 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200267 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530268 "the tenant id does not match the current user")
269
Chris Hoge7579c1a2015-02-26 14:12:15 -0800270 @test.idempotent_id('9db3590f-4d15-4e5f-985e-b28514919a6f')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400271 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500272 # A GET request for another user's security group should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900273 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030274 self.alt_security_client.get_security_group,
275 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530276
Chris Hoge7579c1a2015-02-26 14:12:15 -0800277 @test.idempotent_id('155387a5-2bbc-4acf-ab06-698dae537ea5')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400278 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500279 # A DELETE request for another user's security group should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900280 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030281 self.alt_security_client.delete_security_group,
282 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530283
Chris Hoge7579c1a2015-02-26 14:12:15 -0800284 @test.idempotent_id('b2b76de0-210a-4089-b921-591c9ec552f6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400285 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500286 # A create security group rule request should fail if the tenant id
287 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200288 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530289 parent_group_id = self.security_group['id']
290 ip_protocol = 'icmp'
291 from_port = -1
292 to_port = -1
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.
303 create_security_group_rule,
304 parent_group_id, ip_protocol, from_port,
305 to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530306 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000307 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800308 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700309 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200310 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530311 "happen if the tenant id does not match the"
312 " current user")
313
Chris Hoge7579c1a2015-02-26 14:12:15 -0800314 @test.idempotent_id('c6044177-37ef-4ce4-b12c-270ddf26d7da')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400315 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500316 # A DELETE request for another user's security group rule
317 # should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900318 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030319 self.alt_security_client.delete_security_group_rule,
320 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530321
Chris Hoge7579c1a2015-02-26 14:12:15 -0800322 @test.idempotent_id('c5f52351-53d9-4fc9-83e5-917f7f5e3d71')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400323 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500324 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530325 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Masayuki Igawabfa07602015-01-20 18:47:17 +0900326 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030327 self.alt_client.set_server_metadata,
328 self.server['id'],
329 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530330
Chris Hoge7579c1a2015-02-26 14:12:15 -0800331 @test.idempotent_id('fb6f51e9-df15-4939-898d-1aca38c258f0')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400332 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500333 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530334 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Masayuki Igawabfa07602015-01-20 18:47:17 +0900335 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030336 self.alt_images_client.set_image_metadata,
337 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530338
Chris Hoge7579c1a2015-02-26 14:12:15 -0800339 @test.idempotent_id('dea1936a-473d-49f2-92ad-97bb7aded22e')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400340 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500341 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530342 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800343 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000344 self.addCleanup(self.client.delete_server_metadata_item,
345 self.server['id'], 'meta1')
Masayuki Igawabfa07602015-01-20 18:47:17 +0900346 self.assertRaises(lib_exc.NotFound,
hi2suresh31bb7cb2013-03-14 04:53:49 +0000347 self.alt_client.get_server_metadata_item,
348 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530349
Chris Hoge7579c1a2015-02-26 14:12:15 -0800350 @test.idempotent_id('16b2d724-0d3b-4216-a9fa-97bd4d9cf670')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400351 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500352 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530353 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000354 self.addCleanup(self.images_client.delete_image_metadata_item,
355 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530356 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800357 req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900358 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000359 self.alt_images_client.get_image_metadata_item,
360 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530361
Chris Hoge7579c1a2015-02-26 14:12:15 -0800362 @test.idempotent_id('79531e2e-e721-493c-8b30-a35db36fdaa6')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400363 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500364 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530365 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000366 self.addCleanup(self.client.delete_server_metadata_item,
367 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800368 self.client.set_server_metadata(self.server['id'], req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900369 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000370 self.alt_client.delete_server_metadata_item,
371 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530372
Chris Hoge7579c1a2015-02-26 14:12:15 -0800373 @test.idempotent_id('a5175dcf-cef8-43d6-9b77-3cb707d62e94')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400374 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500375 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530376 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000377 self.addCleanup(self.images_client.delete_image_metadata_item,
378 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530379 self.images_client.set_image_metadata(self.image['id'],
380 req_metadata)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900381 self.assertRaises(lib_exc.NotFound,
hi2sureshd0e24122013-03-15 03:06:53 +0000382 self.alt_images_client.delete_image_metadata_item,
383 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530384
Chris Hoge7579c1a2015-02-26 14:12:15 -0800385 @test.idempotent_id('b0c1e7a0-8853-40fd-8384-01f93d116cae')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400386 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500387 # A Get Console Output for another user's server should fail
Masayuki Igawabfa07602015-01-20 18:47:17 +0900388 self.assertRaises(lib_exc.NotFound,
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030389 self.alt_client.get_console_output,
390 self.server['id'], 10)