blob: 49c4f32d45c904e9fbcfe77bfa3aa614d4c15937 [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 import compute
19from tempest.api.compute import base
Matthew Treinish481466b2012-12-20 17:16:01 -050020from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090021from tempest.common.utils import data_utils
Daryl Walleckdc9e0c42012-04-02 16:51:26 -050022from tempest import exceptions
Giulio Fidente92f77192013-08-26 17:13:28 +020023from tempest.openstack.common import log as logging
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040024from tempest.test import attr
Daryl Walleckced8eb82012-03-19 13:52:37 -050025
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):
Jay Pipesf38eaac2012-06-21 13:37:35 -040034 if not compute.MULTI_USER:
35 msg = "Need >1 user"
ivan-zhu1feeb382013-01-24 10:14:39 +080036 raise cls.skipException(msg)
Jay Pipesf38eaac2012-06-21 13:37:35 -040037
nayna-pateleda1d122013-03-20 14:44:31 +000038 super(AuthorizationTestJSON, cls).setUpClass()
Jay Pipesf38eaac2012-06-21 13:37:35 -040039
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
Jay Pipesf38eaac2012-06-21 13:37:35 -040045 if cls.config.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
Jay Pipesf38eaac2012-06-21 13:37:35 -040060 cls.alt_security_client._set_auth()
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090061 resp, server = cls.create_test_server(wait_until='ACTIVE')
Jay Pipesf38eaac2012-06-21 13:37:35 -040062 resp, cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040063
Masayuki Igawa259c1132013-10-31 17:48:44 +090064 name = data_utils.rand_name('image')
Jay Pipesf38eaac2012-06-21 13:37:35 -040065 resp, body = cls.client.create_image(server['id'], name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090066 image_id = data_utils.parse_image_id(resp['location'])
Jay Pipesf38eaac2012-06-21 13:37:35 -040067 cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
68 resp, cls.image = cls.images_client.get_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050069
Masayuki Igawa259c1132013-10-31 17:48:44 +090070 cls.keypairname = data_utils.rand_name('keypair')
Jay Pipesf38eaac2012-06-21 13:37:35 -040071 resp, keypair = \
72 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050073
Masayuki Igawa259c1132013-10-31 17:48:44 +090074 name = data_utils.rand_name('security')
75 description = data_utils.rand_name('description')
nayna-pateleda1d122013-03-20 14:44:31 +000076 resp, cls.security_group = cls.security_client.create_security_group(
77 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053078
Jay Pipesf38eaac2012-06-21 13:37:35 -040079 parent_group_id = cls.security_group['id']
80 ip_protocol = 'tcp'
81 from_port = 22
82 to_port = 22
nayna-pateleda1d122013-03-20 14:44:31 +000083 resp, cls.rule = cls.security_client.create_security_group_rule(
84 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053085
Daryl Walleckced8eb82012-03-19 13:52:37 -050086 @classmethod
87 def tearDownClass(cls):
Jay Pipesf38eaac2012-06-21 13:37:35 -040088 if compute.MULTI_USER:
Daryl Walleckced8eb82012-03-19 13:52:37 -050089 cls.images_client.delete_image(cls.image['id'])
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053090 cls.keypairs_client.delete_keypair(cls.keypairname)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053091 cls.security_client.delete_security_group(cls.security_group['id'])
nayna-pateleda1d122013-03-20 14:44:31 +000092 super(AuthorizationTestJSON, cls).tearDownClass()
Daryl Walleckced8eb82012-03-19 13:52:37 -050093
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040094 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040095 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050096 # A GET request for a server on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103097 self.assertRaises(exceptions.NotFound, self.alt_client.get_server,
98 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -050099
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400100 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400101 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500102 # A DELETE request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030103 self.assertRaises(exceptions.NotFound, self.alt_client.delete_server,
104 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500105
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400106 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400107 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500108 # An update server request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030109 self.assertRaises(exceptions.NotFound, self.alt_client.update_server,
110 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500111
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400112 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400113 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500114 # A list addresses request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030115 self.assertRaises(exceptions.NotFound, self.alt_client.list_addresses,
116 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500117
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400118 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400119 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500120 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500121 server_id = self.server['id']
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030122 self.assertRaises(exceptions.NotFound,
123 self.alt_client.list_addresses_by_network, server_id,
124 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500125
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400126 @attr(type='gate')
sapan-kona37939762012-06-28 20:22:43 +0530127 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500128 # A list on servers from one tenant should not
129 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200130 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530131 alt_server_ids = []
132 resp, body = self.alt_client.list_servers()
133 alt_server_ids = [s['id'] for s in body['servers']]
134 self.assertNotIn(self.server['id'], alt_server_ids)
135
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400136 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400137 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500138 # A change password request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030139 self.assertRaises(exceptions.NotFound, self.alt_client.change_password,
140 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500141
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400142 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400143 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500144 # A reboot request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030145 self.assertRaises(exceptions.NotFound, self.alt_client.reboot,
146 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500147
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400148 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400149 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500150 # A rebuild request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030151 self.assertRaises(exceptions.NotFound, self.alt_client.rebuild,
152 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500153
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400154 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400155 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500156 # A resize request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030157 self.assertRaises(exceptions.NotFound, self.alt_client.resize,
158 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500159
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400160 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400161 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500162 # A create image request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030163 self.assertRaises(exceptions.NotFound,
164 self.alt_images_client.create_image,
165 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500166
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400167 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500168 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500169 # Server creation with another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030170 self.assertRaises(exceptions.BadRequest, self.alt_client.create_server,
171 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500172
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400173 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500174 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500175 # A create server request should fail if the tenant id does not match
176 # the current user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400177 saved_base_url = self.alt_client.base_url
Jay Pipesff10d552012-04-06 14:18:50 -0400178 try:
Jay Pipesff10d552012-04-06 14:18:50 -0400179 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400180 self.alt_client.base_url = self.client.base_url
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030181 self.assertRaises(exceptions.BadRequest,
182 self.alt_client.create_server, 'test',
183 self.image['id'], self.flavor_ref)
Jay Pipesff10d552012-04-06 14:18:50 -0400184 finally:
185 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400186 self.alt_client.base_url = saved_base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530187
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400188 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400189 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500190 # A create keypair request should fail if the tenant id does not match
191 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200192 # POST keypair with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900193 k_name = data_utils.rand_name('keypair-')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400194 self.alt_keypairs_client._set_auth()
195 self.saved_base_url = self.alt_keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530196 try:
197 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400198 self.alt_keypairs_client.base_url = self.keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530199 resp = {}
200 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030201 self.assertRaises(exceptions.BadRequest,
202 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530203 finally:
204 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400205 self.alt_keypairs_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800206 if (resp['status'] is not None):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400207 resp, _ = self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200208 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800209 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530210
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400211 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400212 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500213 # A GET request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030214 self.assertRaises(exceptions.NotFound,
215 self.alt_keypairs_client.get_keypair,
216 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530217
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400218 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400219 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500220 # A DELETE request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030221 self.assertRaises(exceptions.NotFound,
222 self.alt_keypairs_client.delete_keypair,
223 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530224
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400225 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400226 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500227 # A GET request for an image on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030228 self.assertRaises(exceptions.NotFound,
229 self.alt_images_client.get_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530230
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400231 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400232 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500233 # A DELETE request for another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030234 self.assertRaises(exceptions.NotFound,
235 self.alt_images_client.delete_image,
236 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530237
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400238 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400239 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500240 # A create security group request should fail if the tenant id does not
241 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200242 # POST security group with other user tenant
Masayuki Igawa259c1132013-10-31 17:48:44 +0900243 s_name = data_utils.rand_name('security-')
244 s_description = data_utils.rand_name('security')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400245 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530246 try:
247 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400248 self.alt_security_client.base_url = self.security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530249 resp = {}
250 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030251 self.assertRaises(exceptions.BadRequest,
252 self.alt_security_client.create_security_group,
253 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530254 finally:
255 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400256 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800257 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700258 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200259 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530260 "the tenant id does not match the current user")
261
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400262 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400263 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500264 # A GET request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030265 self.assertRaises(exceptions.NotFound,
266 self.alt_security_client.get_security_group,
267 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530268
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400269 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400270 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500271 # A DELETE request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030272 self.assertRaises(exceptions.NotFound,
273 self.alt_security_client.delete_security_group,
274 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530275
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400276 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400277 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500278 # A create security group rule request should fail if the tenant id
279 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200280 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530281 parent_group_id = self.security_group['id']
282 ip_protocol = 'icmp'
283 from_port = -1
284 to_port = -1
Jay Pipesf38eaac2012-06-21 13:37:35 -0400285 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530286 try:
287 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400288 self.alt_security_client.base_url = self.security_client.base_url
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:
297 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400298 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800299 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700300 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200301 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530302 "happen if the tenant id does not match the"
303 " current user")
304
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400305 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400306 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500307 # A DELETE request for another user's security group rule
308 # should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030309 self.assertRaises(exceptions.NotFound,
310 self.alt_security_client.delete_security_group_rule,
311 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530312
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400313 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400314 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500315 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530316 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030317 self.assertRaises(exceptions.NotFound,
318 self.alt_client.set_server_metadata,
319 self.server['id'],
320 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530321
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400322 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400323 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500324 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530325 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030326 self.assertRaises(exceptions.NotFound,
327 self.alt_images_client.set_image_metadata,
328 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530329
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400330 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400331 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500332 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530333 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800334 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000335 self.addCleanup(self.client.delete_server_metadata_item,
336 self.server['id'], 'meta1')
337 self.assertRaises(exceptions.NotFound,
338 self.alt_client.get_server_metadata_item,
339 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530340
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400341 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400342 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500343 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530344 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000345 self.addCleanup(self.images_client.delete_image_metadata_item,
346 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530347 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800348 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000349 self.assertRaises(exceptions.NotFound,
350 self.alt_images_client.get_image_metadata_item,
351 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530352
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400353 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400354 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500355 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530356 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000357 self.addCleanup(self.client.delete_server_metadata_item,
358 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800359 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000360 self.assertRaises(exceptions.NotFound,
361 self.alt_client.delete_server_metadata_item,
362 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530363
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400364 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400365 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500366 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530367 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000368 self.addCleanup(self.images_client.delete_image_metadata_item,
369 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530370 self.images_client.set_image_metadata(self.image['id'],
371 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000372 self.assertRaises(exceptions.NotFound,
373 self.alt_images_client.delete_image_metadata_item,
374 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530375
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400376 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400377 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500378 # A Get Console Output for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030379 self.assertRaises(exceptions.NotFound,
380 self.alt_client.get_console_output,
381 self.server['id'], 10)
nayna-pateleda1d122013-03-20 14:44:31 +0000382
383
384class AuthorizationTestXML(AuthorizationTestJSON):
385 _interface = 'xml'