blob: 327c7d1708f7df2e8edf85f16d157fdbef0ef24b [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):
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000033 super(AuthorizationTestJSON, cls).setUpClass()
34 if not cls.multi_user:
Jay Pipesf38eaac2012-06-21 13:37:35 -040035 msg = "Need >1 user"
ivan-zhu1feeb382013-01-24 10:14:39 +080036 raise cls.skipException(msg)
Daryl Walleckced8eb82012-03-19 13:52:37 -050037 cls.client = cls.os.servers_client
38 cls.images_client = cls.os.images_client
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053039 cls.keypairs_client = cls.os.keypairs_client
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053040 cls.security_client = cls.os.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050041
Jay Pipesf38eaac2012-06-21 13:37:35 -040042 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040043 creds = cls.isolated_creds.get_alt_creds()
Jay Pipesf38eaac2012-06-21 13:37:35 -040044 username, tenant_name, password = creds
Matthew Treinish481466b2012-12-20 17:16:01 -050045 cls.alt_manager = clients.Manager(username=username,
46 password=password,
47 tenant_name=tenant_name)
Jay Pipesf38eaac2012-06-21 13:37:35 -040048 else:
49 # Use the alt_XXX credentials in the config file
Matthew Treinish481466b2012-12-20 17:16:01 -050050 cls.alt_manager = clients.AltManager()
Daryl Walleckced8eb82012-03-19 13:52:37 -050051
Jay Pipesf38eaac2012-06-21 13:37:35 -040052 cls.alt_client = cls.alt_manager.servers_client
53 cls.alt_images_client = cls.alt_manager.images_client
54 cls.alt_keypairs_client = cls.alt_manager.keypairs_client
55 cls.alt_security_client = cls.alt_manager.security_groups_client
Daryl Walleckced8eb82012-03-19 13:52:37 -050056
Jay Pipesf38eaac2012-06-21 13:37:35 -040057 cls.alt_security_client._set_auth()
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090058 resp, server = cls.create_test_server(wait_until='ACTIVE')
Jay Pipesf38eaac2012-06-21 13:37:35 -040059 resp, cls.server = cls.client.get_server(server['id'])
Jay Pipes3f981df2012-03-27 18:59:44 -040060
Masayuki Igawa259c1132013-10-31 17:48:44 +090061 name = data_utils.rand_name('image')
Jay Pipesf38eaac2012-06-21 13:37:35 -040062 resp, body = cls.client.create_image(server['id'], name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090063 image_id = data_utils.parse_image_id(resp['location'])
Jay Pipesf38eaac2012-06-21 13:37:35 -040064 cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
65 resp, cls.image = cls.images_client.get_image(image_id)
Daryl Walleckced8eb82012-03-19 13:52:37 -050066
Masayuki Igawa259c1132013-10-31 17:48:44 +090067 cls.keypairname = data_utils.rand_name('keypair')
Jay Pipesf38eaac2012-06-21 13:37:35 -040068 resp, keypair = \
69 cls.keypairs_client.create_keypair(cls.keypairname)
Daryl Walleckced8eb82012-03-19 13:52:37 -050070
Masayuki Igawa259c1132013-10-31 17:48:44 +090071 name = data_utils.rand_name('security')
72 description = data_utils.rand_name('description')
nayna-pateleda1d122013-03-20 14:44:31 +000073 resp, cls.security_group = cls.security_client.create_security_group(
74 name, description)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053075
Jay Pipesf38eaac2012-06-21 13:37:35 -040076 parent_group_id = cls.security_group['id']
77 ip_protocol = 'tcp'
78 from_port = 22
79 to_port = 22
nayna-pateleda1d122013-03-20 14:44:31 +000080 resp, cls.rule = cls.security_client.create_security_group_rule(
81 parent_group_id, ip_protocol, from_port, to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053082
Daryl Walleckced8eb82012-03-19 13:52:37 -050083 @classmethod
84 def tearDownClass(cls):
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000085 if cls.multi_user:
Daryl Walleckced8eb82012-03-19 13:52:37 -050086 cls.images_client.delete_image(cls.image['id'])
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053087 cls.keypairs_client.delete_keypair(cls.keypairname)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +053088 cls.security_client.delete_security_group(cls.security_group['id'])
nayna-pateleda1d122013-03-20 14:44:31 +000089 super(AuthorizationTestJSON, cls).tearDownClass()
Daryl Walleckced8eb82012-03-19 13:52:37 -050090
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040091 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040092 def test_get_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050093 # A GET request for a server on another user's account should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103094 self.assertRaises(exceptions.NotFound, self.alt_client.get_server,
95 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -050096
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040097 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -040098 def test_delete_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050099 # A DELETE request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030100 self.assertRaises(exceptions.NotFound, self.alt_client.delete_server,
101 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500102
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400103 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400104 def test_update_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500105 # An update server request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030106 self.assertRaises(exceptions.NotFound, self.alt_client.update_server,
107 self.server['id'], name='test')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500108
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400109 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400110 def test_list_server_addresses_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500111 # A list addresses request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030112 self.assertRaises(exceptions.NotFound, self.alt_client.list_addresses,
113 self.server['id'])
Daryl Walleckced8eb82012-03-19 13:52:37 -0500114
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400115 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400116 def test_list_server_addresses_by_network_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500117 # A list address/network request for another user's server should fail
Daryl Walleckced8eb82012-03-19 13:52:37 -0500118 server_id = self.server['id']
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030119 self.assertRaises(exceptions.NotFound,
120 self.alt_client.list_addresses_by_network, server_id,
121 'public')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500122
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400123 @attr(type='gate')
sapan-kona37939762012-06-28 20:22:43 +0530124 def test_list_servers_with_alternate_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500125 # A list on servers from one tenant should not
126 # show on alternate tenant
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200127 # Listing servers from alternate tenant
sapan-kona37939762012-06-28 20:22:43 +0530128 alt_server_ids = []
129 resp, body = self.alt_client.list_servers()
130 alt_server_ids = [s['id'] for s in body['servers']]
131 self.assertNotIn(self.server['id'], alt_server_ids)
132
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400133 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400134 def test_change_password_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500135 # A change password request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030136 self.assertRaises(exceptions.NotFound, self.alt_client.change_password,
137 self.server['id'], 'newpass')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500138
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400139 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400140 def test_reboot_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500141 # A reboot request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030142 self.assertRaises(exceptions.NotFound, self.alt_client.reboot,
143 self.server['id'], 'HARD')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500144
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400145 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400146 def test_rebuild_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500147 # A rebuild request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030148 self.assertRaises(exceptions.NotFound, self.alt_client.rebuild,
149 self.server['id'], self.image_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500150
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400151 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400152 def test_resize_server_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500153 # A resize request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030154 self.assertRaises(exceptions.NotFound, self.alt_client.resize,
155 self.server['id'], self.flavor_ref_alt)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500156
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400157 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400158 def test_create_image_for_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500159 # A create image request for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030160 self.assertRaises(exceptions.NotFound,
161 self.alt_images_client.create_image,
162 self.server['id'], 'testImage')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500163
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400164 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500165 def test_create_server_with_unauthorized_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500166 # Server creation with another user's image should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030167 self.assertRaises(exceptions.BadRequest, self.alt_client.create_server,
168 'test', self.image['id'], self.flavor_ref)
Daryl Walleckced8eb82012-03-19 13:52:37 -0500169
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400170 @attr(type='gate')
Daryl Walleckced8eb82012-03-19 13:52:37 -0500171 def test_create_server_fails_when_tenant_incorrect(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500172 # A create server request should fail if the tenant id does not match
173 # the current user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400174 saved_base_url = self.alt_client.base_url
Jay Pipesff10d552012-04-06 14:18:50 -0400175 try:
Jay Pipesff10d552012-04-06 14:18:50 -0400176 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400177 self.alt_client.base_url = self.client.base_url
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030178 self.assertRaises(exceptions.BadRequest,
179 self.alt_client.create_server, 'test',
180 self.image['id'], self.flavor_ref)
Jay Pipesff10d552012-04-06 14:18:50 -0400181 finally:
182 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400183 self.alt_client.base_url = saved_base_url
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-')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400191 self.alt_keypairs_client._set_auth()
192 self.saved_base_url = self.alt_keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530193 try:
194 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400195 self.alt_keypairs_client.base_url = self.keypairs_client.base_url
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530196 resp = {}
197 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030198 self.assertRaises(exceptions.BadRequest,
199 self.alt_keypairs_client.create_keypair, k_name)
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +0530200 finally:
201 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400202 self.alt_keypairs_client.base_url = self.saved_base_url
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')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400242 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530243 try:
244 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400245 self.alt_security_client.base_url = self.security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530246 resp = {}
247 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030248 self.assertRaises(exceptions.BadRequest,
249 self.alt_security_client.create_security_group,
250 s_name, s_description)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530251 finally:
252 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400253 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800254 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700255 self.alt_security_client.delete_security_group(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200256 LOG.error("Create Security Group request should not happen if"
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530257 "the tenant id does not match the current user")
258
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400259 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400260 def test_get_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500261 # A GET request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030262 self.assertRaises(exceptions.NotFound,
263 self.alt_security_client.get_security_group,
264 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530265
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400266 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400267 def test_delete_security_group_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500268 # A DELETE request for another user's security group should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030269 self.assertRaises(exceptions.NotFound,
270 self.alt_security_client.delete_security_group,
271 self.security_group['id'])
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530272
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400273 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400274 def test_create_security_group_rule_in_analt_user_tenant(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500275 # A create security group rule request should fail if the tenant id
276 # does not match the current user
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200277 # POST security group rule with other user tenant
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530278 parent_group_id = self.security_group['id']
279 ip_protocol = 'icmp'
280 from_port = -1
281 to_port = -1
Jay Pipesf38eaac2012-06-21 13:37:35 -0400282 self.saved_base_url = self.alt_security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530283 try:
284 # Change the base URL to impersonate another user
Jay Pipesf38eaac2012-06-21 13:37:35 -0400285 self.alt_security_client.base_url = self.security_client.base_url
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530286 resp = {}
287 resp['status'] = None
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030288 self.assertRaises(exceptions.BadRequest,
289 self.alt_security_client.
290 create_security_group_rule,
291 parent_group_id, ip_protocol, from_port,
292 to_port)
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530293 finally:
294 # Reset the base_url...
Jay Pipesf38eaac2012-06-21 13:37:35 -0400295 self.alt_security_client.base_url = self.saved_base_url
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800296 if resp['status'] is not None:
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700297 self.alt_security_client.delete_security_group_rule(resp['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200298 LOG.error("Create security group rule request should not "
rajalakshmi-ganesan184daad2012-05-18 14:47:38 +0530299 "happen if the tenant id does not match the"
300 " current user")
301
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400302 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400303 def test_delete_security_group_rule_of_alt_account_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500304 # A DELETE request for another user's security group rule
305 # should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030306 self.assertRaises(exceptions.NotFound,
307 self.alt_security_client.delete_security_group_rule,
308 self.rule['id'])
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530309
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400310 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400311 def test_set_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500312 # A set metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530313 req_metadata = {'meta1': 'data1', 'meta2': 'data2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030314 self.assertRaises(exceptions.NotFound,
315 self.alt_client.set_server_metadata,
316 self.server['id'],
317 req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530318
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400319 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400320 def test_set_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500321 # A set metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530322 req_metadata = {'meta1': 'value1', 'meta2': 'value2'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030323 self.assertRaises(exceptions.NotFound,
324 self.alt_images_client.set_image_metadata,
325 self.image['id'], req_metadata)
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530326
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400327 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400328 def test_get_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500329 # A get metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530330 req_metadata = {'meta1': 'data1'}
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800331 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2suresh31bb7cb2013-03-14 04:53:49 +0000332 self.addCleanup(self.client.delete_server_metadata_item,
333 self.server['id'], 'meta1')
334 self.assertRaises(exceptions.NotFound,
335 self.alt_client.get_server_metadata_item,
336 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530337
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400338 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400339 def test_get_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500340 # A get metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530341 req_metadata = {'meta1': 'value1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000342 self.addCleanup(self.images_client.delete_image_metadata_item,
343 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530344 self.images_client.set_image_metadata(self.image['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800345 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000346 self.assertRaises(exceptions.NotFound,
347 self.alt_images_client.get_image_metadata_item,
348 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530349
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400350 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400351 def test_delete_metadata_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500352 # A delete metadata for another user's server should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530353 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000354 self.addCleanup(self.client.delete_server_metadata_item,
355 self.server['id'], 'meta1')
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800356 self.client.set_server_metadata(self.server['id'], req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000357 self.assertRaises(exceptions.NotFound,
358 self.alt_client.delete_server_metadata_item,
359 self.server['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530360
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400361 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400362 def test_delete_metadata_of_alt_account_image_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500363 # A delete metadata for another user's image should fail
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530364 req_metadata = {'meta1': 'data1'}
hi2sureshd0e24122013-03-15 03:06:53 +0000365 self.addCleanup(self.images_client.delete_image_metadata_item,
366 self.image['id'], 'meta1')
rajalakshmi-ganesan929a32a2012-05-29 18:00:25 +0530367 self.images_client.set_image_metadata(self.image['id'],
368 req_metadata)
hi2sureshd0e24122013-03-15 03:06:53 +0000369 self.assertRaises(exceptions.NotFound,
370 self.alt_images_client.delete_image_metadata_item,
371 self.image['id'], 'meta1')
rajalakshmi-ganesan72ea31a2012-05-25 11:59:10 +0530372
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400373 @attr(type='gate')
Jay Pipesf38eaac2012-06-21 13:37:35 -0400374 def test_get_console_output_of_alt_account_server_fails(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500375 # A Get Console Output for another user's server should fail
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030376 self.assertRaises(exceptions.NotFound,
377 self.alt_client.get_console_output,
378 self.server['id'], 10)
nayna-pateleda1d122013-03-20 14:44:31 +0000379
380
381class AuthorizationTestXML(AuthorizationTestJSON):
382 _interface = 'xml'