blob: ed7206190b7c71dca1bda5d7310228bbe880a9c0 [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):
Attila Fazekas19044d52013-02-16 07:35:06 +010030 _interface = 'json'
Daryl Walleckced8eb82012-03-19 13:52:37 -050031
32 @classmethod
33 def setUpClass(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000034 # No network resources required for this test
35 cls.set_network_resources()
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000036 super(AuthorizationTestJSON, cls).setUpClass()
37 if not cls.multi_user:
Jay Pipesf38eaac2012-06-21 13:37:35 -040038 msg = "Need >1 user"
ivan-zhu1feeb382013-01-24 10:14:39 +080039 raise cls.skipException(msg)
Daryl Walleckced8eb82012-03-19 13:52:37 -050040 cls.client = cls.os.servers_client
41 cls.images_client = cls.os.images_client
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053042 cls.keypairs_client = cls.os.keypairs_client
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053043 cls.security_client = cls.os.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050044
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000045 if CONF.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040046 creds = cls.isolated_creds.get_alt_creds()
Jay Pipesf38eaac2012-06-21 13:37:35 -040047 username, tenant_name, password = creds
Matthew Treinish481466b2012-12-20 17:16:01 -050048 cls.alt_manager = clients.Manager(username=username,
49 password=password,
50 tenant_name=tenant_name)
Jay Pipesf38eaac2012-06-21 13:37:35 -040051 else:
52 # Use the alt_XXX credentials in the config file
Matthew Treinish481466b2012-12-20 17:16:01 -050053 cls.alt_manager = clients.AltManager()
Daryl Walleckced8eb82012-03-19 13:52:37 -050054
Jay Pipesf38eaac2012-06-21 13:37:35 -040055 cls.alt_client = cls.alt_manager.servers_client
56 cls.alt_images_client = cls.alt_manager.images_client
57 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
58 cls.alt_security_client = cls.alt_manager.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050059
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090060 resp, server = cls.create_test_server(wait_until='ACTIVE')
Jay Pipesf38eaac2012-06-21 13:37:35 -040061 resp, cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040062
Masayuki Igawa259c1132013-10-31 17:48:44 +090063 name = data_utils.rand_name('image')
Jay Pipesf38eaac2012-06-21 13:37:35 -040064 resp, body = cls.client.create_image(server['id'], name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090065 image_id = data_utils.parse_image_id(resp['location'])
Jay Pipesf38eaac2012-06-21 13:37:35 -040066 cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
67 resp, cls.image = cls.images_client.get_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050068
Masayuki Igawa259c1132013-10-31 17:48:44 +090069 cls.keypairname = data_utils.rand_name('keypair')
Jay Pipesf38eaac2012-06-21 13:37:35 -040070 resp, keypair = \
71 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050072
Masayuki Igawa259c1132013-10-31 17:48:44 +090073 name = data_utils.rand_name('security')
74 description = data_utils.rand_name('description')
nayna-pateleda1d122013-03-20 14:44:31 +000075 resp, cls.security_group = cls.security_client.create_security_group(
76 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053077
Jay Pipesf38eaac2012-06-21 13:37:35 -040078 parent_group_id = cls.security_group['id']
79 ip_protocol = 'tcp'
80 from_port = 22
81 to_port = 22
nayna-pateleda1d122013-03-20 14:44:31 +000082 resp, cls.rule = cls.security_client.create_security_group_rule(
83 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053084
Daryl Walleckced8eb82012-03-19 13:52:37 -050085 @classmethod
86 def tearDownClass(cls):
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000087 if cls.multi_user:
Daryl Walleckced8eb82012-03-19 13:52:37 -050088 cls.images_client.delete_image(cls.image['id'])
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053089 cls.keypairs_client.delete_keypair(cls.keypairname)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053090 cls.security_client.delete_security_group(cls.security_group['id'])
nayna-pateleda1d122013-03-20 14:44:31 +000091 super(AuthorizationTestJSON, cls).tearDownClass()
Daryl Walleckced8eb82012-03-19 13:52:37 -050092
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040093 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040094 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050095 # A GET request for a server on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103096 self.assertRaises(exceptions.NotFound, self.alt_client.get_server,
97 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -050098
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040099 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400100 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500101 # A DELETE request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030102 self.assertRaises(exceptions.NotFound, self.alt_client.delete_server,
103 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500104
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400105 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400106 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500107 # An update server request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030108 self.assertRaises(exceptions.NotFound, self.alt_client.update_server,
109 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500110
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400111 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400112 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500113 # A list addresses request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030114 self.assertRaises(exceptions.NotFound, self.alt_client.list_addresses,
115 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500116
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400117 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400118 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500119 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500120 server_id = self.server['id']
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030121 self.assertRaises(exceptions.NotFound,
122 self.alt_client.list_addresses_by_network, server_id,
123 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500124
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400125 @attr(type='gate')
sapan-kona37939762012-06-28 20:22:43 +0530126 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500127 # A list on servers from one tenant should not
128 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200129 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530130 alt_server_ids = []
131 resp, body = self.alt_client.list_servers()
132 alt_server_ids = [s['id'] for s in body['servers']]
133 self.assertNotIn(self.server['id'], alt_server_ids)
134
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400135 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400136 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500137 # A change password request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030138 self.assertRaises(exceptions.NotFound, self.alt_client.change_password,
139 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500140
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400141 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400142 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500143 # A reboot request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030144 self.assertRaises(exceptions.NotFound, self.alt_client.reboot,
145 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500146
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400147 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400148 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500149 # A rebuild request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030150 self.assertRaises(exceptions.NotFound, self.alt_client.rebuild,
151 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500152
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400153 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400154 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500155 # A resize request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030156 self.assertRaises(exceptions.NotFound, self.alt_client.resize,
157 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500158
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400159 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400160 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500161 # A create image request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030162 self.assertRaises(exceptions.NotFound,
163 self.alt_images_client.create_image,
164 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500165
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400166 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500167 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500168 # Server creation with another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030169 self.assertRaises(exceptions.BadRequest, self.alt_client.create_server,
170 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500171
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400172 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500173 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500174 # A create server request should fail if the tenant id does not match
175 # the current user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000176 # Change the base URL to impersonate another user
177 self.alt_client.auth_provider.set_alt_auth_data(
178 request_part='url',
179 auth_data=self.client.auth_provider.auth_data
180 )
181 self.assertRaises(exceptions.BadRequest,
182 self.alt_client.create_server, 'test',
183 self.image['id'], self.flavor_ref)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530184
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400185 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400186 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500187 # A create keypair request should fail if the tenant id does not match
188 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200189 # POST keypair with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900190 k_name = data_utils.rand_name('keypair-')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530191 try:
192 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000193 self.alt_keypairs_client.auth_provider.set_alt_auth_data(
194 request_part='url',
195 auth_data=self.keypairs_client.auth_provider.auth_data
196 )
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530197 resp = {}
198 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030199 self.assertRaises(exceptions.BadRequest,
200 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530201 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000202 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800203 if (resp['status'] is not None):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400204 resp, _ = self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200205 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800206 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530207
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400208 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400209 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500210 # A GET request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030211 self.assertRaises(exceptions.NotFound,
212 self.alt_keypairs_client.get_keypair,
213 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530214
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400215 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400216 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500217 # A DELETE request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030218 self.assertRaises(exceptions.NotFound,
219 self.alt_keypairs_client.delete_keypair,
220 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530221
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400222 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400223 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500224 # A GET request for an image on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030225 self.assertRaises(exceptions.NotFound,
226 self.alt_images_client.get_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530227
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400228 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400229 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500230 # A DELETE request for another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030231 self.assertRaises(exceptions.NotFound,
232 self.alt_images_client.delete_image,
233 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530234
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400235 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400236 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500237 # A create security group request should fail if the tenant id does not
238 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200239 # POST security group with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900240 s_name = data_utils.rand_name('security-')
241 s_description = data_utils.rand_name('security')
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530242 try:
243 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000244 self.alt_security_client.auth_provider.set_alt_auth_data(
245 request_part='url',
246 auth_data=self.security_client.auth_provider.auth_data
247 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530248 resp = {}
249 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030250 self.assertRaises(exceptions.BadRequest,
251 self.alt_security_client.create_security_group,
252 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530253 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000254 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800255 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700256 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200257 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530258 "the tenant id does not match the current user")
259
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400260 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400261 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500262 # A GET request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030263 self.assertRaises(exceptions.NotFound,
264 self.alt_security_client.get_security_group,
265 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530266
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400267 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400268 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500269 # A DELETE request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030270 self.assertRaises(exceptions.NotFound,
271 self.alt_security_client.delete_security_group,
272 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530273
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400274 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400275 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500276 # A create security group rule request should fail if the tenant id
277 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200278 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530279 parent_group_id = self.security_group['id']
280 ip_protocol = 'icmp'
281 from_port = -1
282 to_port = -1
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530283 try:
284 # Change the base URL to impersonate another user
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000285 self.alt_security_client.auth_provider.set_alt_auth_data(
286 request_part='url',
287 auth_data=self.security_client.auth_provider.auth_data
288 )
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530289 resp = {}
290 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030291 self.assertRaises(exceptions.BadRequest,
292 self.alt_security_client.
293 create_security_group_rule,
294 parent_group_id, ip_protocol, from_port,
295 to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530296 finally:
Andrea Frittoli8bbdb162014-01-06 11:06:13 +0000297 # Next request the base_url is back to normal
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800298 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700299 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200300 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530301 "happen if the tenant id does not match the"
302 " current user")
303
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400304 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400305 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500306 # A DELETE request for another user's security group rule
307 # should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030308 self.assertRaises(exceptions.NotFound,
309 self.alt_security_client.delete_security_group_rule,
310 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530311
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400312 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400313 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500314 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530315 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030316 self.assertRaises(exceptions.NotFound,
317 self.alt_client.set_server_metadata,
318 self.server['id'],
319 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530320
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400321 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400322 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500323 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530324 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030325 self.assertRaises(exceptions.NotFound,
326 self.alt_images_client.set_image_metadata,
327 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530328
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400329 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400330 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500331 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530332 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800333 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000334 self.addCleanup(self.client.delete_server_metadata_item,
335 self.server['id'], 'meta1')
336 self.assertRaises(exceptions.NotFound,
337 self.alt_client.get_server_metadata_item,
338 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530339
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400340 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400341 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500342 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530343 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000344 self.addCleanup(self.images_client.delete_image_metadata_item,
345 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530346 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800347 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000348 self.assertRaises(exceptions.NotFound,
349 self.alt_images_client.get_image_metadata_item,
350 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530351
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400352 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400353 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500354 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530355 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000356 self.addCleanup(self.client.delete_server_metadata_item,
357 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800358 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000359 self.assertRaises(exceptions.NotFound,
360 self.alt_client.delete_server_metadata_item,
361 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530362
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400363 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400364 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500365 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530366 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000367 self.addCleanup(self.images_client.delete_image_metadata_item,
368 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530369 self.images_client.set_image_metadata(self.image['id'],
370 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000371 self.assertRaises(exceptions.NotFound,
372 self.alt_images_client.delete_image_metadata_item,
373 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530374
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400375 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400376 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500377 # A Get Console Output for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030378 self.assertRaises(exceptions.NotFound,
379 self.alt_client.get_console_output,
380 self.server['id'], 10)
nayna-pateleda1d122013-03-20 14:44:31 +0000381
382
383class AuthorizationTestXML(AuthorizationTestJSON):
384 _interface = 'xml'