blob: 0a8595f13cd96962426a2398cfedfbddf1795a2c [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
Matthew Treinisha83a16e2012-12-07 13:44:02 -050021from tempest.common.utils.data_utils import parse_image_id
22from tempest.common.utils.data_utils import rand_name
Daryl Walleckdc9e0c42012-04-02 16:51:26 -050023from tempest import exceptions
Giulio Fidente92f77192013-08-26 17:13:28 +020024from tempest.openstack.common import log as logging
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040025from tempest.test import attr
Daryl Walleckced8eb82012-03-19 13:52:37 -050026
Giulio Fidente92f77192013-08-26 17:13:28 +020027LOG = logging.getLogger(__name__)
28
Daryl Walleckced8eb82012-03-19 13:52:37 -050029
nayna-pateleda1d122013-03-20 14:44:31 +000030class AuthorizationTestJSON(base.BaseComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010031 _interface = 'json'
Daryl Walleckced8eb82012-03-19 13:52:37 -050032
33 @classmethod
34 def setUpClass(cls):
Jay Pipesf38eaac2012-06-21 13:37:35 -040035 if not compute.MULTI_USER:
36 msg = "Need >1 user"
ivan-zhu1feeb382013-01-24 10:14:39 +080037 raise cls.skipException(msg)
Jay Pipesf38eaac2012-06-21 13:37:35 -040038
nayna-pateleda1d122013-03-20 14:44:31 +000039 super(AuthorizationTestJSON, cls).setUpClass()
Jay Pipesf38eaac2012-06-21 13:37:35 -040040
Daryl Walleckced8eb82012-03-19 13:52:37 -050041 cls.client = cls.os.servers_client
42 cls.images_client = cls.os.images_client
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053043 cls.keypairs_client = cls.os.keypairs_client
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053044 cls.security_client = cls.os.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050045
Jay Pipesf38eaac2012-06-21 13:37:35 -040046 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040047 creds = cls.isolated_creds.get_alt_creds()
Jay Pipesf38eaac2012-06-21 13:37:35 -040048 username, tenant_name, password = creds
Matthew Treinish481466b2012-12-20 17:16:01 -050049 cls.alt_manager = clients.Manager(username=username,
50 password=password,
51 tenant_name=tenant_name)
Jay Pipesf38eaac2012-06-21 13:37:35 -040052 else:
53 # Use the alt_XXX credentials in the config file
Matthew Treinish481466b2012-12-20 17:16:01 -050054 cls.alt_manager = clients.AltManager()
Daryl Walleckced8eb82012-03-19 13:52:37 -050055
Jay Pipesf38eaac2012-06-21 13:37:35 -040056 cls.alt_client = cls.alt_manager.servers_client
57 cls.alt_images_client = cls.alt_manager.images_client
58 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
59 cls.alt_security_client = cls.alt_manager.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050060
Jay Pipesf38eaac2012-06-21 13:37:35 -040061 cls.alt_security_client._set_auth()
Mauro S. M. Rodrigues0a1bdff2013-03-11 11:41:18 -040062 resp, server = cls.create_server(wait_until='ACTIVE')
Jay Pipesf38eaac2012-06-21 13:37:35 -040063 resp, cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040064
Jay Pipesf38eaac2012-06-21 13:37:35 -040065 name = rand_name('image')
66 resp, body = cls.client.create_image(server['id'], name)
67 image_id = parse_image_id(resp['location'])
Jay Pipesf38eaac2012-06-21 13:37:35 -040068 cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
69 resp, cls.image = cls.images_client.get_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050070
Jay Pipesf38eaac2012-06-21 13:37:35 -040071 cls.keypairname = rand_name('keypair')
72 resp, keypair = \
73 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050074
Jay Pipesf38eaac2012-06-21 13:37:35 -040075 name = rand_name('security')
76 description = rand_name('description')
nayna-pateleda1d122013-03-20 14:44:31 +000077 resp, cls.security_group = cls.security_client.create_security_group(
78 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053079
Jay Pipesf38eaac2012-06-21 13:37:35 -040080 parent_group_id = cls.security_group['id']
81 ip_protocol = 'tcp'
82 from_port = 22
83 to_port = 22
nayna-pateleda1d122013-03-20 14:44:31 +000084 resp, cls.rule = cls.security_client.create_security_group_rule(
85 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053086
Daryl Walleckced8eb82012-03-19 13:52:37 -050087 @classmethod
88 def tearDownClass(cls):
Jay Pipesf38eaac2012-06-21 13:37:35 -040089 if compute.MULTI_USER:
Daryl Walleckced8eb82012-03-19 13:52:37 -050090 cls.images_client.delete_image(cls.image['id'])
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053091 cls.keypairs_client.delete_keypair(cls.keypairname)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053092 cls.security_client.delete_security_group(cls.security_group['id'])
nayna-pateleda1d122013-03-20 14:44:31 +000093 super(AuthorizationTestJSON, cls).tearDownClass()
Daryl Walleckced8eb82012-03-19 13:52:37 -050094
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040095 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040096 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050097 # A GET request for a server on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103098 self.assertRaises(exceptions.NotFound, self.alt_client.get_server,
99 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500100
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400101 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400102 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500103 # A DELETE request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030104 self.assertRaises(exceptions.NotFound, self.alt_client.delete_server,
105 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500106
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400107 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400108 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500109 # An update server request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030110 self.assertRaises(exceptions.NotFound, self.alt_client.update_server,
111 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500112
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400113 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400114 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500115 # A list addresses request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030116 self.assertRaises(exceptions.NotFound, self.alt_client.list_addresses,
117 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500118
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400119 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400120 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500121 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500122 server_id = self.server['id']
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030123 self.assertRaises(exceptions.NotFound,
124 self.alt_client.list_addresses_by_network, server_id,
125 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500126
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400127 @attr(type='gate')
sapan-kona37939762012-06-28 20:22:43 +0530128 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500129 # A list on servers from one tenant should not
130 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200131 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530132 alt_server_ids = []
133 resp, body = self.alt_client.list_servers()
134 alt_server_ids = [s['id'] for s in body['servers']]
135 self.assertNotIn(self.server['id'], alt_server_ids)
136
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400137 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400138 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500139 # A change password request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030140 self.assertRaises(exceptions.NotFound, self.alt_client.change_password,
141 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500142
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400143 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400144 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500145 # A reboot request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030146 self.assertRaises(exceptions.NotFound, self.alt_client.reboot,
147 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500148
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400149 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400150 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500151 # A rebuild request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030152 self.assertRaises(exceptions.NotFound, self.alt_client.rebuild,
153 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500154
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400155 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400156 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500157 # A resize request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030158 self.assertRaises(exceptions.NotFound, self.alt_client.resize,
159 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500160
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400161 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400162 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500163 # A create image request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030164 self.assertRaises(exceptions.NotFound,
165 self.alt_images_client.create_image,
166 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500167
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400168 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500169 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500170 # Server creation with another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030171 self.assertRaises(exceptions.BadRequest, self.alt_client.create_server,
172 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500173
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400174 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500175 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500176 # A create server request should fail if the tenant id does not match
177 # the current user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400178 saved_base_url = self.alt_client.base_url
Jay Pipesff10d552012-04-06 14:18:50 -0400179 try:
Jay Pipesff10d552012-04-06 14:18:50 -0400180 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400181 self.alt_client.base_url = self.client.base_url
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030182 self.assertRaises(exceptions.BadRequest,
183 self.alt_client.create_server, 'test',
184 self.image['id'], self.flavor_ref)
Jay Pipesff10d552012-04-06 14:18:50 -0400185 finally:
186 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400187 self.alt_client.base_url = saved_base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530188
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400189 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400190 def test_create_keypair_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500191 # A create keypair request should fail if the tenant id does not match
192 # the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200193 # POST keypair with other user tenant
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530194 k_name = rand_name('keypair-')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400195 self.alt_keypairs_client._set_auth()
196 self.saved_base_url = self.alt_keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530197 try:
198 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400199 self.alt_keypairs_client.base_url = self.keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530200 resp = {}
201 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030202 self.assertRaises(exceptions.BadRequest,
203 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530204 finally:
205 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400206 self.alt_keypairs_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800207 if (resp['status'] is not None):
Jay Pipesf38eaac2012-06-21 13:37:35 -0400208 resp, _ = self.alt_keypairs_client.delete_keypair(k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +0200209 LOG.error("Create keypair request should not happen "
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800210 "if the tenant id does not match the current user")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530211
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400212 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400213 def test_get_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500214 # A GET request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030215 self.assertRaises(exceptions.NotFound,
216 self.alt_keypairs_client.get_keypair,
217 self.keypairname)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530218
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400219 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400220 def test_delete_keypair_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500221 # A DELETE request for another user's keypair should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030222 self.assertRaises(exceptions.NotFound,
223 self.alt_keypairs_client.delete_keypair,
224 self.keypairname)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530225
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400226 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400227 def test_get_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500228 # A GET request for an image on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030229 self.assertRaises(exceptions.NotFound,
230 self.alt_images_client.get_image, self.image['id'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530231
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400232 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400233 def test_delete_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500234 # A DELETE request for another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030235 self.assertRaises(exceptions.NotFound,
236 self.alt_images_client.delete_image,
237 self.image['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530238
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400239 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400240 def test_create_security_group_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500241 # A create security group request should fail if the tenant id does not
242 # match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200243 # POST security group with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530244 s_name = rand_name('security-')
245 s_description = rand_name('security')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400246 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530247 try:
248 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400249 self.alt_security_client.base_url = self.security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530250 resp = {}
251 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030252 self.assertRaises(exceptions.BadRequest,
253 self.alt_security_client.create_security_group,
254 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530255 finally:
256 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400257 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800258 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700259 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200260 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530261 "the tenant id does not match the current user")
262
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400263 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400264 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500265 # A GET request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030266 self.assertRaises(exceptions.NotFound,
267 self.alt_security_client.get_security_group,
268 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530269
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400270 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400271 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500272 # A DELETE request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030273 self.assertRaises(exceptions.NotFound,
274 self.alt_security_client.delete_security_group,
275 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530276
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400277 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400278 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500279 # A create security group rule request should fail if the tenant id
280 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200281 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530282 parent_group_id = self.security_group['id']
283 ip_protocol = 'icmp'
284 from_port = -1
285 to_port = -1
Jay Pipesf38eaac2012-06-21 13:37:35 -0400286 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530287 try:
288 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400289 self.alt_security_client.base_url = self.security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530290 resp = {}
291 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030292 self.assertRaises(exceptions.BadRequest,
293 self.alt_security_client.
294 create_security_group_rule,
295 parent_group_id, ip_protocol, from_port,
296 to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530297 finally:
298 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400299 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800300 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700301 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200302 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530303 "happen if the tenant id does not match the"
304 " current user")
305
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400306 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400307 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500308 # A DELETE request for another user's security group rule
309 # should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030310 self.assertRaises(exceptions.NotFound,
311 self.alt_security_client.delete_security_group_rule,
312 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530313
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400314 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400315 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500316 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530317 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030318 self.assertRaises(exceptions.NotFound,
319 self.alt_client.set_server_metadata,
320 self.server['id'],
321 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530322
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400323 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400324 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500325 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530326 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030327 self.assertRaises(exceptions.NotFound,
328 self.alt_images_client.set_image_metadata,
329 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530330
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400331 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400332 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500333 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530334 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800335 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000336 self.addCleanup(self.client.delete_server_metadata_item,
337 self.server['id'], 'meta1')
338 self.assertRaises(exceptions.NotFound,
339 self.alt_client.get_server_metadata_item,
340 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530341
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400342 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400343 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500344 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530345 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000346 self.addCleanup(self.images_client.delete_image_metadata_item,
347 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530348 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800349 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000350 self.assertRaises(exceptions.NotFound,
351 self.alt_images_client.get_image_metadata_item,
352 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530353
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400354 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400355 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500356 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530357 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000358 self.addCleanup(self.client.delete_server_metadata_item,
359 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800360 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000361 self.assertRaises(exceptions.NotFound,
362 self.alt_client.delete_server_metadata_item,
363 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530364
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400365 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400366 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500367 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530368 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000369 self.addCleanup(self.images_client.delete_image_metadata_item,
370 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530371 self.images_client.set_image_metadata(self.image['id'],
372 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000373 self.assertRaises(exceptions.NotFound,
374 self.alt_images_client.delete_image_metadata_item,
375 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530376
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400377 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400378 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500379 # A Get Console Output for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030380 self.assertRaises(exceptions.NotFound,
381 self.alt_client.get_console_output,
382 self.server['id'], 10)
nayna-pateleda1d122013-03-20 14:44:31 +0000383
384
385class AuthorizationTestXML(AuthorizationTestJSON):
386 _interface = 'xml'