blob: 03075dfad9dea56d1b034e1000c2c329e331629d [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
Daryl Walleckced8eb82012-03-19 13:52:37 -050017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Matthew Treinish481466b2012-12-20 17:16:01 -050019from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090020from tempest.common.utils import data_utils
Daryl Walleckdc9e0c42012-04-02 16:51:26 -050021from tempest import exceptions
Giulio Fidente92f77192013-08-26 17:13:28 +020022from tempest.openstack.common import log as logging
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040023from tempest.test import attr
Daryl Walleckced8eb82012-03-19 13:52:37 -050024
Giulio Fidente92f77192013-08-26 17:13:28 +020025LOG = logging.getLogger(__name__)
26
Daryl Walleckced8eb82012-03-19 13:52:37 -050027
ivan-zhuf2b00502013-10-18 10:06:52 +080028class AuthorizationTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010029 _interface = 'json'
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
Jay Pipesf38eaac2012-06-21 13:37:35 -040044 if cls.config.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
Jay Pipesf38eaac2012-06-21 13:37:35 -040059 cls.alt_security_client._set_auth()
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
Jay Pipesf38eaac2012-06-21 13:37:35 -0400176 saved_base_url = self.alt_client.base_url
Jay Pipesff10d552012-04-06 14:18:50 -0400177 try:
Jay Pipesff10d552012-04-06 14:18:50 -0400178 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400179 self.alt_client.base_url = self.client.base_url
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030180 self.assertRaises(exceptions.BadRequest,
181 self.alt_client.create_server, 'test',
182 self.image['id'], self.flavor_ref)
Jay Pipesff10d552012-04-06 14:18:50 -0400183 finally:
184 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400185 self.alt_client.base_url = saved_base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530186
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400187 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400188 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500189 # A create keypair request should fail if the tenant id does not match
190 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200191 # POST keypair with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900192 k_name = data_utils.rand_name('keypair-')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400193 self.alt_keypairs_client._set_auth()
194 self.saved_base_url = self.alt_keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530195 try:
196 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400197 self.alt_keypairs_client.base_url = self.keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530198 resp = {}
199 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030200 self.assertRaises(exceptions.BadRequest,
201 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530202 finally:
203 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400204 self.alt_keypairs_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800205 if (resp['status'] is not None):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400206 resp, _ = self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200207 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800208 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530209
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400210 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400211 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500212 # A GET request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030213 self.assertRaises(exceptions.NotFound,
214 self.alt_keypairs_client.get_keypair,
215 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530216
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400217 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400218 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500219 # A DELETE request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030220 self.assertRaises(exceptions.NotFound,
221 self.alt_keypairs_client.delete_keypair,
222 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530223
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400224 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400225 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500226 # A GET request for an image on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030227 self.assertRaises(exceptions.NotFound,
228 self.alt_images_client.get_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530229
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400230 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400231 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500232 # A DELETE request for another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030233 self.assertRaises(exceptions.NotFound,
234 self.alt_images_client.delete_image,
235 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530236
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400237 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400238 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500239 # A create security group request should fail if the tenant id does not
240 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200241 # POST security group with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900242 s_name = data_utils.rand_name('security-')
243 s_description = data_utils.rand_name('security')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400244 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530245 try:
246 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400247 self.alt_security_client.base_url = self.security_client.base_url
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:
254 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400255 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800256 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700257 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200258 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530259 "the tenant id does not match the current user")
260
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400261 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400262 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500263 # A GET request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030264 self.assertRaises(exceptions.NotFound,
265 self.alt_security_client.get_security_group,
266 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530267
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400268 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400269 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500270 # A DELETE request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030271 self.assertRaises(exceptions.NotFound,
272 self.alt_security_client.delete_security_group,
273 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530274
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400275 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400276 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500277 # A create security group rule request should fail if the tenant id
278 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200279 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530280 parent_group_id = self.security_group['id']
281 ip_protocol = 'icmp'
282 from_port = -1
283 to_port = -1
Jay Pipesf38eaac2012-06-21 13:37:35 -0400284 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530285 try:
286 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400287 self.alt_security_client.base_url = self.security_client.base_url
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:
296 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400297 self.alt_security_client.base_url = self.saved_base_url
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'