blob: fd73cc56ccc4e386865cf0bb7220f83595684997 [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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Matthew Treinish481466b2012-12-20 17:16:01 -050017from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090018from tempest.common.utils import data_utils
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000019from tempest import config
Daryl Walleckdc9e0c42012-04-02 16:51:26 -050020from tempest import exceptions
Giulio Fidente92f77192013-08-26 17:13:28 +020021from tempest.openstack.common import log as logging
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040022from tempest.test import attr
Daryl Walleckced8eb82012-03-19 13:52:37 -050023
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000024CONF = config.CONF
25
Giulio Fidente92f77192013-08-26 17:13:28 +020026LOG = logging.getLogger(__name__)
27
Daryl Walleckced8eb82012-03-19 13:52:37 -050028
ivan-zhuf2b00502013-10-18 10:06:52 +080029class AuthorizationTestJSON(base.BaseV2ComputeTest):
Daryl Walleckced8eb82012-03-19 13:52:37 -050030
31 @classmethod
32 def setUpClass(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000033 # No network resources required for this test
34 cls.set_network_resources()
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000035 super(AuthorizationTestJSON, cls).setUpClass()
36 if not cls.multi_user:
Jay Pipesf38eaac2012-06-21 13:37:35 -040037 msg = "Need >1 user"
ivan-zhu1feeb382013-01-24 10:14:39 +080038 raise cls.skipException(msg)
Daryl Walleckced8eb82012-03-19 13:52:37 -050039 cls.client = cls.os.servers_client
40 cls.images_client = cls.os.images_client
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053041 cls.keypairs_client = cls.os.keypairs_client
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053042 cls.security_client = cls.os.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050043
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000044 if CONF.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040045 creds = cls.isolated_creds.get_alt_creds()
Jay Pipesf38eaac2012-06-21 13:37:35 -040046 username, tenant_name, password = creds
Matthew Treinish481466b2012-12-20 17:16:01 -050047 cls.alt_manager = clients.Manager(username=username,
48 password=password,
49 tenant_name=tenant_name)
Jay Pipesf38eaac2012-06-21 13:37:35 -040050 else:
51 # Use the alt_XXX credentials in the config file
Matthew Treinish481466b2012-12-20 17:16:01 -050052 cls.alt_manager = clients.AltManager()
Daryl Walleckced8eb82012-03-19 13:52:37 -050053
Jay Pipesf38eaac2012-06-21 13:37:35 -040054 cls.alt_client = cls.alt_manager.servers_client
55 cls.alt_images_client = cls.alt_manager.images_client
56 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
57 cls.alt_security_client = cls.alt_manager.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050058
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090059 resp, server = cls.create_test_server(wait_until='ACTIVE')
Jay Pipesf38eaac2012-06-21 13:37:35 -040060 resp, cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040061
Masayuki Igawa259c1132013-10-31 17:48:44 +090062 name = data_utils.rand_name('image')
Jay Pipesf38eaac2012-06-21 13:37:35 -040063 resp, body = cls.client.create_image(server['id'], name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090064 image_id = data_utils.parse_image_id(resp['location'])
Jay Pipesf38eaac2012-06-21 13:37:35 -040065 cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
66 resp, cls.image = cls.images_client.get_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050067
Masayuki Igawa259c1132013-10-31 17:48:44 +090068 cls.keypairname = data_utils.rand_name('keypair')
Jay Pipesf38eaac2012-06-21 13:37:35 -040069 resp, keypair = \
70 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050071
Masayuki Igawa259c1132013-10-31 17:48:44 +090072 name = data_utils.rand_name('security')
73 description = data_utils.rand_name('description')
nayna-pateleda1d122013-03-20 14:44:31 +000074 resp, cls.security_group = cls.security_client.create_security_group(
75 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053076
Jay Pipesf38eaac2012-06-21 13:37:35 -040077 parent_group_id = cls.security_group['id']
78 ip_protocol = 'tcp'
79 from_port = 22
80 to_port = 22
nayna-pateleda1d122013-03-20 14:44:31 +000081 resp, cls.rule = cls.security_client.create_security_group_rule(
82 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053083
Daryl Walleckced8eb82012-03-19 13:52:37 -050084 @classmethod
85 def tearDownClass(cls):
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000086 if cls.multi_user:
Daryl Walleckced8eb82012-03-19 13:52:37 -050087 cls.images_client.delete_image(cls.image['id'])
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053088 cls.keypairs_client.delete_keypair(cls.keypairname)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053089 cls.security_client.delete_security_group(cls.security_group['id'])
nayna-pateleda1d122013-03-20 14:44:31 +000090 super(AuthorizationTestJSON, cls).tearDownClass()
Daryl Walleckced8eb82012-03-19 13:52:37 -050091
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040092 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040093 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050094 # A GET request for a server on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103095 self.assertRaises(exceptions.NotFound, self.alt_client.get_server,
96 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -050097
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040098 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040099 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500100 # A DELETE request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030101 self.assertRaises(exceptions.NotFound, self.alt_client.delete_server,
102 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500103
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400104 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400105 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500106 # An update server request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030107 self.assertRaises(exceptions.NotFound, self.alt_client.update_server,
108 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500109
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400110 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400111 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500112 # A list addresses request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030113 self.assertRaises(exceptions.NotFound, self.alt_client.list_addresses,
114 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500115
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400116 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400117 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500118 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500119 server_id = self.server['id']
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030120 self.assertRaises(exceptions.NotFound,
121 self.alt_client.list_addresses_by_network, server_id,
122 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500123
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400124 @attr(type='gate')
sapan-kona37939762012-06-28 20:22:43 +0530125 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500126 # A list on servers from one tenant should not
127 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200128 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530129 alt_server_ids = []
130 resp, body = self.alt_client.list_servers()
131 alt_server_ids = [s['id'] for s in body['servers']]
132 self.assertNotIn(self.server['id'], alt_server_ids)
133
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400134 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400135 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500136 # A change password request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030137 self.assertRaises(exceptions.NotFound, self.alt_client.change_password,
138 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500139
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400140 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400141 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500142 # A reboot request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030143 self.assertRaises(exceptions.NotFound, self.alt_client.reboot,
144 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500145
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400146 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400147 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500148 # A rebuild request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030149 self.assertRaises(exceptions.NotFound, self.alt_client.rebuild,
150 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500151
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400152 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400153 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500154 # A resize request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030155 self.assertRaises(exceptions.NotFound, self.alt_client.resize,
156 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500157
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400158 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400159 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500160 # A create image request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030161 self.assertRaises(exceptions.NotFound,
162 self.alt_images_client.create_image,
163 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500164
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400165 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500166 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500167 # Server creation with another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030168 self.assertRaises(exceptions.BadRequest, self.alt_client.create_server,
169 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500170
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400171 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500172 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500173 # A create server request should fail if the tenant id does not match
174 # the current user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000175 # Change the base URL to impersonate another user
176 self.alt_client.auth_provider.set_alt_auth_data(
177 request_part='url',
178 auth_data=self.client.auth_provider.auth_data
179 )
180 self.assertRaises(exceptions.BadRequest,
181 self.alt_client.create_server, 'test',
182 self.image['id'], self.flavor_ref)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530183
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400184 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400185 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500186 # A create keypair request should fail if the tenant id does not match
187 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200188 # POST keypair with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900189 k_name = data_utils.rand_name('keypair-')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530190 try:
191 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000192 self.alt_keypairs_client.auth_provider.set_alt_auth_data(
193 request_part='url',
194 auth_data=self.keypairs_client.auth_provider.auth_data
195 )
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530196 resp = {}
197 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030198 self.assertRaises(exceptions.BadRequest,
199 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530200 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000201 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800202 if (resp['status'] is not None):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400203 resp, _ = self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200204 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800205 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530206
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400207 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400208 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500209 # A GET request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030210 self.assertRaises(exceptions.NotFound,
211 self.alt_keypairs_client.get_keypair,
212 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530213
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400214 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400215 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500216 # A DELETE request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030217 self.assertRaises(exceptions.NotFound,
218 self.alt_keypairs_client.delete_keypair,
219 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530220
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400221 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400222 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500223 # A GET request for an image on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030224 self.assertRaises(exceptions.NotFound,
225 self.alt_images_client.get_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530226
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400227 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400228 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500229 # A DELETE request for another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030230 self.assertRaises(exceptions.NotFound,
231 self.alt_images_client.delete_image,
232 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530233
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400234 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400235 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500236 # A create security group request should fail if the tenant id does not
237 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200238 # POST security group with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900239 s_name = data_utils.rand_name('security-')
240 s_description = data_utils.rand_name('security')
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530241 try:
242 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000243 self.alt_security_client.auth_provider.set_alt_auth_data(
244 request_part='url',
245 auth_data=self.security_client.auth_provider.auth_data
246 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530247 resp = {}
248 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030249 self.assertRaises(exceptions.BadRequest,
250 self.alt_security_client.create_security_group,
251 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530252 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000253 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800254 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700255 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200256 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530257 "the tenant id does not match the current user")
258
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400259 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400260 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500261 # A GET request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030262 self.assertRaises(exceptions.NotFound,
263 self.alt_security_client.get_security_group,
264 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530265
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400266 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400267 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500268 # A DELETE request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030269 self.assertRaises(exceptions.NotFound,
270 self.alt_security_client.delete_security_group,
271 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530272
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400273 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400274 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500275 # A create security group rule request should fail if the tenant id
276 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200277 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530278 parent_group_id = self.security_group['id']
279 ip_protocol = 'icmp'
280 from_port = -1
281 to_port = -1
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530282 try:
283 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000284 self.alt_security_client.auth_provider.set_alt_auth_data(
285 request_part='url',
286 auth_data=self.security_client.auth_provider.auth_data
287 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530288 resp = {}
289 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030290 self.assertRaises(exceptions.BadRequest,
291 self.alt_security_client.
292 create_security_group_rule,
293 parent_group_id, ip_protocol, from_port,
294 to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530295 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000296 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800297 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700298 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200299 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530300 "happen if the tenant id does not match the"
301 " current user")
302
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400303 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400304 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500305 # A DELETE request for another user's security group rule
306 # should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030307 self.assertRaises(exceptions.NotFound,
308 self.alt_security_client.delete_security_group_rule,
309 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530310
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400311 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400312 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500313 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530314 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030315 self.assertRaises(exceptions.NotFound,
316 self.alt_client.set_server_metadata,
317 self.server['id'],
318 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530319
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400320 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400321 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500322 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530323 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030324 self.assertRaises(exceptions.NotFound,
325 self.alt_images_client.set_image_metadata,
326 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530327
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400328 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400329 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500330 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530331 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800332 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000333 self.addCleanup(self.client.delete_server_metadata_item,
334 self.server['id'], 'meta1')
335 self.assertRaises(exceptions.NotFound,
336 self.alt_client.get_server_metadata_item,
337 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530338
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400339 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400340 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500341 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530342 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000343 self.addCleanup(self.images_client.delete_image_metadata_item,
344 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530345 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800346 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000347 self.assertRaises(exceptions.NotFound,
348 self.alt_images_client.get_image_metadata_item,
349 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530350
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400351 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400352 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500353 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530354 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000355 self.addCleanup(self.client.delete_server_metadata_item,
356 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800357 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000358 self.assertRaises(exceptions.NotFound,
359 self.alt_client.delete_server_metadata_item,
360 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530361
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400362 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400363 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500364 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530365 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000366 self.addCleanup(self.images_client.delete_image_metadata_item,
367 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530368 self.images_client.set_image_metadata(self.image['id'],
369 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000370 self.assertRaises(exceptions.NotFound,
371 self.alt_images_client.delete_image_metadata_item,
372 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530373
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400374 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400375 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500376 # A Get Console Output for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030377 self.assertRaises(exceptions.NotFound,
378 self.alt_client.get_console_output,
379 self.server['id'], 10)
nayna-pateleda1d122013-03-20 14:44:31 +0000380
381
382class AuthorizationTestXML(AuthorizationTestJSON):
383 _interface = 'xml'